mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Update required bot config
This commit is contained in:
parent
a3b01fbb51
commit
51c8be1422
@ -41,6 +41,7 @@ generic:
|
|||||||
# (Optional) Support for generic webhook events. `allowJsTransformationFunctions` will allow users to write short transformation snippets in code, and thus is unsafe in untrusted environments
|
# (Optional) Support for generic webhook events. `allowJsTransformationFunctions` will allow users to write short transformation snippets in code, and thus is unsafe in untrusted environments
|
||||||
#
|
#
|
||||||
enabled: false
|
enabled: false
|
||||||
|
urlPrefix: https://example.com/mywebhookspath/
|
||||||
allowJsTransformationFunctions: false
|
allowJsTransformationFunctions: false
|
||||||
webhook:
|
webhook:
|
||||||
# HTTP webhook listener options
|
# HTTP webhook listener options
|
||||||
|
@ -30,6 +30,7 @@ import * as GitHubWebhookTypes from "@octokit/webhooks-types";
|
|||||||
import LogWrapper from "./LogWrapper";
|
import LogWrapper from "./LogWrapper";
|
||||||
import { OAuthRequest } from "./WebhookTypes";
|
import { OAuthRequest } from "./WebhookTypes";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
|
import { SetupConnection } from "./Connections/SetupConnection";
|
||||||
const log = new LogWrapper("Bridge");
|
const log = new LogWrapper("Bridge");
|
||||||
|
|
||||||
export class Bridge {
|
export class Bridge {
|
||||||
@ -264,15 +265,9 @@ export class Bridge {
|
|||||||
this.bindHandlerToQueue<IGitLabWebhookMREvent, GitLabRepoConnection>(
|
this.bindHandlerToQueue<IGitLabWebhookMREvent, GitLabRepoConnection>(
|
||||||
"gitlab.merge_request.merge",
|
"gitlab.merge_request.merge",
|
||||||
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
||||||
(c, data) => c.onMergeRequestReviewed(data),
|
(c, data) => c.onMergeRequestMerged(data),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.bindHandlerToQueue<IGitLabWebhookMREvent, GitLabRepoConnection>(
|
|
||||||
"gitlab.merge_request.merge",
|
|
||||||
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
|
||||||
(c, data) => c.onMergeRequestReviewed(data),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.bindHandlerToQueue<IGitLabWebhookMREvent, GitLabRepoConnection>(
|
this.bindHandlerToQueue<IGitLabWebhookMREvent, GitLabRepoConnection>(
|
||||||
"gitlab.merge_request.approved",
|
"gitlab.merge_request.approved",
|
||||||
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
(data) => connManager.getConnectionsForGitLabRepo(data.project.path_with_namespace),
|
||||||
@ -561,7 +556,6 @@ export class Bridge {
|
|||||||
BRIDGE_ROOM_TYPE, roomId, room.accountData,
|
BRIDGE_ROOM_TYPE, roomId, room.accountData,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// This is a group room, don't add the admin settings and just sit in the room.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onRoomMessage(roomId: string, event: MatrixEvent<MatrixMessageContent>) {
|
private async onRoomMessage(roomId: string, event: MatrixEvent<MatrixMessageContent>) {
|
||||||
@ -596,7 +590,7 @@ export class Bridge {
|
|||||||
// Divert to the setup room code if we didn't match any of these
|
// Divert to the setup room code if we didn't match any of these
|
||||||
try {
|
try {
|
||||||
await (
|
await (
|
||||||
new SetupConnection(roomId, this.as, this.tokenStore, this.github, !!this.config.jira)
|
new SetupConnection(roomId, this.as, this.tokenStore, this.github, !!this.config.jira, this.config.generic)
|
||||||
).onMessageEvent(event);
|
).onMessageEvent(event);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
log.warn(`Setup connection failed to handle:`, ex);
|
log.warn(`Setup connection failed to handle:`, ex);
|
||||||
@ -605,15 +599,44 @@ export class Bridge {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const connection of this.connectionManager.getAllConnectionsForRoom(roomId)) {
|
if (adminRoom.userId !== event.sender) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const replyProcessor = new RichRepliesPreprocessor(true);
|
||||||
|
const processedReply = await replyProcessor.processEvent(event, this.as.botClient);
|
||||||
|
|
||||||
|
if (processedReply) {
|
||||||
|
const metadata: IRichReplyMetadata = processedReply.mx_richreply;
|
||||||
|
log.info(`Handling reply to ${metadata.parentEventId} for ${adminRoom.userId}`);
|
||||||
|
// This might be a reply to a notification
|
||||||
try {
|
try {
|
||||||
if (connection.onMessageEvent) {
|
const ev = metadata.realEvent;
|
||||||
await connection.onMessageEvent(event);
|
const splitParts: string[] = ev.content["uk.half-shot.matrix-hookshot.github.repo"]?.name.split("/");
|
||||||
|
const issueNumber = ev.content["uk.half-shot.matrix-hookshot.github.issue"]?.number;
|
||||||
|
if (splitParts && issueNumber) {
|
||||||
|
log.info(`Handling reply for ${splitParts}${issueNumber}`);
|
||||||
|
const connections = this.connectionManager.getConnectionsForGithubIssue(splitParts[0], splitParts[1], issueNumber);
|
||||||
|
await Promise.all(connections.map(async c => {
|
||||||
|
if (c instanceof GitHubIssueConnection) {
|
||||||
|
return c.onMatrixIssueComment(processedReply);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
log.info("Missing parts!:", splitParts, issueNumber);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
log.warn(`Connection ${connection.toString()} failed to handle message:`, ex);
|
await adminRoom.sendNotice("Failed to handle repy. You may not be authenticated to do that.");
|
||||||
|
log.error("Reply event could not be handled:", ex);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const command = event.content.body;
|
||||||
|
if (command) {
|
||||||
|
await adminRoom.handleCommand(event.event_id, command);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onRoomJoin(roomId: string, matrixEvent: MatrixEvent<MatrixMemberContent>) {
|
private async onRoomJoin(roomId: string, matrixEvent: MatrixEvent<MatrixMemberContent>) {
|
||||||
|
@ -52,8 +52,9 @@ export interface BridgeConfigJira {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BridgeGenericWebhooksConfig {
|
export interface BridgeGenericWebhooksConfig {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
urlPrefix: string;
|
||||||
allowJsTransformationFunctions?: boolean;
|
allowJsTransformationFunctions?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ export const DefaultConfig = new BridgeConfig({
|
|||||||
},
|
},
|
||||||
generic: {
|
generic: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
urlPrefix: "https://example.com/mywebhookspath/",
|
||||||
allowJsTransformationFunctions: false,
|
allowJsTransformationFunctions: false,
|
||||||
}
|
}
|
||||||
}, {});
|
}, {});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user