TopherGopher
TopherGopher

Reputation: 673

How can I fetch information about a specific repository in github owned by an Organization?

I'm using the github API to fetch information programmatically about different repositories and I'm running into an issue.

I know I have access to the private repos with my auth key because I was able to programmatically create a repo.

Here's the PHP curl code I'm using:

$url = 'https://api.github.com/orgs/<VALID ORG>/repos';

$headers = array();
$headers[] = 'Authorization: token <myvalidauthtoken>';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$result = curl_exec($ch);
$r = json_decode($result);
curl_close($ch);

Right now this code successfully pulls all the repos from my organization, but we have 500+ repositories, so it's not feasible to pull them ALL down just for information about one repos information. (From http://developer.github.com/v3/repos/#list-organization-repositories)

Now, if I look at user owned repositories (not organization repositories), I find that the request should look like this:

GET /repos/:owner/:repo (http://developer.github.com/v3/repos/#get)

and right now my format is:

GET /orgs/:org/repos (http://developer.github.com/v3/repos/#list-organization-repositories)

so I tried a couple of permutations on URL:

$url = 'https://api.github.com/orgs/<VALID ORG>/repos/<VALIDREPO>';
$url = 'https://api.github.com/<VALID ORG>/<VALIDREPO>';
$url = 'https://api.github.com/repos/<VALID ORG>/repos/<VALIDREPO>';
$url = 'https://api.github.com/repos/orgs/<VALID ORG>/repos/VALIDREPO>';

But ALL of these failed. Any ideas fellow geeks?

Upvotes: 1

Views: 1236

Answers (1)

TopherGopher
TopherGopher

Reputation: 673

I can't believe I did this.

For the record, Nevik was right in the format for organizations:

https://api.github.com/repos/<VALID ORG>/<VALIDREPO>

I set my URL like so:

$url = 'https://api.github.com/repos/$org_name/$repo_name';

See the problem yet?

In PHP, the single quote does not parse internal variables, the double quote does:

$url = "https://api.github.com/repos/$org_name/$repo_name";

And everything was fixed.

Thanks again for the sanity check Nevik!

Upvotes: 1

Related Questions