forked from release-drafter/release-drafter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (42 loc) · 1.72 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
const getConfig = require('probot-config')
const { isTriggerableBranch } = require('./lib/triggerable-branch')
const { findReleases, generateReleaseBody } = require('./lib/releases')
const { findCommits, findPullRequests } = require('./lib/commits')
const log = require('./lib/log')
const configName = 'release-drafter.yml'
module.exports = app => {
app.on('push', async context => {
const defaults = {
'branches': context.payload.repository.default_branch,
'change-template': `* $TITLE (#$NUMBER) @$AUTHOR`,
'no-changes-template': `* No changes`
}
const config = Object.assign(defaults, await getConfig(context, configName) || {})
const branch = context.payload.ref.replace(/^refs\/heads\//, '')
if (!config.template) {
log({ app, context, message: 'No valid config found' })
return
}
if (!isTriggerableBranch({ branch, app, context, config })) {
return
}
const { draftRelease, lastRelease } = await findReleases({ app, context })
const commits = await findCommits({ app, context, branch, lastRelease })
const mergedPullRequests = await findPullRequests({ app, context, commits })
const body = generateReleaseBody({ commits, config, lastRelease, mergedPullRequests })
if (!draftRelease) {
log({ app, context, message: 'Creating new draft release' })
await context.github.repos.createRelease(context.repo({
tag_name: '',
body: body,
draft: true
}))
} else {
log({ app, context, message: 'Updating existing draft release' })
await context.github.repos.editRelease(context.repo({
release_id: draftRelease.id,
body: body
}))
}
})
}