0

Using curl --user "UserName" https://api.github.com/orgs/org/repos gives a lot of extra output. How do you use the GitHub api to output all repo names, for example:

  • Repo1
  • Repo2
  • Repo3
blashmet
  • 249
  • 1
  • 4
  • 15
  • Show us what you've tried? GitHub has pretty extensive documentation for their APIs, and I suspect you can find many examples via your favorite search engine or even here on StackOverflow. – larsks Jun 26 '15 at 00:18
  • I tried a lot of things, but didn't want to complicate the question (it seems like I included everything in the "specific reason" above: desired behavior, specific problem, and shortest code, so I'm not sure what the problem is). Since you asked, here they are: 1. $ curl --user "UserName" https://api.github.com/orgs/org/repos | test.txt grep -o -p '.*name="\K.*?(?=".*)' test.txt 2. $ curl --user "UserName" https://api.github.com/orgs/org/repos | grep -Po 'name="\K.*?(?=")' 3. curl --user "UserName" https://api.github.com/orgs/orgs/repos | grep '"name":' – blashmet Jun 26 '15 at 16:01
  • use `jq`... e.g., `curl --user "UserName" https://api.github.com/orgs/org/repos | jq '.[].name'`. Get `jq` [here](https://stedolan.github.io/jq/) – CharlieC Mar 24 '17 at 21:09

1 Answers1

1

I think you're on the right track - you have selected the right API (https://developer.github.com/v3/repos/#list-organization-repositories).

Since the response is JSON, you would ideally use a JSON tool to filter the content, but you can start with a simple grep like this:

curl --user "UserName" https://api.github.com/orgs/org/repos | grep "full_name"

This will print all of the repo names. You can extend that solution with more elaborate logic if you like.

Related:

Community
  • 1
  • 1
nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • Thanks for the starter! This was simpler than I thought. Using curl --user "UserName" https://api.github.com/orgs/orgs/repos | grep '"name":' still gives a lot of extra content: '% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 --:--:-- --:--:-- --:--:-- 0 "name": "OctopusDeploy-PowerShell-Modules", "name": "GuardRail-PowerShell-Modules", "name": "Infrastructure-PowerShell-Modules",1 "name": "Deployment-PowerShell-Modules",0' How do I extract the name only? – blashmet Jun 26 '15 at 16:03
  • From this post [link] http://stackoverflow.com/questions/13242469/how-to-use-sed-grep-to-extract-text-between-two-words, I tried: '$ curl --user "UserName" https://api.github.com/orgs/org/repos | grep '"name":"\K.*?(?=")' But it doesn't output anything. I thought it might be because there is a space after the : that is not being interpreted, but I tried back-ticking it with no luck: '$ curl --user "UserName" https://api.github.com/orgs/org/repos | grep '"name":` "\K.*?(?=")' – blashmet Jun 26 '15 at 16:14
  • 1
    use `jq`... e.g., `curl --user "UserName" https://api.github.com/orgs/org/repos | jq '.[].name'`. Get `jq` [here](https://stedolan.github.io/jq/) – CharlieC Mar 24 '17 at 21:07