GitHub API - get details of multiple repositories - github

I am putting together a page that lists the plugins for the Knockout library.
Right now I am using a simple list of repositories, e.g.
[
"civicsource/knockout-responsive"
"civicsource/knockout-spin"
"civicsource/knockout-transitions"
"CraigCav/Knockout-jqGridBinding"
"CraigCav/ko.datasource"
]
Then getting the details for each of those repositories with the GitHub API with e.g.
$.getJSON("https://api.github.com/repos/" + identity)
These results are cached for a few hours in localStorage, so the client isn't re-requesting them every few minutes.
This is okay for the moment because the GitHub API has a rate-limit of 60 per hour and there are currently 58 plugins in the list.
However, when we breach 60 plugins, we will not be able to load within an hour the details of all the items on the list.
Two solutions come to mind, namely having some server-side caching, or alternatively asking GitHub if they'll up the limit for this page to whatever the number of plugins is.
A better solution would be to reduce the number of requests, in particular request the details of all these plugins in one GitHub API call. I was unable to find a suitable on in the GitHub API documentation.
Is there a hook in the GitHub API to get the details of multiple repositories in a single call?

Is there a hook in the GitHub API to get the details of multiple repositories in a single call?
No, that's not possible currently with the GitHub API. You can only fetch a list of repositories from a specific user (or org) or a list of all public repositories. You can't say "give me the information for repositories X, Y and Z" in a single request.

Related

Best way to get Github repository info using Service Account

We're building a microservice to interact with Github REST API to read repository information within our organization. At the moment, we use individual user id and personal access token (created for the user id) to access the remote api programmatically.
Our requirement is to have a service account to access the api that has read privileges and no coupling with any individual. I was looking at Github Apps to perform the integration but it seem a bit complicated for our purpose as it focuses on making changes and handling events. We only need to read the repositories and collect information such as pull requests, commits etc. done on those repositories.
Are there any other simpler ways to achieve this?

Azure Devops - How to get published information of a wiki page using Rest API

I referred this Microsoft document "MS Rest API documentation for wiki" and was able to get all the pages available in wiki. I was trying to get the published author and published time related information for which there is no available reference.
Is there any Azure DevOps Rest API available to get this information?
Azure Devops - How to get published information of a wiki page using Rest API
I am afraid there is no such REST API at this moment, however you can track it by tools such as Fiddler or press F12 in Chrome browser then select Network.
On the web UI, we could access the View revisions of the Wiki:
We could get the history of this Wiki:
Then we press F12 and click the first history, we could get the REST API like below:
https://dev.azure.com/<OrganizationName>/<ProjectName>/_apis/git/repositories/<WikiName>/Commits/<CommitsId>?
But, if we want to automate it by REST API, This seems impossible at the moment.
To automate it, we need to get the first commit ID for the Wiki, I could use the REST API:
https://dev.azure.com/<OrganizationName>/<ProjectName>/_apis/git/repositories/<WikiName>/Commits/?
Now, I could get the all the commits, but those commits for all Wiki files, and there are no other parameters that can be used to filter out which wiki document the commit is associated with. So, we could not get the first commit for each wiki automatically. That is the current limitation.
Hope this helps.
You can get commits from specific pages: searchCriteria.itemPath=
Here is doc:
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get-commits?view=azure-devops-rest-6.0
Wiki page path will be: /WikiName/Folder--Name/Page-Name.md
Keep in mind that space in page name or folder name you need to replace with '-'. Also add extension to the page '.md'

Get All Issues on GitHub repository in specific month using GitHub API

I am trying to get all Pull requests created by specific user in a specific month in my django application using GitHub API.
e.g:
https://api.github.com/repos/myrepo/example/issues?creator=person_name&start_date=2018-1-1&end_date=2018-1-31
You can find issues created by a user in a given month using the search issues API endpoint, e.g.
https://api.github.com/search/issues?q=author:username+created:2018-01-01..2018-01-31
created can take a value like YYYY-MM-DD..YYYY-MM-DD to set a date range.
You might also want to add type:issue so you don't see pull requests or repo:user-or-org/repo to restrict results to a single repository.
Note that there are restrictions on searching users' contributions, including issues. You may need to have your users authenticate before you can search their issues. You should be able to try the endpoint out with your own user account, as long as you've got an authenticated session (e.g. by using a search URL in a browser where you're logged into GitHub).

Is there a GitHub API to get autocomplete suggestions for user/organization name?

I know how to get the list of organizations for a user.
However, I want to let the user type in the user/organization name and provide autocomplete for that name where the autocomplete includes all user/organizations, not just the organizations they belong to.
It would be too long to get the entire list (and I am not sure that GitHub even exposes that), but the top 5-20 for any given prefix is all I want.
The Search API smells more like a single transaction search and not an autocomplete API, so while I could use it, most likely it would hit the rate limit too often and give a bad UX.
There is something close to this with https://github.com/autocomplete/users?q=prefix, but that is not part of the official GitHub API, so I know that the back end does support these kind of queries... I am just not finding it from the API documentation, and I don't want to access a non-API URL.
GitHub does not do this for you and likely never will. One option you have is to construct a service like that yourself and constantly update your list of users. One way to update the list of users (sanely) is to do the following:
Make an initial GET to /users?per_page=100
Save the ETag header that's returned and use pagination to get all of the most recent ones
On future requests send along the ETag and when there are new users, save the newest ETag.
Repeat.
So you'll be able to then build an auto-completion service yourself so long as you keep your listing of GitHub users up-to-date.
Also note, that sending along the ETag will save your ratelimit if there is nothing new to return.

Can I query the Github API for my repository quota?

I'm working on an app that creates private Github repositories (among other things). Every once in a while, we are over quota with our private repos.
I'd like to know how many repositories we have left before making the API call that will fail.
Can that be done, using the Github API? I couldn't find anything in the documentation, but that's doesn't mean it's not possible :)
awendt, I'm not quite familiar with private quotas, but authenticated users receive a Plan object when the API returns the call to /user. This will tell you what plan you have and will tell you how many private_repos you're allowed. With that information and the information from /user which tells you how many private repos you currently have, you should be able to figure it out.
Then again, you could use github3.py and you'd have the User object, with the plan attribute and could use those two together as described above.
Disclaimer I'm github3.py's author.