Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(actions): add action to omit PR from changelog #10984

Merged
merged 9 commits into from
Dec 10, 2024
39 changes: 39 additions & 0 deletions .github/scripts/omitPrFromChangelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-check
const {
labels: { planning },
} = require("./support/resources");

/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */
module.exports = async ({ github, context }) => {
const { repo, owner } = context.repo;
const payload = /** @type {import('@octokit/webhooks-types').PullRequestLabeledEvent} */ (context.payload);
const {
label,
pull_request: { number },
} = payload;

const pullRequestBody = payload.pull_request.body;
const ommitComment = `\n\nBEGIN_COMMIT_OVERRIDE\nEND_COMMIT_OVERRIDE`;

if (!pullRequestBody) {
console.log("No issue body was found");
return;
}

if (label?.name === planning.noChangelogEntry) {
const pullRequestProps = {
owner,
repo,
pull_number: number,
};

const newPullRequestBody = pullRequestBody + ommitComment;

await github.rest.pulls.update({
...pullRequestProps,
body: newPullRequestBody,
});
} else {
console.log(`The \`no changleog entry\` label is not present on this PR.`);
}
};
1 change: 1 addition & 0 deletions .github/scripts/support/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const resources = {
needsMilestone: "needs milestone",
spike: "spike",
spikeComplete: "spike complete",
noChangelogEntry: "no changelog entry",
},
priority: {
low: "p - low",
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/omit-pr-from-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Remove PR from changelog
on:
pull_request:
types:
- labeled
- opened
branches:
- dev
jobs:
product-label:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Add omit comment to PR
uses: actions/github-script@v7
with:
script: |
const action = require('${{ github.workspace }}/.github/scripts/omitPrFromChangelog.js')
await action({github, context, core})
Loading