Skip to content

Commit

Permalink
Automatically add type: release and skip-changelog to release PRs (
Browse files Browse the repository at this point in the history
…#59)

Also adds possibility to attach labels to the release PR :

By default it attaches `skip-changelog` and `type: release` to the
newly created release PR. It happened in some occasions that
the release PR leaked into the changelog of the next release, requiring
the release lead to manually remove it.
  • Loading branch information
sunyatasattva authored Feb 25, 2023
2 parents fcba46a + 5987c80 commit ccb50c6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
14 changes: 11 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports =
/***/ ((module) => {

"use strict";
module.exports = JSON.parse("{\"labelTypePrefix\":\"type: \",\"labelTypeMap\":{\"bug\":\"Bug Fixes\",\"regression\":\"Bug Fixes\",\"feature\":\"Features\",\"enhancement\":\"Enhancements\",\"new api\":\"New APIs\",\"experimental\":\"Experiments\",\"task\":\"Various\"},\"groupTitleOrder\":[\"Features\",\"Enhancements\",\"New APIs\",\"Bug Fixes\",\"Performance\",\"Experiments\",\"Documentation\",\"Code Quality\",\"undefined\",\"Various\"],\"rewordTerms\":{\"e2e\":\"end-to-end\",\"url\":\"URL\",\"config\":\"configuration\",\"docs\":\"documentation\"},\"needsDevNoteLabel\":\"status:needs-dev-note\",\"labelsToOmit\":[\"skip-changelog\"]}");
module.exports = JSON.parse("{\"labelTypePrefix\":\"type: \",\"labelTypeMap\":{\"bug\":\"Bug Fixes\",\"regression\":\"Bug Fixes\",\"feature\":\"Features\",\"enhancement\":\"Enhancements\",\"new api\":\"New APIs\",\"experimental\":\"Experiments\",\"task\":\"Various\"},\"groupTitleOrder\":[\"Features\",\"Enhancements\",\"New APIs\",\"Bug Fixes\",\"Performance\",\"Experiments\",\"Documentation\",\"Code Quality\",\"undefined\",\"Various\"],\"rewordTerms\":{\"e2e\":\"end-to-end\",\"url\":\"URL\",\"config\":\"configuration\",\"docs\":\"documentation\"},\"needsDevNoteLabel\":\"status:needs-dev-note\",\"labelsToOmit\":[\"skip-changelog\"],\"releasePRLabels\":[\"skip-changelog\",\"type: release\"]}");

/***/ }),

Expand Down Expand Up @@ -460,9 +460,11 @@ const insertNewChangelogEntry = ( contents, changelog, releaseVersion ) => {
const regex = /== Changelog ==\n/;
return contents.replace(
regex,
`== Changelog ==\n\n= ${ releaseVersion } - ${ new Date().toISOString().split('T')[0] } =\n\n${ changelog }`
`== Changelog ==\n\n= ${ releaseVersion } - ${
new Date().toISOString().split( 'T' )[ 0 ]
} =\n\n${ changelog }`
);
}
};

/**
* Inserts the new changelog entry into the readme file contents
Expand Down Expand Up @@ -742,6 +744,12 @@ const branchHandler = async ( context, octokit, config ) => {
compile( initialChecklistTemplate )( templateData )
);

await octokit.issues.addLabels( {
...context.repo,
issue_number: prCreated.data.number,
labels: config.releasePRLabels,
} );

await octokit.issues.createComment( {
...context.repo,
issue_number: prCreated.data.number,
Expand Down
6 changes: 5 additions & 1 deletion lib/automations/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ This is a label your project uses to indicate pull requests that require some ad

You can add any labels here that the changelog generator should use as a signal to omit the pull request from being included in the generated changelog.

**`releasePRLabels`**

You can add any labels here which will be attached to the new PR automatically created for each release. It defaults to adding `type: release` and `skip-changelog`.

## API

### Inputs
Expand All @@ -127,4 +131,4 @@ You can add any labels here that the changelog generator should use as a signal

### Outputs

_None._
_None._
12 changes: 10 additions & 2 deletions lib/automations/release/branch-create-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ const insertNewChangelogEntry = ( contents, changelog, releaseVersion ) => {
const regex = /== Changelog ==\n/;
return contents.replace(
regex,
`== Changelog ==\n\n= ${ releaseVersion } - ${ new Date().toISOString().split('T')[0] } =\n\n${ changelog }`
`== Changelog ==\n\n= ${ releaseVersion } - ${
new Date().toISOString().split( 'T' )[ 0 ]
} =\n\n${ changelog }`
);
}
};

/**
* Inserts the new changelog entry into the readme file contents
Expand Down Expand Up @@ -323,6 +325,12 @@ const branchHandler = async ( context, octokit, config ) => {
compile( initialChecklistTemplate )( templateData )
);

await octokit.issues.addLabels( {
...context.repo,
issue_number: prCreated.data.number,
labels: config.releasePRLabels,
} );

await octokit.issues.createComment( {
...context.repo,
issue_number: prCreated.data.number,
Expand Down
4 changes: 4 additions & 0 deletions lib/automations/release/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
"needsDevNoteLabel": "status:needs-dev-note",
"labelsToOmit": [
"skip-changelog"
],
"releasePRLabels": [
"skip-changelog",
"type: release"
]
}
1 change: 1 addition & 0 deletions lib/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
* @property {Array<string>} labelsToOmit When any label in this array is attached to
* an issue/pull, then the entry should be
* ignored in the changelog.
* @property {Array<string>} releasePRLabels Labels to add to the release PR.
*/

module.exports = {};

0 comments on commit ccb50c6

Please sign in to comment.