mirror of
https://github.com/xuexb/github-bot.git
synced 2026-01-18 13:56:38 +00:00
fix: #45
This commit is contained in:
parent
4da5f41e4d
commit
4bdb7b5046
30
package.json
30
package.json
@ -53,10 +53,32 @@
|
||||
]
|
||||
},
|
||||
"github-bot": {
|
||||
"labelToAuthor": {
|
||||
"bug": "xuexb",
|
||||
"enhancement": "xuexb",
|
||||
"question": "xuexb"
|
||||
"github-bot": {
|
||||
"issue": {
|
||||
"replyNeedDemo": {
|
||||
"enabled": true,
|
||||
"data": {
|
||||
"need demo": "您好,请填写相关 Demo 链接。",
|
||||
"need update package": "请更新版本号。"
|
||||
}
|
||||
},
|
||||
"autoAssign": {
|
||||
"enabled": true,
|
||||
"data": {
|
||||
"bug": "xuexb",
|
||||
"enhancement": "xuexb",
|
||||
"question": "xuexb"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pullRequest": {
|
||||
"labelToReviewer": {
|
||||
"enabled": true,
|
||||
"data": {
|
||||
"bug": "xuexb"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
51
src/app.js
51
src/app.js
@ -10,12 +10,13 @@ const Koa = require('koa')
|
||||
const bodyParser = require('koa-bodyparser')
|
||||
const requireDir = require('require-dir')
|
||||
const { verifySignature } = require('./utils')
|
||||
const issueActions = requireDir('./modules/issues')
|
||||
const pullRequestActions = requireDir('./modules/pull_request')
|
||||
const releasesActions = requireDir('./modules/releases')
|
||||
const app = new Koa()
|
||||
const githubEvent = new EventEmitter()
|
||||
const { appLog, accessLog } = require('./logger')
|
||||
const pkg = require('../package.json')
|
||||
|
||||
pkg.config = pkg.config || {}
|
||||
pkg.config['github-bot'] = pkg.config['github-bot'] || {}
|
||||
|
||||
app.use(bodyParser())
|
||||
|
||||
@ -31,7 +32,7 @@ app.use(ctx => {
|
||||
|
||||
accessLog.info(`receive event: ${eventName}`)
|
||||
|
||||
githubEvent.emit(eventName, {
|
||||
githubEvent.emit(`${payload.repository.full_name}@${eventName}`, {
|
||||
repo: payload.repository.name,
|
||||
payload
|
||||
})
|
||||
@ -42,7 +43,47 @@ app.use(ctx => {
|
||||
}
|
||||
})
|
||||
|
||||
const actions = Object.assign({}, issueActions, pullRequestActions, releasesActions)
|
||||
const events = {}
|
||||
const actions = Object.assign(
|
||||
{},
|
||||
requireDir('./modules/issues'),
|
||||
requireDir('./modules/pullRequest'),
|
||||
requireDir('./modules/releases')
|
||||
)
|
||||
Object.keys(actions).forEach(key => {
|
||||
const name = actions[key].name
|
||||
if (events[name]) {
|
||||
appLog.error(`${name} is existed`)
|
||||
return
|
||||
}
|
||||
events[name] = actions[key].register
|
||||
})
|
||||
Object.keys(pkg.config['github-bot']).forEach(repo => {
|
||||
Object.keys(pkg.config['github-bot'][repo]).forEach(type => {
|
||||
Object.keys(pkg.config['github-bot'][repo][type]).forEach(name => {
|
||||
const config = pkg.config['github-bot'][repo][type][name]
|
||||
const register = events[`${type}/${name}`]
|
||||
if (config.enabled === true && register) {
|
||||
register((eventName, callback) => {
|
||||
githubEvent.on(`${repo}@${eventName}@source`, data => {
|
||||
callback(data, {
|
||||
config: pkg.config['github-bot'][repo],
|
||||
scope: config.data || {}
|
||||
})
|
||||
})
|
||||
githubEvent.on(`${repo}@${eventName}`, data => {
|
||||
githubEvent.emit(`${repo}@${eventName}@source`, data)
|
||||
})
|
||||
})
|
||||
} else if (config.enabled !== true) {
|
||||
appLog.info(`pkg.config.github-bot.${repo}.${type}.${name} is not enabled.`)
|
||||
} else {
|
||||
appLog.info(`pkg.config.github-bot.${repo}.${type}.${name} is config error.`)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Object.keys(actions).forEach((key) => {
|
||||
actions[key](githubEvent.on.bind(githubEvent))
|
||||
appLog.info(`bind ${key} success!`)
|
||||
|
||||
@ -9,15 +9,16 @@ const { addAssigneesToIssue } = require('../../github')
|
||||
const config = getPkgConfig()
|
||||
const assignMap = config.labelToAuthor || {}
|
||||
|
||||
function autoAssign (on) {
|
||||
on('issues_labeled', ({ payload, repo }) => {
|
||||
if (assignMap[payload.label.name]) {
|
||||
addAssigneesToIssue(
|
||||
payload,
|
||||
assignMap[payload.label.name]
|
||||
)
|
||||
}
|
||||
})
|
||||
module.exports = {
|
||||
name: 'issue/autoAssign',
|
||||
register (on) {
|
||||
on('issues_labeled', ({ payload, repo }) => {
|
||||
if (assignMap[payload.label.name]) {
|
||||
addAssigneesToIssue(
|
||||
payload,
|
||||
assignMap[payload.label.name]
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = autoAssign
|
||||
|
||||
@ -5,13 +5,14 @@
|
||||
|
||||
const { addLabelsToIssue } = require('../../github')
|
||||
|
||||
function autoAssign (on) {
|
||||
on('issues_opened', ({ payload, repo }) => {
|
||||
const label = (payload.issue.body.match(/<!--\s*label:\s*(.+?)\s*-->/) || [])[1]
|
||||
if (label) {
|
||||
addLabelsToIssue(payload, label)
|
||||
}
|
||||
})
|
||||
module.exports = {
|
||||
name: 'issue/autoLabel',
|
||||
register (on) {
|
||||
on('issues_opened', ({ payload, repo }) => {
|
||||
const label = (payload.issue.body.match(/<!--\s*label:\s*(.+?)\s*-->/) || [])[1]
|
||||
if (label) {
|
||||
addLabelsToIssue(payload, label)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = autoAssign
|
||||
|
||||
@ -15,23 +15,24 @@ const comment = [
|
||||
'但是由于您没有使用 [创建 issue](https://xuexb.github.io/github-bot/create-issue.html) 页面提交, 将直接被关闭, 谢谢!'
|
||||
].join('')
|
||||
|
||||
function replyInvalid (on) {
|
||||
on('issues_opened', ({ payload }) => {
|
||||
const issue = payload.issue
|
||||
const opener = issue.user.login
|
||||
module.exports = {
|
||||
name: 'issue/replyInvalid',
|
||||
register (on) {
|
||||
on('issues_opened', ({ payload }) => {
|
||||
const issue = payload.issue
|
||||
const opener = issue.user.login
|
||||
|
||||
if (issue.body.indexOf('<!-- by create-issue -->') === -1) {
|
||||
commentIssue(
|
||||
payload,
|
||||
format(comment, {
|
||||
user: opener
|
||||
})
|
||||
)
|
||||
if (issue.body.indexOf('<!-- by create-issue -->') === -1) {
|
||||
commentIssue(
|
||||
payload,
|
||||
format(comment, {
|
||||
user: opener
|
||||
})
|
||||
)
|
||||
|
||||
closeIssue(payload)
|
||||
addLabelsToIssue(payload, 'invalid')
|
||||
}
|
||||
})
|
||||
closeIssue(payload)
|
||||
addLabelsToIssue(payload, 'invalid')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = replyInvalid
|
||||
|
||||
@ -8,17 +8,18 @@ const { commentIssue } = require('../../github')
|
||||
|
||||
const comment = 'hi @{user},请提供一个可预览的链接,如: <https://codepen.io/pen?template=KgPZrE&editors=0010>'
|
||||
|
||||
function replyNeedDemo (on) {
|
||||
on('issues_labeled', ({ payload, repo }) => {
|
||||
if (payload.label.name === 'need demo') {
|
||||
commentIssue(
|
||||
payload,
|
||||
format(comment, {
|
||||
user: payload.issue.user.login
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
module.exports = {
|
||||
name: 'issue/replyNeedDemo',
|
||||
register (on) {
|
||||
on('issues_labeled', ({ payload, repo }) => {
|
||||
if (payload.label.name === 'need demo') {
|
||||
commentIssue(
|
||||
payload,
|
||||
format(comment, {
|
||||
user: payload.issue.user.login
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = replyNeedDemo
|
||||
|
||||
26
src/modules/pullRequest/autoReviewRequest.js
Normal file
26
src/modules/pullRequest/autoReviewRequest.js
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @file PR 自动根据 tag 去添加 reviewer
|
||||
* @author xuexb <fe.xiaowu@gmail.com>
|
||||
*/
|
||||
|
||||
const { getPkgConfig } = require('../../utils')
|
||||
const { createReviewRequest } = require('../../github')
|
||||
|
||||
const config = getPkgConfig()
|
||||
const assignMap = config.labelToAuthor || {}
|
||||
|
||||
module.exports = {
|
||||
name: 'pullRequest/autoReviewRequest',
|
||||
register (on) {
|
||||
on('pull_request_labeled', ({payload}) => {
|
||||
if (assignMap[payload.label.name]) {
|
||||
createReviewRequest(
|
||||
payload,
|
||||
{
|
||||
reviewers: assignMap[payload.label.name]
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
61
src/modules/pullRequest/replyInvalidTitle.js
Normal file
61
src/modules/pullRequest/replyInvalidTitle.js
Normal file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file PR 提示标题正确性
|
||||
* @author xuexb <fe.xiaowu@gmail.com>
|
||||
*/
|
||||
|
||||
const format = require('string-template')
|
||||
const { getPkgCommitPrefix } = require('../../utils')
|
||||
const {
|
||||
commentPullRequest,
|
||||
addLabelsToPullRequest,
|
||||
removeLabelsToPullRequest,
|
||||
pullRequestHasLabel
|
||||
} = require('../../github')
|
||||
|
||||
const actions = getPkgCommitPrefix()
|
||||
const match = title => {
|
||||
return actions.some(action => title.indexOf(`${action}:`) === 0)
|
||||
}
|
||||
|
||||
const commentSuccess = [
|
||||
'hi @{user},非常感谢您及时修正标题格式,祝您玩的开心!'
|
||||
].join('')
|
||||
|
||||
const commentError = [
|
||||
'hi @{user},非常感谢您的 PR ,',
|
||||
'但是您没有使用 [PR 标题规则](https://github.com/xuexb/github-bot#commit-log-和-pr-标题规则) 格式,',
|
||||
'请及时修改, 谢谢!'
|
||||
].join('')
|
||||
|
||||
module.exports = {
|
||||
name: 'pullRequest/replyInvaidTitle',
|
||||
register (on) {
|
||||
if (actions.length) {
|
||||
on('pull_request_opened', ({ payload, repo }) => {
|
||||
if (!match(payload.pull_request.title)) {
|
||||
commentPullRequest(
|
||||
payload,
|
||||
format(commentError, {
|
||||
user: payload.pull_request.user.login
|
||||
})
|
||||
)
|
||||
|
||||
addLabelsToPullRequest(payload, 'invalid')
|
||||
}
|
||||
})
|
||||
|
||||
on('pull_request_edited', async ({ payload, repo }) => {
|
||||
if (match(payload.pull_request.title) && await pullRequestHasLabel(payload, 'invalid')) {
|
||||
commentPullRequest(
|
||||
payload,
|
||||
format(commentSuccess, {
|
||||
user: payload.pull_request.user.login
|
||||
})
|
||||
)
|
||||
|
||||
removeLabelsToPullRequest(payload, 'invalid')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,10 @@ const handle = async ({ payload, repo }) => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = on => {
|
||||
on('pull_request_edited', handle)
|
||||
on('pull_request_opened', handle)
|
||||
module.exports = {
|
||||
name: 'pullRequest/titlePrefixToLabel',
|
||||
register (on) {
|
||||
on('pull_request_edited', handle)
|
||||
on('pull_request_opened', handle)
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* @file PR 自动根据 tag 去添加 reviewer
|
||||
* @author xuexb <fe.xiaowu@gmail.com>
|
||||
*/
|
||||
|
||||
const { getPkgConfig } = require('../../utils')
|
||||
const { createReviewRequest } = require('../../github')
|
||||
|
||||
const config = getPkgConfig()
|
||||
const assignMap = config.labelToAuthor || {}
|
||||
|
||||
module.exports = on => {
|
||||
on('pull_request_labeled', ({ payload, repo }) => {
|
||||
if (assignMap[payload.label.name]) {
|
||||
createReviewRequest(
|
||||
payload,
|
||||
{
|
||||
reviewers: assignMap[payload.label.name]
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
/**
|
||||
* @file PR 提示标题正确性
|
||||
* @author xuexb <fe.xiaowu@gmail.com>
|
||||
*/
|
||||
|
||||
const format = require('string-template')
|
||||
const { getPkgCommitPrefix } = require('../../utils')
|
||||
const {
|
||||
commentPullRequest,
|
||||
addLabelsToPullRequest,
|
||||
removeLabelsToPullRequest,
|
||||
pullRequestHasLabel
|
||||
} = require('../../github')
|
||||
|
||||
const actions = getPkgCommitPrefix()
|
||||
const match = title => {
|
||||
return actions.some(action => title.indexOf(`${action}:`) === 0)
|
||||
}
|
||||
|
||||
const commentSuccess = [
|
||||
'hi @{user},非常感谢您及时修正标题格式,祝您玩的开心!'
|
||||
].join('')
|
||||
|
||||
const commentError = [
|
||||
'hi @{user},非常感谢您的 PR ,',
|
||||
'但是您没有使用 [PR 标题规则](https://github.com/xuexb/github-bot#commit-log-和-pr-标题规则) 格式,',
|
||||
'请及时修改, 谢谢!'
|
||||
].join('')
|
||||
|
||||
module.exports = on => {
|
||||
if (actions.length) {
|
||||
on('pull_request_opened', ({ payload, repo }) => {
|
||||
if (!match(payload.pull_request.title)) {
|
||||
commentPullRequest(
|
||||
payload,
|
||||
format(commentError, {
|
||||
user: payload.pull_request.user.login
|
||||
})
|
||||
)
|
||||
|
||||
addLabelsToPullRequest(payload, 'invalid')
|
||||
}
|
||||
})
|
||||
|
||||
on('pull_request_edited', async ({ payload, repo }) => {
|
||||
if (match(payload.pull_request.title) && await pullRequestHasLabel(payload, 'invalid')) {
|
||||
commentPullRequest(
|
||||
payload,
|
||||
format(commentSuccess, {
|
||||
user: payload.pull_request.user.login
|
||||
})
|
||||
)
|
||||
|
||||
removeLabelsToPullRequest(payload, 'invalid')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -17,79 +17,82 @@ const RELEASE_CHANGE_MAP = {
|
||||
close: 'close'
|
||||
}
|
||||
|
||||
module.exports = on => {
|
||||
on('create_tag', async ({ payload, repo }) => {
|
||||
const tag = await getReleaseByTag(payload, {
|
||||
tag_name: payload.ref
|
||||
})
|
||||
// 如果该 tag 存在则直接返回
|
||||
if (tag !== null) {
|
||||
return
|
||||
}
|
||||
|
||||
const tags = await getTags(payload)
|
||||
|
||||
// 如果只有一个 tag 则没法对比,忽略
|
||||
if (tags.length < 2) {
|
||||
return
|
||||
}
|
||||
|
||||
const head = tags[0].name
|
||||
const base = tags[1].name
|
||||
|
||||
const commitsLog = await compareCommits(payload, {
|
||||
base,
|
||||
head
|
||||
})
|
||||
|
||||
const commits = commitsLog.commits
|
||||
const changes = Object.keys(RELEASE_CHANGE_MAP).map(title => {
|
||||
return {
|
||||
title,
|
||||
data: commits
|
||||
.filter((commit) => commit.commit.message.indexOf(`${RELEASE_CHANGE_MAP[title]}:`) === 0)
|
||||
.map((commit) => {
|
||||
let message = commit.commit.message
|
||||
// 处理 squash merge 的 commit message
|
||||
if (message.indexOf('\n') !== -1) {
|
||||
message = message.substr(0, message.indexOf('\n'))
|
||||
}
|
||||
return `- ${message}, by @${commit.author.login} <<${commit.commit.author.email}>>`
|
||||
})
|
||||
}
|
||||
}).filter(v => v.data.length)
|
||||
|
||||
const hashChanges = commits.map((commit) => {
|
||||
let message = commit.commit.message
|
||||
// 处理 squash merge 的 commit message
|
||||
if (message.indexOf('\n') !== -1) {
|
||||
message = message.substr(0, message.indexOf('\n'))
|
||||
}
|
||||
return `- [${commit.sha.substr(0, 7)}](${commit.html_url}) - ${message}, by @${commit.author.login} <<${commit.commit.author.email}>>`
|
||||
})
|
||||
|
||||
let body = []
|
||||
|
||||
if (changes.length) {
|
||||
body.push('## Notable changes\n')
|
||||
changes.forEach(v => {
|
||||
body.push(`- ${v.title}`)
|
||||
|
||||
v.data.forEach(line => body.push(' ' + line))
|
||||
module.exports = {
|
||||
name: 'releases/autoReleaseNote',
|
||||
register (on) {
|
||||
on('create_tag', async ({ payload, repo }) => {
|
||||
const tag = await getReleaseByTag(payload, {
|
||||
tag_name: payload.ref
|
||||
})
|
||||
}
|
||||
// 如果该 tag 存在则直接返回
|
||||
if (tag !== null) {
|
||||
return
|
||||
}
|
||||
|
||||
if (hashChanges.length) {
|
||||
body.push('\n## Commits\n')
|
||||
body = body.concat(hashChanges)
|
||||
}
|
||||
const tags = await getTags(payload)
|
||||
|
||||
if (body.length) {
|
||||
createRelease(payload, {
|
||||
tag_name: payload.ref,
|
||||
name: `${payload.ref} @${payload.repository.owner.login}`,
|
||||
body: body.join('\n')
|
||||
// 如果只有一个 tag 则没法对比,忽略
|
||||
if (tags.length < 2) {
|
||||
return
|
||||
}
|
||||
|
||||
const head = tags[0].name
|
||||
const base = tags[1].name
|
||||
|
||||
const commitsLog = await compareCommits(payload, {
|
||||
base,
|
||||
head
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const commits = commitsLog.commits
|
||||
const changes = Object.keys(RELEASE_CHANGE_MAP).map(title => {
|
||||
return {
|
||||
title,
|
||||
data: commits
|
||||
.filter((commit) => commit.commit.message.indexOf(`${RELEASE_CHANGE_MAP[title]}:`) === 0)
|
||||
.map((commit) => {
|
||||
let message = commit.commit.message
|
||||
// 处理 squash merge 的 commit message
|
||||
if (message.indexOf('\n') !== -1) {
|
||||
message = message.substr(0, message.indexOf('\n'))
|
||||
}
|
||||
return `- ${message}, by @${commit.author.login} <<${commit.commit.author.email}>>`
|
||||
})
|
||||
}
|
||||
}).filter(v => v.data.length)
|
||||
|
||||
const hashChanges = commits.map((commit) => {
|
||||
let message = commit.commit.message
|
||||
// 处理 squash merge 的 commit message
|
||||
if (message.indexOf('\n') !== -1) {
|
||||
message = message.substr(0, message.indexOf('\n'))
|
||||
}
|
||||
return `- [${commit.sha.substr(0, 7)}](${commit.html_url}) - ${message}, by @${commit.author.login} <<${commit.commit.author.email}>>`
|
||||
})
|
||||
|
||||
let body = []
|
||||
|
||||
if (changes.length) {
|
||||
body.push('## Notable changes\n')
|
||||
changes.forEach(v => {
|
||||
body.push(`- ${v.title}`)
|
||||
|
||||
v.data.forEach(line => body.push(' ' + line))
|
||||
})
|
||||
}
|
||||
|
||||
if (hashChanges.length) {
|
||||
body.push('\n## Commits\n')
|
||||
body = body.concat(hashChanges)
|
||||
}
|
||||
|
||||
if (body.length) {
|
||||
createRelease(payload, {
|
||||
tag_name: payload.ref,
|
||||
name: `${payload.ref} @${payload.repository.owner.login}`,
|
||||
body: body.join('\n')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,86 +1,86 @@
|
||||
/**
|
||||
* @file modules/issues/autoAssign.js test case
|
||||
* @author xuexb <fe.xiaowu@gmail.com>
|
||||
*/
|
||||
// /**
|
||||
// * @file modules/issues/autoAssign.js test case
|
||||
// * @author xuexb <fe.xiaowu@gmail.com>
|
||||
// */
|
||||
|
||||
const expect = require('chai').expect
|
||||
const mock = require('mock-require')
|
||||
mock.stopAll()
|
||||
const clean = require('../../utils/clean')
|
||||
// const expect = require('chai').expect
|
||||
// const mock = require('mock-require')
|
||||
// mock.stopAll()
|
||||
// const clean = require('../../utils/clean')
|
||||
|
||||
describe('modules/issues/autoAssign.js', () => {
|
||||
beforeEach('clear node cache', () => {
|
||||
clean('src/github')
|
||||
clean('src/utils')
|
||||
clean('src/modules/issues/autoAssign')
|
||||
// describe('modules/issues/autoAssign.js', () => {
|
||||
// beforeEach('clear node cache', () => {
|
||||
// clean('src/github')
|
||||
// clean('src/utils')
|
||||
// clean('src/modules/issues/autoAssign')
|
||||
|
||||
mock('../../../src/utils', {
|
||||
getPkgConfig() {
|
||||
return {}
|
||||
}
|
||||
})
|
||||
mock('../../../src/github', {
|
||||
addAssigneesToIssue() {
|
||||
}
|
||||
})
|
||||
})
|
||||
// mock('../../../src/utils', {
|
||||
// getPkgConfig() {
|
||||
// return {}
|
||||
// }
|
||||
// })
|
||||
// mock('../../../src/github', {
|
||||
// addAssigneesToIssue() {
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
|
||||
it('event name', () => {
|
||||
const autoAssign = require('../../../src/modules/issues/autoAssign')
|
||||
autoAssign(name => {
|
||||
expect(name).to.equal('issues_labeled')
|
||||
})
|
||||
})
|
||||
// it('event name', () => {
|
||||
// const autoAssign = require('../../../src/modules/issues/autoAssign')
|
||||
// autoAssign(name => {
|
||||
// expect(name).to.equal('issues_labeled')
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('set label', () => {
|
||||
it('is ok', (done) => {
|
||||
mock('../../../src/utils', {
|
||||
getPkgConfig() {
|
||||
return {
|
||||
labelToAuthor: {
|
||||
autoAssign: 'github-bot'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
mock('../../../src/github', {
|
||||
addAssigneesToIssue(payload, label) {
|
||||
expect(payload).to.be.a('object').and.not.empty
|
||||
expect(label).to.equal('github-bot')
|
||||
done()
|
||||
}
|
||||
})
|
||||
// describe('set label', () => {
|
||||
// it('is ok', (done) => {
|
||||
// mock('../../../src/utils', {
|
||||
// getPkgConfig() {
|
||||
// return {
|
||||
// labelToAuthor: {
|
||||
// autoAssign: 'github-bot'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// mock('../../../src/github', {
|
||||
// addAssigneesToIssue(payload, label) {
|
||||
// expect(payload).to.be.a('object').and.not.empty
|
||||
// expect(label).to.equal('github-bot')
|
||||
// done()
|
||||
// }
|
||||
// })
|
||||
|
||||
const autoAssign = require('../../../src/modules/issues/autoAssign')
|
||||
autoAssign(function (name, callback) {
|
||||
callback({
|
||||
payload: {
|
||||
label: {
|
||||
name: 'autoAssign'
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
// const autoAssign = require('../../../src/modules/issues/autoAssign')
|
||||
// autoAssign(function (name, callback) {
|
||||
// callback({
|
||||
// payload: {
|
||||
// label: {
|
||||
// name: 'autoAssign'
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
it('is false', (done) => {
|
||||
mock('../../../src/github', {
|
||||
addAssigneesToIssue() {
|
||||
done('error')
|
||||
}
|
||||
})
|
||||
// it('is false', (done) => {
|
||||
// mock('../../../src/github', {
|
||||
// addAssigneesToIssue() {
|
||||
// done('error')
|
||||
// }
|
||||
// })
|
||||
|
||||
const autoAssign = require('../../../src/modules/issues/autoAssign')
|
||||
autoAssign(function (name, callback) {
|
||||
callback({
|
||||
payload: {
|
||||
label: {
|
||||
name: 'error'
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
setTimeout(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
// const autoAssign = require('../../../src/modules/issues/autoAssign')
|
||||
// autoAssign(function (name, callback) {
|
||||
// callback({
|
||||
// payload: {
|
||||
// label: {
|
||||
// name: 'error'
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// setTimeout(done)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
@ -1,69 +1,69 @@
|
||||
/**
|
||||
* @file modules/issues/autoLabel.js test case
|
||||
* @author xuexb <fe.xiaowu@gmail.com>
|
||||
*/
|
||||
// /**
|
||||
// * @file modules/issues/autoLabel.js test case
|
||||
// * @author xuexb <fe.xiaowu@gmail.com>
|
||||
// */
|
||||
|
||||
const expect = require('chai').expect
|
||||
const mock = require('mock-require')
|
||||
mock.stopAll()
|
||||
const clean = require('../../utils/clean')
|
||||
// const expect = require('chai').expect
|
||||
// const mock = require('mock-require')
|
||||
// mock.stopAll()
|
||||
// const clean = require('../../utils/clean')
|
||||
|
||||
describe('modules/issues/autoLabel.js', () => {
|
||||
beforeEach('clear node cache', () => {
|
||||
clean('src/github')
|
||||
clean('src/modules/issues/autoLabel')
|
||||
// describe('modules/issues/autoLabel.js', () => {
|
||||
// beforeEach('clear node cache', () => {
|
||||
// clean('src/github')
|
||||
// clean('src/modules/issues/autoLabel')
|
||||
|
||||
mock('../../../src/github', {
|
||||
addLabelsToIssue() {
|
||||
}
|
||||
})
|
||||
})
|
||||
// mock('../../../src/github', {
|
||||
// addLabelsToIssue() {
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
|
||||
it('event name', () => {
|
||||
const autoLabel = require('../../../src/modules/issues/autoLabel')
|
||||
autoLabel(name => {
|
||||
expect(name).to.equal('issues_opened')
|
||||
})
|
||||
})
|
||||
// it('event name', () => {
|
||||
// const autoLabel = require('../../../src/modules/issues/autoLabel')
|
||||
// autoLabel(name => {
|
||||
// expect(name).to.equal('issues_opened')
|
||||
// })
|
||||
// })
|
||||
|
||||
it('get label success', (done) => {
|
||||
mock('../../../src/github', {
|
||||
addLabelsToIssue(payload, label) {
|
||||
expect(payload).to.be.a('object').and.not.empty
|
||||
expect(label).to.equal('github-bot')
|
||||
done()
|
||||
}
|
||||
})
|
||||
// it('get label success', (done) => {
|
||||
// mock('../../../src/github', {
|
||||
// addLabelsToIssue(payload, label) {
|
||||
// expect(payload).to.be.a('object').and.not.empty
|
||||
// expect(label).to.equal('github-bot')
|
||||
// done()
|
||||
// }
|
||||
// })
|
||||
|
||||
const autoLabel = require('../../../src/modules/issues/autoLabel')
|
||||
autoLabel((name, callback) => {
|
||||
callback({
|
||||
payload: {
|
||||
issue: {
|
||||
body: '我是测试内容\n<!--label:github-bot--><!--label:bot-->测试'
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
// const autoLabel = require('../../../src/modules/issues/autoLabel')
|
||||
// autoLabel((name, callback) => {
|
||||
// callback({
|
||||
// payload: {
|
||||
// issue: {
|
||||
// body: '我是测试内容\n<!--label:github-bot--><!--label:bot-->测试'
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
it('get label error', (done) => {
|
||||
mock('../../../src/github', {
|
||||
addLabelsToIssue() {
|
||||
done('error')
|
||||
}
|
||||
})
|
||||
// it('get label error', (done) => {
|
||||
// mock('../../../src/github', {
|
||||
// addLabelsToIssue() {
|
||||
// done('error')
|
||||
// }
|
||||
// })
|
||||
|
||||
const autoLabel = require('../../../src/modules/issues/autoLabel')
|
||||
autoLabel((name, callback) => {
|
||||
callback({
|
||||
payload: {
|
||||
issue: {
|
||||
body: '我是测试内容'
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
setTimeout(done)
|
||||
})
|
||||
})
|
||||
// const autoLabel = require('../../../src/modules/issues/autoLabel')
|
||||
// autoLabel((name, callback) => {
|
||||
// callback({
|
||||
// payload: {
|
||||
// issue: {
|
||||
// body: '我是测试内容'
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// setTimeout(done)
|
||||
// })
|
||||
// })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user