mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Fix GitLab's ready for review hook (#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 <zecakeh@tedomum.fr> * Add changelog Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr> --------- Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr> Co-authored-by: Will Hunt <will@half-shot.uk>
This commit is contained in:
parent
e5705e74c0
commit
2bffd5c90e
1
changelog.d/936.bugfix
Normal file
1
changelog.d/936.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix GitLab's ready for review hook.
|
@ -622,22 +622,18 @@ export class GitLabRepoConnection extends CommandConnection<GitLabRepoConnection
|
||||
log.info(`onMergeRequestUpdate ${this.roomId} ${this.instance}/${this.path} ${event.object_attributes.iid}`);
|
||||
this.validateMREvent(event);
|
||||
// Check if the MR changed to / from a draft
|
||||
if (!event.changes.title) {
|
||||
if (!event.changes.draft) {
|
||||
return;
|
||||
}
|
||||
const orgRepoName = event.project.path_with_namespace;
|
||||
let content: string;
|
||||
const wasDraft = event.changes.title.before.startsWith('Draft: ');
|
||||
const isDraft = event.changes.title.after.startsWith('Draft: ');
|
||||
if (wasDraft && !isDraft) {
|
||||
const isDraft = event.changes.draft.current;
|
||||
if (!isDraft) {
|
||||
// Ready for review
|
||||
content = `**${event.user.username}** marked MR [${orgRepoName}#${event.object_attributes.iid}](${event.object_attributes.url}) as ready for review "${event.object_attributes.title}" `;
|
||||
} else if (!wasDraft && isDraft) {
|
||||
} else {
|
||||
// Back to draft.
|
||||
content = `**${event.user.username}** marked MR [${orgRepoName}#${event.object_attributes.iid}](${event.object_attributes.url}) as draft "${event.object_attributes.title}" `;
|
||||
} else {
|
||||
// Nothing changed, drop it.
|
||||
return;
|
||||
}
|
||||
await this.intent.sendEvent(this.roomId, {
|
||||
msgtype: "m.notice",
|
||||
|
@ -64,9 +64,9 @@ export interface IGitLabWebhookMREvent {
|
||||
object_attributes: IGitLabMergeRequestObjectAttributes;
|
||||
labels: IGitLabLabel[];
|
||||
changes: {
|
||||
[key: string]: {
|
||||
before: string;
|
||||
after: string;
|
||||
draft?: {
|
||||
previous: boolean;
|
||||
current: boolean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user