用于同步 bot 标签的工具
这是在 GitHub 寄存器上同步特定机器人标签的小型工具 .
使用量
安装
npm i @google-automations/label-utils
使用量
syncLabels 将自动创建或更新标签。 这个
颜色由名称决定,应当一致
存储器.
以下是一个简单的例子:
import {syncLabels} from '@google-automations/label-utils';
const myLabels = [
{
name: 'my-bot:my-label',
description: 'label description'
},
];
app.on('schedule.repository' as '*', async context => {
const owner = context.payload.organization.login;
const repo = context.payload.repository.name;
await syncLabels(context.octokit, owner, repo, myLabels);
});
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢
cron:
- name: my-bot-sync-label
schedule: 0 3 * * *
description: my-bot syncing labels
params:
cron_type: "repository"
下面是同步标签在
installation_repositories.added 事件:
interface Repo {
full_name: string;
}
const myLabels = [
{
name: 'my-bot:my-label',
description: 'label description'
},
];
export = (app: Probot) => {
app.on('installation_repositories.added', async context => {
await Promise.all(
context.payload.repositories_added.map((r: Repo) => {
const [owner, repo] = r.full_name.split('/');
return syncLabels(
context.octokit,
owner,
repo,
myLabels
);
})
);
});
}