From 247295f4eca5de7bc69960d5ad3bd262564938ab Mon Sep 17 00:00:00 2001 From: xuexb Date: Sun, 15 Oct 2017 12:53:17 +0800 Subject: [PATCH] fix: release note error --- README.md | 6 +- src/modules/releases/autoReleaseNote.js | 101 ++++++++++++------------ src/utils.js | 21 ++++- 3 files changed, 74 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 166b300..10e5c3d 100644 --- a/README.md +++ b/README.md @@ -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 克隆老是报错 diff --git a/src/modules/releases/autoReleaseNote.js b/src/modules/releases/autoReleaseNote.js index ee59d99..e3c1d57 100644 --- a/src/modules/releases/autoReleaseNote.js +++ b/src/modules/releases/autoReleaseNote.js @@ -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') + }); + } + }); }); }); } diff --git a/src/utils.js b/src/utils.js index 1d88795..2c85e02 100755 --- a/src/utils.js +++ b/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); + }); + }); }, /**