diff --git a/changelog.d/696.feature b/changelog.d/696.feature new file mode 100644 index 00000000..d85a23ae --- /dev/null +++ b/changelog.d/696.feature @@ -0,0 +1 @@ +Add support for push events on Github repo connections. \ No newline at end of file diff --git a/docs/usage/room_configuration/github_repo.md b/docs/usage/room_configuration/github_repo.md index 8d2aa20d..70db9c32 100644 --- a/docs/usage/room_configuration/github_repo.md +++ b/docs/usage/room_configuration/github_repo.md @@ -65,6 +65,7 @@ the events marked as default below will be enabled. Otherwise, this is ignored. - pull_request.opened * - pull_request.ready_for_review * - pull_request.reviewed * +- push - release * - release.created * - release.drafted diff --git a/src/Bridge.ts b/src/Bridge.ts index d26c0e0d..5fffd3b4 100644 --- a/src/Bridge.ts +++ b/src/Bridge.ts @@ -293,6 +293,12 @@ export class Bridge { (c, data) => c.onPROpened(data), ); + this.bindHandlerToQueue( + "github.push", + (data) => connManager.getConnectionsForGithubRepo(data.repository.owner.login, data.repository.name), + (c, data) => c.onPush(data), + ); + this.bindHandlerToQueue( "github.pull_request.closed", (data) => connManager.getConnectionsForGithubRepo(data.repository.owner.login, data.repository.name), diff --git a/src/Connections/GithubRepo.ts b/src/Connections/GithubRepo.ts index ca16671b..f212f2bc 100644 --- a/src/Connections/GithubRepo.ts +++ b/src/Connections/GithubRepo.ts @@ -8,7 +8,7 @@ import { Connection, IConnection, IConnectionState, InstantiateConnectionOpts, P import { GetConnectionsResponseItem } from "../provisioning/api"; import { IssuesOpenedEvent, IssuesReopenedEvent, IssuesEditedEvent, PullRequestOpenedEvent, IssuesClosedEvent, PullRequestClosedEvent, PullRequestReadyForReviewEvent, PullRequestReviewSubmittedEvent, ReleasePublishedEvent, ReleaseCreatedEvent, - IssuesLabeledEvent, IssuesUnlabeledEvent, WorkflowRunCompletedEvent, + IssuesLabeledEvent, IssuesUnlabeledEvent, WorkflowRunCompletedEvent, PushEvent, } from "@octokit/webhooks-types"; import { MatrixMessageContent, MatrixEvent, MatrixReactionContent } from "../MatrixEvent"; import { MessageSenderClient } from "../MatrixSender"; @@ -25,7 +25,7 @@ import { GitHubIssueConnection } from "./GithubIssue"; import { BridgeConfigGitHub } from "../Config/Config"; import { ApiError, ErrCode, ValidatorApiError } from "../api"; import { PermissionCheckFn } from "."; -import { MinimalGitHubIssue, MinimalGitHubRepo } from "../libRs"; +import { GitHubRepoMessageBody, MinimalGitHubIssue, MinimalGitHubRepo } from "../libRs"; import Ajv, { JSONSchemaType } from "ajv"; import { HookFilter } from "../HookFilter"; import { GitHubGrantChecker } from "../Github/GrantChecker"; @@ -107,6 +107,7 @@ export type AllowedEventsNames = "pull_request.ready_for_review" | "pull_request.reviewed" | "pull_request" | + "push" | "release.created" | "release.drafted" | "release" | @@ -132,6 +133,7 @@ export const AllowedEvents: AllowedEventsNames[] = [ "pull_request.ready_for_review" , "pull_request.reviewed" , "pull_request" , + "push", "release.created" , "release.drafted" , "release", @@ -324,6 +326,21 @@ const CREATED_GRACE_PERIOD_MS = 6000; const DEFAULT_HOTLINK_PREFIX = "#"; const MAX_RETURNED_TARGETS = 10; +interface IPushEventContent { + body: string, + formatted_body: string, + msgtype: "m.notice", + format: "org.matrix.custom.html", + external_url: string, + "uk.half-shot.matrix-hookshot.github.push": { + commits: string[], + ref: string, + base_ref: string|null, + pusher: string, + }, + "uk.half-shot.matrix-hookshot.github.repo": GitHubRepoMessageBody["uk.half-shot.matrix-hookshot.github.repo"], +} + function compareEmojiStrings(e0: string, e1: string, e0Index = 0) { return e0.codePointAt(e0Index) === e1.codePointAt(0); } @@ -1259,6 +1276,29 @@ export class GitHubRepoConnection extends CommandConnection c.id), + pusher: `${event.pusher.name} <${event.pusher.email}>`, + ref: event.ref, + base_ref: event.base_ref, + }, + msgtype: "m.notice", + body: content, + formatted_body: md.render(content), + format: "org.matrix.custom.html", + }; + await this.intent.sendEvent(this.roomId, eventContent); + } + public toString() { return `GitHubRepo ${this.org}/${this.repo}`; } diff --git a/web/components/roomConfig/GithubRepoConfig.tsx b/web/components/roomConfig/GithubRepoConfig.tsx index 3cb164ca..28c151e8 100644 --- a/web/components/roomConfig/GithubRepoConfig.tsx +++ b/web/components/roomConfig/GithubRepoConfig.tsx @@ -136,6 +136,7 @@ const ConnectionConfiguration: FunctionComponentReady for review Reviewed + Pushed commits Workflow Runs
    Success