How to fetch JSON about a particular repository using github API - rest

I've read the official documentation (GitHub docs) but it's not very clear about fetching information about a particular repo.
I want to fetch information (in JSON) about a particular repo of mine using browser only (and not Postman).
I tried this URL and it is fetching me all the repositories.
https://api.github.com/users/tmtanzeel/repos
But I need info about a particular repo only. I tried these:
https://api.github.com/users/tmtanzeel/repos/angular-project
https://api.github.com/users/tmtanzeel/repos?name=angular-project
https://api.github.com/users/tmtanzeel/repos?id=191101189
But none is working. Please pitch in.

Ok, I got it. I figured it out.
Solution:
Instaed of /<username>/repos we should be doing /repos/<username>.
Sample:
https://api.github.com/repos/tmtanzeel/repo-name
A lot more information you'll find with the above URL:

Related

How do I programmatically extract GitHub repositories that contain a code string?

I am looking for a way to extract GitHub repositories containing files with a certain code string. I can do manually using the GitHub search bar. For instance, if I'm looking for the usages of the library pymc3 I could look for it in the search bar and then click on Code
How does one do this programmatically?
I tried going over the GitHub Search API documentation. The Search Code functionality allows looking into code but that seems to only search based on an user, organization, or repository. The Search Repositories functionality only looks into the description, title and README.
Update 1:
While browsing this post, I believe I found the answer to identify some repositories that contain a code string.
If I write the following code -
url = "https://api.github.com/search/code?q=pymc3 +in:file"
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
I get the following result -
"total_count":43642,"incomplete_results":false,"items":[{"name":"pymc3_stoch_vol ...
However, the result gives me a bunch of information such as the git URL, HTML URL and some of the repositories that contain this string. I need to find a way to extract all the repositories that contain this string.
Update 2:
I now understand that GitHub limits results to 100 per page and 1000 results overall.
The only question remains why I didn't find this information on GitHub Search API documentation? Please do let me know if my understanding or the linked answer is wrong.
This kind of query should be addressed more by GraphQL API, but searching code is still not supported.
Only the new code-search (presented here) might be able to provide that, but:
it is still in beta
its API is not yet public.
So for now, code search in all GitHub repositories is not supported.

How to format request for github api

I'm having trouble formatting my request for the github api.
I have tried looking at the documentation and doing:
https://api.github.com/repos/facebook/react/commits/master?since=2019-01-01&until=2019-12-30
But this only returns one result instead of all commits for the year. I am using the requests library in python, and have also tried it natively in the browser.
Any help appreciated, Thanks.
You are using the Single Commit API with GET /repos/:owner/:repo/commits/:ref
You need List commits API : GET /repos/:owner/:repo/commits :
https://api.github.com/repos/facebook/react/commits?since=2019-01-01&until=2019-12-30&sha=master
You can specify the branch with sha param. If you want the default branch, you can omit this field:
https://api.github.com/repos/facebook/react/commits?since=2019-01-01&until=2019-12-30

How to get a link to a file from a VSO repo

When I browse a GitHub repo, I can copy the URL from the browser, and I can share it like this -
https://github.com/zlatko-michailov/onesql/blob/master/lang/src/onesql.syntax.ts. The file content is returned in the http response stream without any decorations.
How can I do the same thing for a VSO repo? If I have to tweak the URL a little bit, that's OK.
I see the browser uses a REST API that is documented here - https://learn.microsoft.com/en-us/rest/api/azure/devops/git/items/get?view=azure-devops-rest-5.0. I played with different combinations of includeContent, $format, download, etc., but I could only get the content as a separate download, not in the http response body.
The subject file is some CSV data, and the client is Excel, which doesn't seem to be able to handle downloads.
I solved my own problem. There is no need to create a feed.
The API that fetches raw files is sourceProviders. The link is here: https://learn.microsoft.com/en-us/rest/api/azure/devops/build/source%20providers/get%20file%20contents?view=azure-devops-rest-5.0
It is not very well documented - examples for the required parameters are missing. The tricky one is sourceProvider. It has to be tfsgit. Skipping serviceEndpointId worked for me.
Here is the pattern:
GET https://dev.azure.com/{organization}/{project}/_apis/sourceProviders/tfsgit/filecontents?&repository={repository}&commitOrBranch={commitOrBranch}&path={path}&api-version=5.0-preview.1

Azure DevOps/VSTS REST API does not get changes of a changeset

I'm trying to to get the changes of a changeset but it returns 404. I used this:
https://<myname>.visualstudio.com/<projectname>/_apis/tfvc/changesets/291/changes
changeset exists
without the '/changes' it works, returns the changeset info but I also need the merge sources
tried to specify the API version (e.g.: api-version-5.0)
I created a full control Personal Access Token for the client app but no luck. I tried to use this link in the browser and I got the same result: it works only without '/changes'.
What did I wrong?
As this is an old Q, this is for anyone else who has same problem, The projectname needs to be removed from the request.
https://<myname>.visualstudio.com/_apis/tfvc/changesets/291/changes
You look at the docs and sure enough it's not there but most other REST calls require a project name, so it can be confusing.
Also the docs are not very clear that you can interchange https://{myName}.visualstudio.com/ for the documented https://dev.azure.com/{organization}

I've got an error 404 while creating my new repository on Github. How to fix?

This is my first time using Github to host my personal webpage. I've assumed that there is nothing wrong with my repository name which is tonyng.github.io, in which I've followed the format accurately.
However, there just seems to be an error whenever I tried to access the link through tonyng.github.io.
Here are my files for my webpage in this link : https://github.com/tonystaark/tonyng.github.io
Any advice?
So it seems to me that your username is tonystaark but repo name is tonyng.github.io
According to the doc:
If the first part of the repository doesn’t exactly match your
username, it won’t work, so make sure to get it right.