How can a Github workflow read a file on another private repository hosted on the same GitHub account?

I have a private git repository like:

I have a test.json file in another private repository in the same GitHub subscription and account like:

How can a workflow in repo1 have http get access to the url ?

All I need is a simple way to read the content of test.json in a workflow running on repo2 .

It works the best for me to read the file using a curl get request.

You can use a Personal Access Token (PAT) with the repo scope to authorize the request to the URL for the file. If you add the PAT as a secret for your repository, you can do something like this:

- name: get file
    TOKEN: ${{ secrets.repo_token }}
  run: |
    curl -H "Authorization: token ${TOKEN}"

Thank you so much for help.

Any suggestion for learning path where do I learn details like this?

1 Like

You’re welcome! :smiley_cat:

Nothing too specific, I’m afraid. The key here is knowing that PATs can be used to authorize all sorts of things. I then just checked the documentation on scopes to see which would be needed, and tried downloading a file from a private repository to make sure it’d actually work. I picked up most of the general concepts by poking around the documentation and reading here on the forum. :wink:

1 Like