mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Add support for starting workflows
This commit is contained in:
parent
36a3863ba3
commit
8659cb8a32
@ -7,11 +7,12 @@ import { IConnection } from "./IConnection";
|
||||
import { IssuesOpenedEvent, IssuesReopenedEvent, IssuesEditedEvent, PullRequestOpenedEvent, IssuesClosedEvent, PullRequestClosedEvent, PullRequestReadyForReviewEvent, PullRequestReviewSubmittedEvent, ReleaseCreatedEvent } from "@octokit/webhooks-types";
|
||||
import { MatrixMessageContent, MatrixEvent, MatrixReactionContent } from "../MatrixEvent";
|
||||
import { MessageSenderClient } from "../MatrixSender";
|
||||
import { NotLoggedInError } from "../errors";
|
||||
import { CommandError, NotLoggedInError } from "../errors";
|
||||
import { RequestError } from "@octokit/types";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { ReposGetResponseData } from "../Github/Types";
|
||||
import { UserTokenStore } from "../UserTokenStore";
|
||||
import axios from "axios";
|
||||
import axios, { Axios, AxiosError } from "axios";
|
||||
import emoji from "node-emoji";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import markdown from "markdown-it";
|
||||
@ -205,8 +206,7 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
|
||||
public async onAssign(userId: string, number: string, ...users: string[]) {
|
||||
const octokit = await this.tokenStore.getOctokitForUser(userId);
|
||||
if (!octokit) {
|
||||
await this.as.botIntent.sendText(this.roomId, "You must login to assign an issue", "m.notice");
|
||||
return;
|
||||
throw new NotLoggedInError();
|
||||
}
|
||||
|
||||
if (users.length === 1) {
|
||||
@ -225,8 +225,7 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
|
||||
public async onClose(userId: string, number: string, comment?: string) {
|
||||
const octokit = await this.tokenStore.getOctokitForUser(userId);
|
||||
if (!octokit) {
|
||||
await this.as.botIntent.sendText(this.roomId, "You must login to close an issue", "m.notice");
|
||||
return;
|
||||
throw new NotLoggedInError();
|
||||
}
|
||||
|
||||
if (comment) {
|
||||
@ -250,8 +249,7 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
|
||||
public async onWorkflowRun(userId: string, name: string, args?: string, ref?: string) {
|
||||
const octokit = await this.tokenStore.getOctokitForUser(userId);
|
||||
if (!octokit) {
|
||||
await this.as.botIntent.sendText(this.roomId, "You must login to close an issue", "m.notice");
|
||||
return;
|
||||
throw new NotLoggedInError();
|
||||
}
|
||||
const workflowArgs: Record<string, string> = {};
|
||||
if (args) {
|
||||
@ -269,14 +267,18 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
|
||||
await this.as.botIntent.sendText(this.roomId, `Could not find a workflow by the name of "${name}". The workflows on this repository are ${workflowNames}`, "m.notice");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (!ref) {
|
||||
ref = (await octokit.repos.get({
|
||||
repo: this.state.repo,
|
||||
owner: this.state.org,
|
||||
})).data.default_branch;
|
||||
}
|
||||
} catch (ex) {
|
||||
throw new CommandError(ex.message, `Could not determine default ref (maybe pass one in)`);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
await octokit.actions.createWorkflowDispatch({
|
||||
repo: this.state.repo,
|
||||
owner: this.state.org,
|
||||
@ -284,6 +286,13 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
|
||||
ref,
|
||||
inputs: workflowArgs,
|
||||
});
|
||||
} catch (ex) {
|
||||
const httpError = ex as AxiosError;
|
||||
if (httpError.response?.data) {
|
||||
throw new CommandError(httpError.response?.data.message, ${httpError.response?.data.message});
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
await this.as.botIntent.sendText(this.roomId, `Workflow started`, "m.notice");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user