summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/code_review/signals.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-12 15:13:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-12 15:13:54 +0000
commit98638cd5e43611aac2193a5c2f80f72374040430 (patch)
tree6605f0f284efed1d05708b3799f093eb5e305a8f /app/assets/javascripts/code_review/signals.js
parent43d816ebc20da6ff959176248c70d8c4c7c9345a (diff)
downloadgitlab-ce-98638cd5e43611aac2193a5c2f80f72374040430.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/code_review/signals.js')
-rw-r--r--app/assets/javascripts/code_review/signals.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/app/assets/javascripts/code_review/signals.js b/app/assets/javascripts/code_review/signals.js
new file mode 100644
index 00000000000..101b7996bb5
--- /dev/null
+++ b/app/assets/javascripts/code_review/signals.js
@@ -0,0 +1,51 @@
+import createApolloClient from '../lib/graphql';
+
+import { getDerivedMergeRequestInformation } from '../diffs/utils/merge_request';
+import { EVT_MR_PREPARED } from '../diffs/constants';
+
+import getMr from '../graphql_shared/queries/merge_request.query.graphql';
+import mrPreparation from '../graphql_shared/subscriptions/merge_request_prepared.subscription.graphql';
+
+function required(name) {
+ throw new Error(`${name} is a required argument`);
+}
+
+async function observeMergeRequestFinishingPreparation({ apollo, signaler }) {
+ const { namespace, project, id: iid } = getDerivedMergeRequestInformation({
+ endpoint: document.location.pathname,
+ });
+ const projectPath = `${namespace}/${project}`;
+
+ if (projectPath && iid) {
+ const currentStatus = await apollo.query({
+ query: getMr,
+ variables: { projectPath, iid },
+ });
+ const { id: gqlMrId, preparedAt } = currentStatus.data.project.mergeRequest;
+ let preparationObservable;
+ let preparationSubscriber;
+
+ if (!preparedAt) {
+ preparationObservable = apollo.subscribe({
+ query: mrPreparation,
+ variables: {
+ issuableId: gqlMrId,
+ },
+ });
+
+ preparationSubscriber = preparationObservable.subscribe((preparationUpdate) => {
+ if (preparationUpdate.data.mergeRequestMergeStatusUpdated?.preparedAt) {
+ signaler.$emit(EVT_MR_PREPARED);
+ preparationSubscriber.unsubscribe();
+ }
+ });
+ }
+ }
+}
+
+export async function start({
+ signalBus = required('signalBus'),
+ apolloClient = createApolloClient(),
+} = {}) {
+ await observeMergeRequestFinishingPreparation({ signaler: signalBus, apollo: apolloClient });
+}