mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 11:40:36 +03:00
Fix "Add download link to PR" workflow
This commit is contained in:
parent
3a2a5e961b
commit
56809419c2
63
.github/workflows/download-link-on-pr.yml
vendored
63
.github/workflows/download-link-on-pr.yml
vendored
@ -8,33 +8,43 @@ jobs:
|
|||||||
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
|
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
# This snippet is public-domain, taken from
|
# This snippet is public-domain, taken from
|
||||||
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
|
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
|
||||||
script: |
|
script: |
|
||||||
const {owner, repo} = context.repo;
|
async function upsertComment(owner, repo, issue_number, purpose, body) {
|
||||||
const run_id = ${{github.event.workflow_run.id}};
|
const {data: comments} = await github.rest.issues.listComments(
|
||||||
const pull_head_sha = '${{github.event.workflow_run.head_sha}}';
|
{owner, repo, issue_number});
|
||||||
const pull_user_id = ${{github.event.sender.id}};
|
|
||||||
|
|
||||||
const issue_number = await (async () => {
|
const marker = `<!-- bot: ${purpose} -->`;
|
||||||
const pulls = await github.pulls.list({owner, repo});
|
body = marker + "\n" + body;
|
||||||
for await (const {data} of github.paginate.iterator(pulls)) {
|
|
||||||
for (const pull of data) {
|
const existing = comments.filter((c) => c.body.includes(marker));
|
||||||
if (pull.head.sha === pull_head_sha && pull.user.id === pull_user_id) {
|
if (existing.length > 0) {
|
||||||
return pull.number;
|
const last = existing[existing.length - 1];
|
||||||
}
|
core.info(`Updating comment ${last.id}`);
|
||||||
}
|
await github.rest.issues.updateComment({
|
||||||
|
owner, repo,
|
||||||
|
body,
|
||||||
|
comment_id: last.id,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
core.info(`Creating a comment in issue / PR #${issue_number}`);
|
||||||
|
await github.rest.issues.createComment({issue_number, body, owner, repo});
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
if (issue_number) {
|
|
||||||
core.info(`Using pull request ${issue_number}`);
|
|
||||||
} else {
|
|
||||||
return core.error(`No matching pull request found`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const {data: {artifacts}} = await github.actions.listWorkflowRunArtifacts({owner, repo, run_id});
|
const {owner, repo} = context.repo;
|
||||||
|
const run_id = ${{github.event.workflow_run.id}};
|
||||||
|
|
||||||
|
const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }};
|
||||||
|
if (!pull_requests.length) {
|
||||||
|
return core.error("This workflow doesn't match any pull requests!");
|
||||||
|
}
|
||||||
|
|
||||||
|
const artifacts = await github.paginate(
|
||||||
|
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
|
||||||
if (!artifacts.length) {
|
if (!artifacts.length) {
|
||||||
return core.error(`No artifacts found`);
|
return core.error(`No artifacts found`);
|
||||||
}
|
}
|
||||||
@ -43,12 +53,9 @@ jobs:
|
|||||||
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
|
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {data: comments} = await github.issues.listComments({repo, owner, issue_number});
|
core.info("Review thread message body:", body);
|
||||||
const existing_comment = comments.find((c) => c.user.login === 'github-actions[bot]');
|
|
||||||
if (existing_comment) {
|
for (const pr of pull_requests) {
|
||||||
core.info(`Updating comment ${existing_comment.id}`);
|
await upsertComment(owner, repo, pr.number,
|
||||||
await github.issues.updateComment({repo, owner, comment_id: existing_comment.id, body});
|
"nightly-link", body);
|
||||||
} else {
|
}
|
||||||
core.info(`Creating a comment`);
|
|
||||||
await github.issues.createComment({repo, owner, issue_number, body});
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user