mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Support GitLab wiki page events (#104)
* Support GitLab wiki events * changelog * Fixup formatting
This commit is contained in:
parent
02cae5eb88
commit
16e97d309d
1
changelog.d/104.feature
Normal file
1
changelog.d/104.feature
Normal file
@ -0,0 +1 @@
|
||||
Support GitLab wiki page change events for GitLabProject connections.
|
@ -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 } from "./Connections";
|
||||
import { IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookNoteEvent, IGitLabWebhookTagPushEvent } from "./Gitlab/WebhookTypes";
|
||||
import { IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookNoteEvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "./Gitlab/WebhookTypes";
|
||||
import { JiraIssueEvent, JiraIssueUpdatedEvent } from "./Jira/WebhookTypes";
|
||||
import { JiraOAuthResult } from "./Jira/Types";
|
||||
import { MatrixEvent, MatrixMemberContent, MatrixMessageContent } from "./MatrixEvent";
|
||||
@ -331,6 +331,12 @@ export class Bridge {
|
||||
(c, data) => c.onGitLabTagPush(data),
|
||||
);
|
||||
|
||||
this.bindHandlerToQueue<IGitLabWebhookWikiPageEvent, GitLabRepoConnection>(
|
||||
"gitlab.wiki_page",
|
||||
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
||||
(c, data) => c.onWikiPageEvent(data),
|
||||
);
|
||||
|
||||
this.queue.on<UserNotificationsEvent>("notifications.user.events", async (msg) => {
|
||||
const adminRoom = this.adminRooms.get(msg.data.roomId);
|
||||
if (!adminRoom) {
|
||||
|
@ -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 } from "../Gitlab/WebhookTypes";
|
||||
import { IGitLabWebhookMREvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "../Gitlab/WebhookTypes";
|
||||
import { CommandConnection } from "./CommandConnection";
|
||||
|
||||
export interface GitLabRepoConnectionState {
|
||||
@ -192,6 +192,34 @@ export class GitLabRepoConnection extends CommandConnection {
|
||||
format: "org.matrix.custom.html",
|
||||
});
|
||||
}
|
||||
|
||||
public async onWikiPageEvent(data: IGitLabWebhookWikiPageEvent) {
|
||||
const attributes = data.object_attributes;
|
||||
log.info(`onWikiPageEvent ${this.roomId} ${this.instance}/${this.path}`);
|
||||
if (this.shouldSkipHook('wiki', `wiki.${attributes.action}`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let statement: string;
|
||||
if (attributes.action === "create") {
|
||||
statement = "created new wiki page";
|
||||
} else if (attributes.action === "delete") {
|
||||
statement = "deleted wiki page";
|
||||
} else {
|
||||
statement = "updated wiki page";
|
||||
}
|
||||
|
||||
const message = attributes.message && ` "${attributes.message}"`;
|
||||
|
||||
const content = `**${data.user.username}** ${statement} "[${attributes.title}](${attributes.url})" for ${data.project.path_with_namespace} ${message}`;
|
||||
await this.as.botIntent.sendEvent(this.roomId, {
|
||||
msgtype: "m.notice",
|
||||
body: content,
|
||||
formatted_body: md.renderInline(content),
|
||||
format: "org.matrix.custom.html",
|
||||
});
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return `GitLabRepo ${this.instance}/${this.path}`;
|
||||
|
@ -86,6 +86,23 @@ export interface IGitLabWebhookTagPushEvent {
|
||||
repository: IGitlabRepository;
|
||||
}
|
||||
|
||||
export interface IGitLabWebhookWikiPageEvent {
|
||||
object_kind: "wiki_page";
|
||||
user: IGitlabUser;
|
||||
project: IGitlabProject;
|
||||
wiki: {
|
||||
web_url: string;
|
||||
path_with_namespace: string;
|
||||
};
|
||||
object_attributes: {
|
||||
title: string;
|
||||
url: string;
|
||||
message: string;
|
||||
format: "markdown";
|
||||
content: string;
|
||||
action: "create"|"update"|"delete";
|
||||
};
|
||||
}
|
||||
|
||||
export interface IGitLabWebhookNoteEvent {
|
||||
user: IGitlabUser;
|
||||
|
@ -89,6 +89,8 @@ export class Webhooks extends EventEmitter {
|
||||
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 {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user