Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the API to download diff from private project #282

Open
asudhak opened this issue Aug 17, 2022 · 2 comments
Open

Using the API to download diff from private project #282

asudhak opened this issue Aug 17, 2022 · 2 comments
Labels
question A question on how to use this action

Comments

@asudhak
Copy link

asudhak commented Aug 17, 2022

The README has a good example to obtain the diff of a given pull request using
const diff_url = context.payload.pull_request.diff_url

However, there's a note that says "(Note that this particular example only works for a public URL, where the diff URL is publicly accessible. Getting the diff for a private URL requires using the API.)"

What does using the API mean ? How do I add credentials to the github oktokit client to allow it to fetch the diff URL from my private repo ? The diff_url I'm trying to access is part of the same project in which the workflow runs.

@philip-gai
Copy link
Member

This is likely related to #272.

Using the octokit exposed via the github argument, you should be able to retreive the diff, however it does not work because of the above issue. For example, this should work but it does not with actions/github-script:

# This does not work because headers are stripped
name: Get PR diff
on: pull_request
jobs:
  diff:
    name: Diff
    runs-on: ubuntu-latest
    steps:
      - name: Diff
        uses: actions/github-script@v6.1.1
        with:
          script: |
            const pull_url = context.payload.pull_request.url
            const result = await github.rest.pulls.get({
              ...context.repo,
              pull_number: context.payload.pull_request.number,
              mediaType: {
                format: "diff",
              },
            });
            console.log(result)

@joshmgross joshmgross added the question A question on how to use this action label Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question on how to use this action
Projects
None yet
Development

No branches or pull requests

4 participants