-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support adding comments for PRs coming from a fork
- Loading branch information
Thomas Neidhart
committed
Sep 13, 2024
1 parent
152ce3c
commit eba8b0b
Showing
2 changed files
with
79 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Add license check comment for PRs coming from a fork | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
add-pr-comment-for-forks: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
if: | | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.head_repository.full_name != github.repository | ||
steps: | ||
- name: 'Download artifact' | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
script: | | ||
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "pr-comment" | ||
})[0]; | ||
var download = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/pr-comment.zip', Buffer.from(download.data)); | ||
- run: unzip pr-comment.zip | ||
|
||
- name: 'Comment on PR' | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
var fs = require('fs'); | ||
const issue_number = Number(fs.readFileSync('./pr.txt')); | ||
const body = fs.readFileSync('./comment.txt', { encoding: 'utf8', flag: 'r' }); | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue_number, | ||
body: body | ||
}); |
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