chore: use changeset feedback action

Signed-off-by: djamaile <rdjamaile@gmail.com>
This commit is contained in:
djamaile
2022-12-09 11:19:02 +01:00
parent d0f063e873
commit 833872e55b
@@ -21,75 +21,10 @@ jobs:
if: github.repository == 'backstage/backstage' && github.event.pull_request.user.login != 'backstage-service'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: backstage/actions/changeset-feedback@v0.5.9
with:
# Fetch the commit that's merged into the base rather than the target ref
# This will let us diff only the contents of the PR, without fetching more history
ref: 'refs/pull/${{ github.event.pull_request.number }}/merge'
- name: fetch base
run: git fetch --depth 1 origin ${{ github.base_ref }}
# We avoid using the in-source script since this workflow has elevated permissions that we don't want to expose
- name: Generate Feedback
id: generate-feedback
run: |
rm -f generate.js
wget -O generate.js https://raw.githubusercontent.com/backstage/backstage/master/scripts/generate-changeset-feedback.js 1>&2
node generate.js FETCH_HEAD > feedback.txt
- name: Post Feedback
uses: actions/github-script@v6
env:
ISSUE_NUMBER: ${{ github.event.pull_request.number }}
with:
script: |
const owner = "backstage";
const repo = "backstage";
const marker = "<!-- changeset-feedback -->";
const feedback = require('fs').readFileSync('feedback.txt', 'utf8');
const issue_number = Number(process.env.ISSUE_NUMBER);
const body = feedback.trim() ? feedback + marker : undefined
const existingComments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
});
const existingComment = existingComments.find((c) =>
c.user.login === "github-actions[bot]" &&
c.body.includes(marker)
);
if (existingComment) {
if (body) {
if (existingComment.body !== body) {
console.log(`updating existing comment in #${issue_number}`);
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body,
});
} else {
console.log(`skipped update of identical comment in #${issue_number}`);
}
} else {
console.log(`removing comment from #${issue_number}`);
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: existingComment.id,
body,
});
}
} else if (body) {
console.log(`creating comment for #${issue_number}`);
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
diffRef: 'refs/pull/${{ github.event.pull_request.number }}/merge'
github-token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
issue-number: ${{ steps.pr-number.outputs.pr-number }}