Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitLab's ready for review hook #936

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/936.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix GitLab's ready for review hook.
12 changes: 4 additions & 8 deletions src/Connections/GitlabRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/Gitlab/WebhookTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export interface IGitLabWebhookMREvent {
object_attributes: IGitLabMergeRequestObjectAttributes;
labels: IGitLabLabel[];
changes: {
[key: string]: {
before: string;
after: string;
draft?: {
previous: boolean;
current: boolean;
}
}
}
Expand Down
Loading