-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create issues when the release is failing (#349)
BREAKING CHANGE: Issues will be created or are commented by default . Set the `failComment` or `failTitle` option to `false` to disable this behavior. Co-authored-by: Jonas Schubert <jonas.schubert@siemens.com> Co-authored-by: Florian Greinacher <florian@greinacher.de>
- Loading branch information
1 parent
467a9d4
commit 0ad008e
Showing
12 changed files
with
688 additions
and
78 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const HOME_URL = 'https://github.com/semantic-release/semantic-release'; | ||
|
||
const RELEASE_NAME = 'GitLab release'; | ||
|
||
module.exports = {RELEASE_NAME}; | ||
module.exports = {HOME_URL, RELEASE_NAME}; |
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,62 @@ | ||
const {template} = require('lodash'); | ||
const urlJoin = require('url-join'); | ||
const got = require('got'); | ||
const debug = require('debug')('semantic-release:gitlab'); | ||
const resolveConfig = require('./resolve-config'); | ||
const getRepoId = require('./get-repo-id'); | ||
const getFailComment = require('./get-fail-comment'); | ||
|
||
module.exports = async (pluginConfig, context) => { | ||
const { | ||
options: {repositoryUrl}, | ||
branch, | ||
errors, | ||
logger, | ||
} = context; | ||
const {gitlabToken, gitlabUrl, gitlabApiUrl, failComment, failTitle, labels, assignee} = resolveConfig( | ||
pluginConfig, | ||
context | ||
); | ||
const repoId = getRepoId(context, gitlabUrl, repositoryUrl); | ||
const encodedRepoId = encodeURIComponent(repoId); | ||
const apiOptions = {headers: {'PRIVATE-TOKEN': gitlabToken}}; | ||
|
||
if (failComment === false || failTitle === false) { | ||
logger.log('Skip issue creation.'); | ||
} else { | ||
const encodedFailTitle = encodeURIComponent(failTitle); | ||
const description = failComment ? template(failComment)({branch, errors}) : getFailComment(branch, errors); | ||
|
||
const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${repoId}/issues`); | ||
const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`); | ||
|
||
const openFailTitleIssues = await got(openFailTitleIssueEndpoint, {...apiOptions}).json(); | ||
const existingIssue = openFailTitleIssues.find(openFailTitleIssue => openFailTitleIssue.title === failTitle); | ||
|
||
if (existingIssue) { | ||
debug('comment on issue: %O', existingIssue); | ||
|
||
const issueNotesEndpoint = urlJoin( | ||
gitlabApiUrl, | ||
`/projects/${existingIssue.project_id}/issues/${existingIssue.iid}/notes` | ||
); | ||
await got.post(issueNotesEndpoint, { | ||
...apiOptions, | ||
json: {body: description}, | ||
}); | ||
|
||
const {id, web_url} = existingIssue; | ||
logger.log('Commented on issue #%d: %s.', id, web_url); | ||
} else { | ||
const newIssue = {id: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee}; | ||
debug('create issue: %O', newIssue); | ||
|
||
/* eslint camelcase: off */ | ||
const {id, web_url} = await got.post(issuesEndpoint, { | ||
...apiOptions, | ||
json: newIssue, | ||
}); | ||
logger.log('Created issue #%d: %s.', id, web_url); | ||
} | ||
} | ||
}; |
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,46 @@ | ||
const {HOME_URL} = require('./definitions/constants'); | ||
|
||
const FAQ_URL = `${HOME_URL}/blob/master/docs/support/FAQ.md`; | ||
const GET_HELP_URL = `${HOME_URL}#get-help`; | ||
const USAGE_DOC_URL = `${HOME_URL}/blob/master/docs/usage/README.md`; | ||
const NEW_ISSUE_URL = `${HOME_URL}/issues/new`; | ||
|
||
const formatError = error => `### ${error.message} | ||
${error.details || | ||
`Unfortunately this error doesn't have any additional information.${ | ||
error.pluginName | ||
? ` Feel free to kindly ask the author of the \`${error.pluginName}\` plugin to add more helpful information.` | ||
: '' | ||
}`}`; | ||
|
||
module.exports = (branch, errors) => `## :rotating_light: The automated release from the \`${ | ||
branch.name | ||
}\` branch failed. :rotating_light: | ||
I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again. | ||
You can find below the list of errors reported by **semantic-release**. Each one of them has to be resolved in order to automatically publish your package. I'm sure you can fix this 💪. | ||
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it. | ||
Once all the errors are resolved, **semantic-release** will release your package the next time you push a commit to the \`${ | ||
branch.name | ||
}\` branch. You can also manually restart the failed CI job that runs **semantic-release**. | ||
If you are not sure how to resolve this, here are some links that can help you: | ||
- [Usage documentation](${USAGE_DOC_URL}) | ||
- [Frequently Asked Questions](${FAQ_URL}) | ||
- [Support channels](${GET_HELP_URL}) | ||
If those don't help, or if this issue is reporting something you think isn't right, you can always ask the humans behind **[semantic-release](${NEW_ISSUE_URL})**. | ||
--- | ||
${errors.map(error => formatError(error)).join('\n\n---\n\n')} | ||
--- | ||
Good luck with your project ✨ | ||
Your **[semantic-release](${HOME_URL})** bot :package: :rocket:`; |
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
Oops, something went wrong.