-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename and get it all working w/ Probot 7
- Loading branch information
1 parent
ceb5649
commit 25f88dc
Showing
18 changed files
with
389 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,42 @@ | ||
const run = require('./lib/run') | ||
const configName = 'draftah.yml' | ||
const getConfig = require('probot-config') | ||
const { isRelevantBranch } = require('./lib/branch') | ||
const { findReleases, generateBody } = require('./lib/releases') | ||
const { findMergedPullRequests } = require('./lib/pull-requests') | ||
|
||
module.exports = robot => { | ||
robot.on('push', async context => { | ||
await run({ robot, context, configName }) | ||
const configName = 'release-drafter.yml' | ||
|
||
module.exports = app => { | ||
app.on('push', async context => { | ||
const config = await getConfig(context, configName) || {} | ||
const { body: template } = config | ||
const branch = context.payload.ref.replace(/^refs\/heads\//, '') | ||
|
||
if (!template) { | ||
app.log(`No valid config found`) | ||
return | ||
} | ||
|
||
if (!isRelevantBranch({ branch, app, context, config })) { | ||
return | ||
} | ||
|
||
const { draftRelease, lastRelease } = await findReleases({ context }) | ||
const mergedPullRequests = await findMergedPullRequests({ app, context, branch, lastRelease }) | ||
|
||
const body = generateBody({ template, lastRelease, mergedPullRequests }) | ||
|
||
if (!draftRelease) { | ||
app.log(`Creating new draft release`) | ||
await context.github.repos.createRelease(context.repo({ | ||
body: body, | ||
draft: true | ||
})) | ||
} else { | ||
app.log(`Updating existing draft release`, { draftRelease }) | ||
await context.github.repos.editRelease(context.repo({ | ||
release_id: draftRelease.id, | ||
body: body | ||
})) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports.encodeContent = (content) => { | ||
return Buffer.from(content).toString('base64') | ||
} | ||
|
||
module.exports.decodeContent = (content) => { | ||
return Buffer.from(content, 'base64').toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports.isRelevantBranch = ({ app, context, branch, config }) => { | ||
const validBranches = config.branches || [context.payload.repository.default_branch] | ||
const relevant = validBranches.indexOf(branch) !== -1 | ||
if (!relevant) { | ||
app.log(`Ignoring push. ${branch} is not one of: ${validBranches.join(', ')}`) | ||
} | ||
return relevant | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const compareVersions = require('compare-versions') | ||
|
||
module.exports.findReleases = async ({ context }) => { | ||
let releases = await context.github.paginate( | ||
context.github.repos.getReleases(context.repo()), | ||
res => res.data | ||
) | ||
|
||
const sortedPublishedReleases = releases | ||
.filter(r => !r.draft) | ||
.sort((r1, r2) => compareVersions(r1.tag_name, r2.tag_name)) | ||
|
||
return { | ||
draftRelease: releases.find((r) => r.draft), | ||
lastRelease: sortedPublishedReleases[sortedPublishedReleases.length - 1] | ||
} | ||
} | ||
|
||
module.exports.generateBody = ({ template, lastRelease, mergedPullRequests }) => { | ||
let body = template | ||
|
||
if (lastRelease) { | ||
body = body.replace('$PREVIOUS_TAG', lastRelease.tag_name) | ||
} | ||
|
||
if (lastRelease) { | ||
if (mergedPullRequests.length === 0) { | ||
body = body.replace('$CHANGES', '* No changes') | ||
} else { | ||
body = body.replace('$CHANGES', mergedPullRequests.map(pr => ( | ||
`* ${pr.title} #${pr.number} (@${pr.user.login})` | ||
)).join('\n')) | ||
} | ||
} | ||
|
||
return body | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.