mirror of
https://github.com/xuexb/github-bot.git
synced 2026-01-25 14:06:59 +00:00
fix: release note error
This commit is contained in:
parent
3ac7b7f4d1
commit
247295f4ec
@ -5,7 +5,7 @@
|
||||
- [x] 不规范 issue 自动关闭
|
||||
- [x] 当 issue 标记 label 为 need demo 时,自动回复,需要相关demo
|
||||
- [x] issue 自动 assign 给指定人员,需要配置 `package.json` 中 `config.github-bot.lableToAuthor` 映射
|
||||
- [x] 当往远程第一次推送新版本号时,自动列出最新版本距离上一版本的 commit log 并发布 release notes
|
||||
- [x] 当往远程第一次推送新版本号时,自动列出最新版本距离上一版本的 commit log 并发布 release notes ,需要所对应项目克隆到 `./github/{项目名}`
|
||||
- [x] 发 PR 时根据打的 label 自动添加指定的 reviewer ,需要配置 `package.json` 中 `config.github-bot.lableToAuthor` 映射
|
||||
- [x] 发 PR 时标题不规范时提醒修改,需要配置 `package.json` 中 `config.validate-commit-msg.type` 前缀,标题必须以 `前缀:` 开头
|
||||
- [x] 发 PR 时自动根据标题的 [PR 标题规则](https://github.com/xuexb/github-bot#commit-log-和-pr-标题规则) 前缀生成对应的 label , `feat->enhancement, fix->bug`
|
||||
@ -53,3 +53,7 @@ docs: update install info
|
||||
|
||||
- [@yugasun](https://github.com/yugasun/)
|
||||
- [@xuexb](https://github.com/xuexb/)
|
||||
|
||||
## todo
|
||||
|
||||
- [ ] 现在必须手动的克隆下项目,使用 execSync 克隆老是报错
|
||||
|
||||
@ -18,63 +18,64 @@ module.exports = on => {
|
||||
getReleaseByTag(payload, {
|
||||
tag_name: payload.ref
|
||||
}).then(() => {}, () => {
|
||||
const repoDir = updateRepo({
|
||||
updateRepo({
|
||||
url: payload.repository.clone_url,
|
||||
repo
|
||||
});
|
||||
const tags = getTags({
|
||||
dir: repoDir
|
||||
});
|
||||
const after = tags[0];
|
||||
const before = tags.length > 1 ? tags[1] : getFirstCommitHash({
|
||||
dir: repoDir
|
||||
});
|
||||
const log = getCommitLog({
|
||||
dir: repoDir,
|
||||
before,
|
||||
after
|
||||
});
|
||||
}).then(repoDir => {
|
||||
const tags = getTags({
|
||||
dir: repoDir
|
||||
});
|
||||
const after = tags[0];
|
||||
const before = tags.length > 1 ? tags[1] : getFirstCommitHash({
|
||||
dir: repoDir
|
||||
});
|
||||
const log = getCommitLog({
|
||||
dir: repoDir,
|
||||
before,
|
||||
after
|
||||
});
|
||||
|
||||
const hash = getCommitLog({
|
||||
dir: repoDir,
|
||||
before,
|
||||
after,
|
||||
html_url: payload.repository.html_url,
|
||||
hash: true
|
||||
});
|
||||
const hash = getCommitLog({
|
||||
dir: repoDir,
|
||||
before,
|
||||
after,
|
||||
html_url: payload.repository.html_url,
|
||||
hash: true
|
||||
});
|
||||
|
||||
const changes = Object.keys(RELEASE_CHANGE_MAP).map(title => {
|
||||
return {
|
||||
title,
|
||||
data: log.filter(log => log.indexOf(`- ${RELEASE_CHANGE_MAP[title]}:`) === 0)
|
||||
const changes = Object.keys(RELEASE_CHANGE_MAP).map(title => {
|
||||
return {
|
||||
title,
|
||||
data: log.filter(log => log.indexOf(`- ${RELEASE_CHANGE_MAP[title]}:`) === 0)
|
||||
}
|
||||
}).filter(v => v.data.length);
|
||||
|
||||
let body = [];
|
||||
|
||||
if (changes.length) {
|
||||
body.push('## Notable changes\n');
|
||||
changes.forEach(v => {
|
||||
body.push([
|
||||
`- ${v.title}`
|
||||
]);
|
||||
|
||||
v.data.forEach(line => body.push(' ' + line));
|
||||
});
|
||||
}
|
||||
}).filter(v => v.data.length);
|
||||
|
||||
let body = [];
|
||||
if (hash.length) {
|
||||
body.push('\n## Commits\n');
|
||||
body = body.concat(hash);
|
||||
}
|
||||
|
||||
if (changes.length) {
|
||||
body.push('## Notable changes\n');
|
||||
changes.forEach(v => {
|
||||
body.push([
|
||||
`- ${v.title}`
|
||||
]);
|
||||
|
||||
v.data.forEach(line => body.push(' ' + line));
|
||||
});
|
||||
}
|
||||
|
||||
if (hash.length) {
|
||||
body.push('\n## Commits\n');
|
||||
body = body.concat(hash);
|
||||
}
|
||||
|
||||
if (body.length) {
|
||||
createRelease(payload, {
|
||||
tag_name: payload.ref,
|
||||
name: `${payload.ref} @${payload.repository.owner.login}`,
|
||||
body: body.join('\n')
|
||||
});
|
||||
}
|
||||
if (body.length) {
|
||||
createRelease(payload, {
|
||||
tag_name: payload.ref,
|
||||
name: `${payload.ref} @${payload.repository.owner.login}`,
|
||||
body: body.join('\n')
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
21
src/utils.js
21
src/utils.js
@ -78,16 +78,31 @@ const utils = {
|
||||
return execSync(format(shell, options)).toString().split(/\n+/);
|
||||
},
|
||||
|
||||
updateRepo({url, repo}) {
|
||||
/**
|
||||
* 更新 github 项目
|
||||
*
|
||||
* @param {string} options.repo 项目名
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateRepo({repo}) {
|
||||
const repoDir = path.resolve(__dirname, '../github/', repo);
|
||||
|
||||
if (!utils.isDirectory(repoDir)) {
|
||||
throw new Error(`${repoDir} 不是github目录!`);
|
||||
}
|
||||
|
||||
execSync(`cd ${repoDir} && git pull`);
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`cd ${repoDir} && git pull`, err => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return repoDir;
|
||||
setTimeout(() => {
|
||||
resolve(repoDir);
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user