0

I'm trying to get a list of an organisation's repositories, including private ones. The thing is, we have an enterprise deployment.

I've tried the solutions in How to list organization's private repositories via GitHub API?, but they're all related with an organisation using Github's servers, not an enterprise deployment.

Looking at the Get a repository docs, this seems fairly simple:

$ TOKEN="my_access_token_goes_here"
$ curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $TOKEN" \
  https://github.example.com/api/v3/repos/example/a_public_repo
{
  "id": 1234,
  "node_id": "ayz3BCDE...",
  "name": "a_public_repo",
  "full_name": "example/a_public_repo",
  "private": false,
  "owner": {
  ...
  },

So now I tried getting a private repo:

$ curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $TOKEN" \
  https://github.example.com/api/v3/repos/example/a_private_repo
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/enterprise-server@3.7/rest/reference/repos#get-a-repository"
}

The example/a_private_repo does exist and my user does have write access to it (I regularly commit code to it).

The token has the repo:status permission, which according to the docs:

Grants read/write access to commit statuses in public, private, and internal repositories. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.

I don't get an authentication error, or a 403 error, so I don't know if I'm using a bad URL, an authenticaton problem, or something else.

Any help is appreciated! Cheers!

Leonardo
  • 1,533
  • 17
  • 28

1 Answers1

0

Using HitHub CLI to get the repo

$ echo "my_access_token_goes_here" > mytoken.txt
$ gh auth login --hostname github.example.com --with-token < mytoken.txt
error validating token: missing required scopes 'repo', 'read:org'

That gave me a clue that I do have an authentication problem. I tried generating a new access token with the repo and read:org permissions:

$ echo "my_new_access_token_goes_here" > mytoken.txt

$ gh auth login --hostname github.example.com --with-token < mytoken.txt
$ gh api \
  -H "Accept: application/vnd.github+json" \
  --hostname github.example.com \
  /repos/example/a_public_repo
{
  "id": 1234,
  "node_id": "ayz3BCDE...",
  "name": "a_public_repo",
  "full_name": "example/a_public_repo",
  "private": false,
  "owner": {
  ...
  },

$ gh api \
  -H "Accept: application/vnd.github+json" \
  --hostname github.example.com \
  /repos/example/a_private_repo
{
  "id": 5678,
  "node_id": "fdkhbwe3de...",
  "name": "a_private_repo",
  "full_name": "example/a_private_repo",
  "private": true,
  "owner": {
  ...
  },

Retying with cURL:

$ TOKEN="my_new_access_token_goes_here"
$ curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $TOKEN" \
  https://github.example.com/api/v3/repos/example/a_private_repo
{
  "id": 5678,
  "node_id": "fdkhbwe3de...",
  "name": "a_private_repo",
  "full_name": "example/a_private_repo",
  "private": true,
  "owner": {
  ...
  },

Hope this helps anyone with the same problem. Cheers!

Leonardo
  • 1,533
  • 17
  • 28