0

I am trying to iterate through a list in a bash script but I keep getting a "Not Found"

#!/bin/bash
for repo in $(gh repo list eljoeyjojo --json name |jq '.[].name'); do
echo $repo
gh api repos/eljoeyjojo/$repo/contributors
done

Expected Result:

    "diner-app"
     username-1 5 contributions
     username-2 2 contributions

    "terraform-vault-core"
     username-1 5 contributions
     username-2 2 contributions

    ...............
    ...............
    ...............

Actual Result:

"diner-app"
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/repos#list-repository-contributors"
}
gh: Not Found (HTTP 404)
"terraform-vault-core"
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/repos#list-repository-contributors"
}
gh: Not Found (HTTP 404)
"whatever-repo"
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/repos#list-repository-contributors"
}
gh: Not Found (HTTP 404)
"flask-hello-world"
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/repos#list-repository-contributors"
}
gh: Not Found (HTTP 404)

If I use a a single variable in that for loop like $REPO1 it works fine but when it iterates in a loop it keep keeps giving me 404 errors.

eljoeyjojo
  • 61
  • 7
  • I don't think `contributors` is a part of the api .. I could be wrong, but I can't find it in the [Documentation](https://cli.github.com/manual/gh_api) – Zak Aug 17 '22 at 20:56
  • `jq` is returning the repo name with quotes around it, which doesn't work in the github URL. See the linked question for how to fix that. – Barmar Aug 17 '22 at 20:57
  • You can see those quotes in the output of `echo $repo`, can't you? – Barmar Aug 17 '22 at 20:58
  • you are right @Barmar and a simple jq -r fixed it so I appreciate the help! thank you so much – eljoeyjojo Aug 17 '22 at 21:03

0 Answers0