Skip to content

Commit

Permalink
feat: support config workflow notice
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Sep 8, 2023
1 parent cb5a981 commit f915734
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"lint:fix": "eslint . --fix && prettier . -w",
"test": "jest --config jest.config.json --verbose",
"test:cov": "yarn test --coverage",
"extract-fixtures": "tsx scripts/extract-webhook-example.ts"
"extract-fixtures": "tsx scripts/extract-webhook-example.ts",
"generate:json-schemas": "node scripts/generate-json-schemas-all.js"
},
"wireit": {
"build": {
Expand Down
18 changes: 7 additions & 11 deletions src/github/templates/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Octokit } from '@octokit/rest';

import {
BOT_DEPLOY_NAME,
BOT_DEPLOY_PRE_NAME,
SYNC_TO_NPM_NAME,
workflowAboutRelease,
} from '@/constants/opensumi';
import { StringBuilder } from '@/utils';

import { Context, ExtractPayload, MarkdownContent } from '../types';
Expand Down Expand Up @@ -73,15 +67,17 @@ export async function handleWorkflowRun(
throw new StopHandleError('should have ctx octokit');
}

const mapping = {
'opensumi/actions': new Set([SYNC_TO_NPM_NAME]),
'opensumi/github-bot': new Set([BOT_DEPLOY_PRE_NAME, BOT_DEPLOY_NAME]),
} as Partial<Record<string, Set<string>>>;
const mapping = ctx.setting.workflowEventToNotify ?? {};

// const mapping = {
// 'opensumi/actions': new Set([SYNC_TO_NPM_NAME]),
// 'opensumi/github-bot': new Set([BOT_DEPLOY_PRE_NAME, BOT_DEPLOY_NAME]),
// } as Partial<Record<string, Set<string>>>;

const repoAllow = mapping[repository.full_name];

if (repoAllow) {
const allow = repoAllow.has(workflow.name);
const allow = repoAllow.includes(workflow.name);
if (allow) {
return renderWorkflow(payload, ctx);
}
Expand Down
3 changes: 0 additions & 3 deletions src/kv/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// 在 github app 的设置页面中查看
// 如:https://github.com/organizations/riril/settings/apps/ririltestbot

import { GitHubCommon, KVManager } from '@/kv';

import { AppSetting, ISetting } from './types';
Expand Down
6 changes: 6 additions & 0 deletions src/kv/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export interface ISetting {
* 监听哪些事件
*/
event?: string[];
/**
* 通知 workflow 的成功、失败事件
* 键是仓库的名字,值是某个 workflow 的名字(yml 中配置的 name 字段)
* @example { 'opensumi/actions': ['sync to npmmirror'] }
*/
workflowEventToNotify?: Record<string, string[]>;
/**
* 不在消息中展示 repo 名字,适合单仓库
* @default false
Expand Down
15 changes: 15 additions & 0 deletions src/public/json-schemas/app-settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
},
"description": "监听哪些事件"
},
"workflowEventToNotify": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"description": "通知 workflow 的成功、失败事件 键是仓库的名字,值是某个 workflow 的名字(yml 中配置的 name 字段)",
"examples": [
{
"opensumi/actions": ["sync to npmmirror"]
}
]
},
"notDisplayRepoName": {
"type": "boolean",
"description": "不在消息中展示 repo 名字,适合单仓库",
Expand Down
15 changes: 15 additions & 0 deletions src/public/json-schemas/setting.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
},
"description": "监听哪些事件"
},
"workflowEventToNotify": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"description": "通知 workflow 的成功、失败事件 键是仓库的名字,值是某个 workflow 的名字(yml 中配置的 name 字段)",
"examples": [
{
"opensumi/actions": ["sync to npmmirror"]
}
]
},
"notDisplayRepoName": {
"type": "boolean",
"description": "不在消息中展示 repo 名字,适合单仓库",
Expand Down

0 comments on commit f915734

Please sign in to comment.