forked from uiur/github-pr-release
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.4 KB
/
index.js
File metadata and controls
50 lines (41 loc) · 1.4 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
var fs = require('fs')
var releaseMessage = require('./lib/release-message.js')
var GithubClient = require('./lib/github-client.js')
var path = require('path')
const createReleasePR = (config) => {
var client = new GithubClient(config)
return client.prepareReleasePR().then((releasePR) => {
// this is just attach label to PR, which should not disturp main process.
client.addReleasePRLabel(releasePR.number)
return client.collectReleasePRs(releasePR).then((prs) => {
if (typeof config.mapFunction === 'function') {
prs = prs.map(config.mapFunction)
}
var templatePath = config.template || path.join(__dirname, 'release.mustache')
var template = fs.readFileSync(templatePath, 'utf8')
var message = releaseMessage(template, prs)
client.assignReviewers(releasePR, prs)
client.updatePR(releasePR, message)
return { prs, releasePR }
})
})
}
const getPRsInMergedReleasePR = (config) => {
var client = new GithubClient(config)
return client.getLatestMergedReleasePR().then((releasePR) => {
if (releasePR) {
return client.collectReleasePRs(releasePR).then((prs) => {
const targets = prs.filter(function (pr) {
return pr.number !== releasePR.number
})
return { prs: targets, releasePR }
})
} else {
return null
}
})
}
module.exports = {
createReleasePR,
getPRsInMergedReleasePR
}