peter-evans / slash-command-dispatch

A GitHub action that facilitates "ChatOps" by creating repository dispatch events for slash commands
MIT License
583 stars 53 forks source link

Issue with viewing repository collaborators #352

Closed prateekdesai04 closed 1 month ago

prateekdesai04 commented 1 month ago

Below is our workflow which was running fine and suddenly broke:

name: Slash Command Dispatch
on:
  issue_comment:
    types: [created]
jobs:
  slashCommandDispatch:
    runs-on: ubuntu-latest
    if: ${{ github.event.issue.pull_request }}
    steps:
      - name: Get PR SHA
        id: sha
        uses: actions/github-script@v4
        with:
          result-encoding: string
          script: |
            const { owner, repo, number } = context.issue;
            const pr = await github.pulls.get({
              owner,
              repo,
              pull_number: number,
            });
            return pr.data.head.sha
      - name: Get PR number
        id: pr_number
        uses: actions/github-script@v4
        with:
          result-encoding: string
          script: |
            const { owner, repo, number } = context.issue;
            return number
      - name: Get Forked Repository and Branch
        id: pr_info
        run: |
          # Use the GitHub API to fetch information about the pull request
          pr_info=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \
                      "https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.pr_number.outputs.result }}")
          # Extract the forked repository and branch from the pull request info
          forked_repo=$(echo "$pr_info" | jq -r '.head.repo.full_name')
          forked_branch=$(echo "$pr_info" | jq -r '.head.ref')
          echo "Forked Repository: $forked_repo"
          echo "Forked Branch: $forked_branch"
          echo "FORK_NAME=$forked_repo" >> $GITHUB_OUTPUT
          echo "FORK_BRANCH=$forked_branch" >> $GITHUB_OUTPUT
      - name: Slash Command Dispatch
        id: scd
        uses: peter-evans/slash-command-dispatch@v4
        with:
          token: ${{ secrets.PAT }}
          permission: write
          commands: |
            benchmark
            platform_tests
          dispatch-type: workflow
          static-args: |
            repository=${{ github.repository }}
            comment-id=${{ github.event.comment.id }}
            pr-sha=${{ steps.sha.outputs.result }}
            branch_or_pr_number=PR-${{ steps.pr_number.outputs.result }}
            fork_info=${{ steps.pr_info.outputs.FORK_NAME }}|${{ steps.pr_info.outputs.FORK_BRANCH }}
      - name: Edit comment with error message
        if: steps.scd.outputs.error-message
        uses: peter-evans/create-or-update-comment@v4
        with:
          comment-id: ${{ github.event.comment.id }}
          body: |
            > ${{ steps.scd.outputs.error-message }}

image

Could you suggest a fix or provide your insights on this issue?

peter-evans commented 1 month ago

Hi @prateekdesai04

Check that the PAT hasn't expired, and the user associated with the PAT still has access to read the collaborators of the repo.

prateekdesai04 commented 1 month ago

Thanks @peter-evans it was a PAT issue on our end!