-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr.js
38 lines (34 loc) · 1007 Bytes
/
pr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const rq = require('./rq')
const config = require('config')
const count = config.count
const co = require('co')
const prdata = require('./fixtures/github-hook.json')
const _ = require('lodash')
const crypto = require('crypto')
const mockHook = _.cloneDeep(prdata.mergeRequest.open)
const secret = config.webHookSecret
const createPr = function * (num) {
for (let i = 1; i <= num; i = i + 1) {
_.set(
mockHook,
'pull_request.title',
`#${config.taskNo}-${i} 集成 github pr 操作`
)
mockHook.i = i
const localSig = githubHmac(JSON.stringify(mockHook), secret)
mockHook.headers = {
'x-github-event': 'pull_request',
'x-hub-signature': localSig
}
yield done => rq.create_integration(mockHook, done)
}
}
co(function * () {
yield createPr(count)
}, function (err, result) {
console.log(err, result)
})
function githubHmac (blob, secret) {
const hmac = crypto.createHmac('sha1', secret)
return `sha1=${hmac.update(blob).digest('hex')}`
}