mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 08:06:23 +00:00
When the workflow is triggered from a fork the permissions for the `GITHUB_TOKEN` are read-only. This chane skips the write operations if we're running from a fork. See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-events-for-forked-repositories
42 lines
1.3 KiB
YAML
42 lines
1.3 KiB
YAML
name: Pull Request Test
|
|
|
|
on:
|
|
pull_request:
|
|
branches: main
|
|
types: [opened, synchronize]
|
|
|
|
jobs:
|
|
pull-request-test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- uses: ./
|
|
with:
|
|
script: |
|
|
// Get the existing comments.
|
|
const {data: comments} = await github.issues.listComments({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.payload.number,
|
|
})
|
|
|
|
if (context.payload.pull_request.head.repo.full_name !== 'actions/github-script') {
|
|
console.log('Not attempting to write comment on PR from fork');
|
|
} else {
|
|
if (botComment) {
|
|
await github.issues.updateComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
comment_id: botComment.id,
|
|
body: commentBody
|
|
})
|
|
} else {
|
|
await github.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.payload.number,
|
|
body: commentBody
|
|
})
|
|
}
|
|
}
|