Skip to content

Commit 2bffd5c

Browse files
zecakehHalf-Shot
andauthored
Fix GitLab's ready for review hook (matrix-org#936)
* Fix GitLab's ready for review hook As far back as I could go in the docs (GitLab 14.10), the keys for changes have been `previous` and `current`. There is a `draft` change that we can use directly instead of guessing from the title. The type of the value depends on the key of the change. Signed-off-by: Kévin Commaille <[email protected]> * Add changelog Signed-off-by: Kévin Commaille <[email protected]> --------- Signed-off-by: Kévin Commaille <[email protected]> Co-authored-by: Will Hunt <[email protected]>
1 parent e5705e7 commit 2bffd5c

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

changelog.d/936.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix GitLab's ready for review hook.

src/Connections/GitlabRepo.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,22 +622,18 @@ export class GitLabRepoConnection extends CommandConnection<GitLabRepoConnection
622622
log.info(`onMergeRequestUpdate ${this.roomId} ${this.instance}/${this.path} ${event.object_attributes.iid}`);
623623
this.validateMREvent(event);
624624
// Check if the MR changed to / from a draft
625-
if (!event.changes.title) {
625+
if (!event.changes.draft) {
626626
return;
627627
}
628628
const orgRepoName = event.project.path_with_namespace;
629629
let content: string;
630-
const wasDraft = event.changes.title.before.startsWith('Draft: ');
631-
const isDraft = event.changes.title.after.startsWith('Draft: ');
632-
if (wasDraft && !isDraft) {
630+
const isDraft = event.changes.draft.current;
631+
if (!isDraft) {
633632
// Ready for review
634633
content = `**${event.user.username}** marked MR [${orgRepoName}#${event.object_attributes.iid}](${event.object_attributes.url}) as ready for review "${event.object_attributes.title}" `;
635-
} else if (!wasDraft && isDraft) {
634+
} else {
636635
// Back to draft.
637636
content = `**${event.user.username}** marked MR [${orgRepoName}#${event.object_attributes.iid}](${event.object_attributes.url}) as draft "${event.object_attributes.title}" `;
638-
} else {
639-
// Nothing changed, drop it.
640-
return;
641637
}
642638
await this.intent.sendEvent(this.roomId, {
643639
msgtype: "m.notice",

src/Gitlab/WebhookTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export interface IGitLabWebhookMREvent {
6464
object_attributes: IGitLabMergeRequestObjectAttributes;
6565
labels: IGitLabLabel[];
6666
changes: {
67-
[key: string]: {
68-
before: string;
69-
after: string;
67+
draft?: {
68+
previous: boolean;
69+
current: boolean;
7070
}
7171
}
7272
}

0 commit comments

Comments
 (0)