mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Support GitLab release events (#278)
* Support GitLab release events * changelog
This commit is contained in:
parent
4060ded7f8
commit
ec7e80a910
1
changelog.d/278.feature
Normal file
1
changelog.d/278.feature
Normal file
@ -0,0 +1 @@
|
||||
Support GitLab release webhook events.
|
@ -11,7 +11,7 @@ import { GithubInstance } from "./Github/GithubInstance";
|
||||
import { IBridgeStorageProvider } from "./Stores/StorageProvider";
|
||||
import { IConnection, GitHubDiscussionSpace, GitHubDiscussionConnection, GitHubUserSpace, JiraProjectConnection, GitLabRepoConnection,
|
||||
GitHubIssueConnection, GitHubProjectConnection, GitHubRepoConnection, GitLabIssueConnection, FigmaFileConnection } from "./Connections";
|
||||
import { IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookNoteEvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "./Gitlab/WebhookTypes";
|
||||
import { IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookNoteEvent, IGitLabWebhookReleaseEvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "./Gitlab/WebhookTypes";
|
||||
import { JiraIssueEvent, JiraIssueUpdatedEvent } from "./Jira/WebhookTypes";
|
||||
import { JiraOAuthResult } from "./Jira/Types";
|
||||
import { MatrixEvent, MatrixMemberContent, MatrixMessageContent } from "./MatrixEvent";
|
||||
@ -339,6 +339,12 @@ export class Bridge {
|
||||
(c, data) => c.onMergeRequestReviewed(data),
|
||||
);
|
||||
|
||||
this.bindHandlerToQueue<IGitLabWebhookReleaseEvent, GitLabRepoConnection>(
|
||||
"gitlab.release.create",
|
||||
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
||||
(c, data) => c.onRelease(data),
|
||||
);
|
||||
|
||||
this.bindHandlerToQueue<IGitLabWebhookTagPushEvent, GitLabRepoConnection>(
|
||||
"gitlab.tag_push",
|
||||
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
||||
|
@ -7,7 +7,7 @@ import { MatrixEvent, MatrixMessageContent } from "../MatrixEvent";
|
||||
import markdown from "markdown-it";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { GitLabInstance } from "../Config/Config";
|
||||
import { IGitLabWebhookMREvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "../Gitlab/WebhookTypes";
|
||||
import { IGitLabWebhookMREvent, IGitLabWebhookReleaseEvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "../Gitlab/WebhookTypes";
|
||||
import { CommandConnection } from "./CommandConnection";
|
||||
|
||||
export interface GitLabRepoConnectionState {
|
||||
@ -238,6 +238,23 @@ export class GitLabRepoConnection extends CommandConnection {
|
||||
});
|
||||
}
|
||||
|
||||
public async onRelease(data: IGitLabWebhookReleaseEvent) {
|
||||
if (this.shouldSkipHook('release', 'release.created')) {
|
||||
return;
|
||||
}
|
||||
log.info(`onReleaseCreated ${this.roomId} ${this.toString()} ${data.tag}`);
|
||||
const orgRepoName = data.project.path_with_namespace;
|
||||
const content = `**${data.commit.author.name}** 🪄 released [${data.name}](${data.url}) for ${orgRepoName}
|
||||
|
||||
${data.description}`;
|
||||
await this.as.botIntent.sendEvent(this.roomId, {
|
||||
msgtype: "m.notice",
|
||||
body: content,
|
||||
formatted_body: md.render(content),
|
||||
format: "org.matrix.custom.html",
|
||||
});
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return `GitLabRepo ${this.instance.url}/${this.path}`;
|
||||
}
|
||||
|
@ -2,11 +2,6 @@
|
||||
|
||||
export interface IGitLabWebhookEvent {
|
||||
object_kind: string;
|
||||
event_type: string;
|
||||
object_attributes: {
|
||||
action: string;
|
||||
state: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IGitlabUser {
|
||||
@ -62,6 +57,7 @@ export interface IGitLabLabel {
|
||||
|
||||
export interface IGitLabWebhookMREvent {
|
||||
object_kind: "merge_request";
|
||||
event_type: string;
|
||||
user: IGitlabUser;
|
||||
project: IGitlabProject;
|
||||
repository: IGitlabRepository;
|
||||
@ -104,8 +100,46 @@ export interface IGitLabWebhookWikiPageEvent {
|
||||
};
|
||||
}
|
||||
|
||||
export interface IGitLabWebhookReleaseEvent {
|
||||
object_kind: "release";
|
||||
description: string;
|
||||
name: string;
|
||||
tag: string;
|
||||
created_at: string;
|
||||
released_at: string;
|
||||
url: string;
|
||||
action: "create";
|
||||
project: IGitlabProject;
|
||||
commit: {
|
||||
id: string;
|
||||
message: string;
|
||||
title: string;
|
||||
timestamp: string;
|
||||
url: string;
|
||||
author: {
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
};
|
||||
assets: {
|
||||
count: number;
|
||||
links: [{
|
||||
id: string;
|
||||
external: boolean;
|
||||
link_type: "other";
|
||||
name: string;
|
||||
url: string;
|
||||
}],
|
||||
sources: [{
|
||||
format: string;
|
||||
url: string;
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
export interface IGitLabWebhookNoteEvent {
|
||||
user: IGitlabUser;
|
||||
event_type: string;
|
||||
project: IGitlabProject;
|
||||
issue: IGitlabIssue;
|
||||
repository: {
|
||||
@ -122,6 +156,7 @@ export interface IGitLabWebhookNoteEvent {
|
||||
}
|
||||
export interface IGitLabWebhookIssueStateEvent {
|
||||
user: IGitlabUser;
|
||||
event_type: string;
|
||||
project: IGitlabProject;
|
||||
repository: {
|
||||
name: string;
|
||||
@ -132,6 +167,7 @@ export interface IGitLabWebhookIssueStateEvent {
|
||||
object_attributes: {
|
||||
id: number;
|
||||
iid: number;
|
||||
action: string;
|
||||
description: string;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { MessageQueue, createMessageQueue } from "./MessageQueue";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import qs from "querystring";
|
||||
import axios from "axios";
|
||||
import { IGitLabWebhookEvent } from "./Gitlab/WebhookTypes";
|
||||
import { IGitLabWebhookEvent, IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookReleaseEvent } from "./Gitlab/WebhookTypes";
|
||||
import { EmitterWebhookEvent, Webhooks as OctokitWebhooks } from "@octokit/webhooks"
|
||||
import { IJiraWebhookEvent } from "./Jira/WebhookTypes";
|
||||
import { JiraWebhooksRouter } from "./Jira/Router";
|
||||
@ -78,17 +78,22 @@ export class Webhooks extends EventEmitter {
|
||||
}
|
||||
|
||||
private onGitLabPayload(body: IGitLabWebhookEvent) {
|
||||
log.info(`onGitLabPayload ${body.event_type}:`, body);
|
||||
if (body.event_type === "merge_request") {
|
||||
return `gitlab.merge_request.${body.object_attributes.action}`;
|
||||
} else if (body.event_type === "issue") {
|
||||
return `gitlab.issue.${body.object_attributes.action}`;
|
||||
} else if (body.event_type === "note") {
|
||||
log.info(`onGitLabPayload ${body.object_kind}:`, body);
|
||||
if (body.object_kind === "merge_request") {
|
||||
const action = (body as unknown as IGitLabWebhookMREvent).object_attributes.action;
|
||||
return `gitlab.merge_request.${action}`;
|
||||
} else if (body.object_kind === "issue") {
|
||||
const action = (body as unknown as IGitLabWebhookIssueStateEvent).object_attributes.action;
|
||||
return `gitlab.issue.${action}`;
|
||||
} else if (body.object_kind === "note") {
|
||||
return `gitlab.note.created`;
|
||||
} else if (body.object_kind === "tag_push") {
|
||||
return "gitlab.tag_push";
|
||||
} else if (body.object_kind === "wiki_page") {
|
||||
return "gitlab.wiki_page";
|
||||
} else if (body.object_kind === "release") {
|
||||
const action = (body as unknown as IGitLabWebhookReleaseEvent).action;
|
||||
return `gitlab.release.${action}`;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user