mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Support filtering workflow run on workflow names (#588)
* Filter workflow events on specific workflow names * Document new key * changelog * Change to a allow/deny list as per feedback
This commit is contained in:
parent
423dbb11fd
commit
7d74f1b1a8
1
changelog.d/588.feature
Normal file
1
changelog.d/588.feature
Normal file
@ -0,0 +1 @@
|
||||
Add new GitHubRepo connection config setting `workflowRun.workflows` to filter run reports by workflow name.
|
@ -39,6 +39,8 @@ This connection supports a few options which can be defined in the room state:
|
||||
|newIssue.labels|Automatically set these labels on issues created via commands|Array of: String matching a label name|*empty*|
|
||||
|workflowRun|Configuration options for workflow run results|`{ matchingBranch: string }`|*empty*|
|
||||
|workflowRun.matchingBranch|Only report workflow runs if it matches this regex.|Regex string|*empty*|
|
||||
|workflowRun.includingWorkflows|Only report workflow runs with a matching workflow name.|Array of: String matching a workflow name|*empty*|
|
||||
|workflowRun.excludingWorkflows|Never report workflow runs with a matching workflow name.|Array of: String matching a workflow name|*empty*|
|
||||
|
||||
|
||||
[^1]: `ignoreHooks` takes precedence over `enableHooks`.
|
||||
|
@ -57,6 +57,8 @@ export interface GitHubRepoConnectionOptions extends IConnectionState {
|
||||
};
|
||||
workflowRun?: {
|
||||
matchingBranch?: string;
|
||||
includingWorkflows?: string[];
|
||||
excludingWorkflows?: string[];
|
||||
}
|
||||
}
|
||||
export interface GitHubRepoConnectionState extends GitHubRepoConnectionOptions {
|
||||
@ -225,6 +227,16 @@ const ConnectionStateSchema = {
|
||||
nullable: true,
|
||||
type: "string",
|
||||
},
|
||||
includingWorkflows: {
|
||||
nullable: true,
|
||||
type: "array",
|
||||
items: {type: "string"},
|
||||
},
|
||||
excludingWorkflows: {
|
||||
nullable: true,
|
||||
type: "array",
|
||||
items: {type: "string"},
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -1082,6 +1094,7 @@ ${event.release.body}`;
|
||||
|
||||
public async onWorkflowCompleted(event: WorkflowRunCompletedEvent) {
|
||||
const workflowRun = event.workflow_run;
|
||||
const workflowName = event.workflow_run.name;
|
||||
const workflowRunType = `workflow.run.${workflowRun.conclusion}`;
|
||||
// Type safety checked above.
|
||||
if (
|
||||
@ -1092,6 +1105,15 @@ ${event.release.body}`;
|
||||
if (this.state.workflowRun?.matchingBranch && !workflowRun.head_branch.match(this.state.workflowRun?.matchingBranch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Workflow filtering
|
||||
if (this.state.workflowRun?.excludingWorkflows?.includes(workflowName)) {
|
||||
return;
|
||||
}
|
||||
if (this.state.workflowRun?.includingWorkflows && !this.state.workflowRun.includingWorkflows.includes(workflowName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info(`onWorkflowCompleted ${this.roomId} ${this.org}/${this.repo} '${workflowRun.id}'`);
|
||||
const orgRepoName = event.repository.full_name;
|
||||
const content = `Workflow **${event.workflow.name}** [${WORKFLOW_CONCLUSION_TO_NOTICE[workflowRun.conclusion]}](${workflowRun.html_url}) for ${orgRepoName} on branch \`${workflowRun.head_branch}\``;
|
||||
|
Loading…
x
Reference in New Issue
Block a user