Github Pinned Repositories REST call without using graphQl - rest

I'm trying to sort out how to make a call to Github's API to get a hold of my pinned repos but I can't seem to find anything from Github's documentation using a REST call.
I did find this which uses graphql and does what I want but I'm not looking to spin up another server for this project.
so far I'm using https://api.github.com/users/USERNAME/repos. Has a good amount of what I want but nothing for pinned repos.
anyone know?

As #Wilhelm said, you do not need your own servers to make a GraphQL call.
Have a look here to get started.
Briefly,
https://api.github.com/graphql POST request
Authorization: bearer <token> header
{ "query": "query MyQueryToGithub { ... }" } JSON payload

Related

How to call an backend api and fetch result to show on react admin dashboard?

I have an API for my backend which gives some JSON data in response. React Admin allow data to be shown using a DATA provider. I have tried all the data provider but none of them give me the results.
I have this API Method:
GET http://localhost:8081/customer/status/{phone_no}
which gives response as :
[
{
"mobile_number": "98160******",
"status": true
}
]
So here I want to get this data in my list view and show it on the dashboard. Is there any way to do this. I have also used the jsonDataProvider. It is not also working.
I need this to be fixed very soon. If someone know how to do that pls ping.
What error is it giving you? Use the developer tools to see the errors.
Most of the time, it is probably that you need to add Content-Range header to your API:
See below documentation from the Data Providers section:
Note: The simple REST client expects the API to include a Content-Range header in the response to getList calls. The value must be the total number of resources in the collection. This allows react-admin to know how many pages of resources there are in total, and build the pagination controls.
Content-Range: posts 0-24/319
If your API is on another domain as the JS code, you’ll need to whitelist this header with an Access-Control-Expose-Headers CORS header.
Access-Control-Expose-Headers: Content-Range
Thanks

How can I get a JSON response from Github's REST API?

I'm trying to use this guide to get a list of all issues from a repository. For example, let's look at the facebook/react repository.
When I do a GET request to https://github.com/facebook/react/issues/ it just returns the web page, but what I want is a JSON with all the issues.
How can I get a JSON response?
You need to use the API's root endpoint, on the api subdomain:
GET https://api.github.com/repos/facebook/react/issues
^^^^

Are there any ways to get/export list of comments for particular project/branch in Github?

Are there any ways to get/export list of comments for particular project/branch in Github?
Is there available any plugin/api?
Is Github giving any solvents for
this?
I found the below question which is related to this but seems the answer is only for getting the comments for a particular commit on Github.
Get list of comments from GitHub pull request
Thank you!
Relevant GitHub api documentation.
I think what you are looking for is something like this:
https://api.github.com/repos/{owner}/{repo}/comments
So if the repository you are interested in obtaining information for is angular, your request would be:
https://api.github.com/repos/angular/angular/comments
To obtain, all of the comments for that repository, you must know their Api limits to 100 results per request(and has some other limits, such as 60 unauthenticated requests per hour). So depending on how programmatically you are doing this, you would want to make your requests as follows:
https://api.github.com/repos/angular/angular/comments?page=1&per_page=100
https://api.github.com/repos/angular/angular/comments?page=2&per_page=100
etc...
UPDATE:
Following the additional information provided in the comments, for this to work with a private repository, you would need to do two things.
Update the url you are using to https://api.github.com/user/repos/{owner}/{repo}/comments
Documentation
Provide the appropriate authentication to the requests. One way to do this is through the headers. Add both of the following headers:
User-Agent: 'YOUR_USERNAME'
Authorization: 'token YOUR_TOKEN'

How to demo a REST API without a REST client

I need to build a way to demo a REST API that takes three or four inputs, makes a REST call to an external server, then displays the response. This demo needs to be performed by a rather limited technical audience to business so REST clients are out.
It seemed like a simple HTML page that would do an ajax call would be fine for this, except I ran into the No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access fun messages because my localhost domain does not match the target domain. I don't have access to the target REST web service, so I can't make the necessary changes for the CORS headers.
Any ideas?
Build a very small and simple web application that shows the same HTML but does the REST call with its own REST client and shows the results.
Then run that on a local server.
Can you use a product where you can host your REST API? (There are number of API hosting products available. )If so you can try wso2 APImanager.? It is free and opensource. You do not need to develop any HTML page. You can try available swagger client or REST tool to test your APIs. You can do CORS settings too..
You can also use ExploREST, a project created with this goal in mind (production demo here).
With this tool, you can make GET/POST/PUT/DEL requests, but you can also create special links in the text documenting your API so that each time someone click on it, it will make the request you defined.
Example:
## My API is very good, I am documenting it. Try
%{
"text": "to post",
"post": {
"address": "/character",
"data": {
"name":"Dark Vador",
"type": "sith"
}
}
}%
Will result in a link that make a post when the user clicks on it.
The project is open source so do not hesitate to contribute !

Is there a way to increase the API Rate limit or to bypass it altogether for GitHub?

I am developing a web application which needs to send a lot of HTTP requests to GitHub. After n number of successful requests, I get HTTP 403: Forbidden with the message API Rate Limit Exceeded.
Is there a way to increase the API Rate limit or to bypass it altogether for GitHub?
This is a relative solution, because the limit is still 5000 API calls per hour,
or ~80 calls per minute, which is really not that much.
I am writing a tool to compare over 350 repositories in an organization and
to find their correlations.
Ok, the tool uses python for git/github access, but I think
that is not the relevant point, here.
After some initial success, I found out that the capabilities of the GitHub API
are too limited in # of calls and also in bandwidth, if you really want to ask
the repos a lot of deep questions.
Therefore, I switched the concept, using a different approach:
Instead of doing everything with the GitHub API, I wrote a GitHub Mirror script
that is able to mirror all of those repos in less than 15 minutes using my
parallel python script via pygit2.
Then, I wrote everything possible using the local repositories and pygit2.
This solution became faster by a factor of 100 or more, because there was neither an API nor a bandwidth bottle neck.
Of course, this did cost extra effort, because the pygit2 API is quite a bit
different from github3.py that I preferred for the GitHub solution part.
And that is actually my conclusion/advice:
The most efficient way to work with lots of Git data is:
clone all repos you are interested in, locally
write everything possible using pygit2, locally
write other things, like public/private info, pull requests, access to
wiki pages, issues etc. using the github3.py API or what you prefer.
This way, you can maximize your throughput, while your limitation is now the
quality of your program. (also non-trivial)
In order to increase the API rate limit you might
authenticate yourself at Github via your OAuth2 token or
use a key/secret to increase the unauthenticated rate limit.
There are multiple ways of doing this:
Basic Auth + OAuth2Token
curl -u <token>:x-oauth-basic https://api.github.com/user
Set and Send OAuth2Token in Header
curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com
Set and Send OAuth2Token as URL Parameter
curl https://api.github.com/?access_token=OAUTH-TOKEN
Set Key & Secret for Server-2-Server communication
curl 'https://api.github.com/users/whatever?client_id=xxxx&client_secret=yyyy'
Just make new "Personal Access Token" here and use simple fetch method (if you are coding in JS of course :D) and replace YOUR_ACCESS_TOKEN with your token.
The best way to test it is to use Postman
async function fetchGH() {
const response = await fetch('https://api.github.com/repos/facebook/react/issues', {
headers: {
'Authorization': 'token YOUR_ACCESS_TOKEN',
}
})
return await response.json()
}
Solution: Add authentication details or the client ID and secret (generated when you register your application on GitHub).
Found details here and here
"If you need to make unauthenticated calls but need to use a higher rate limit associated with your OAuth application, you can send over your client ID and secret in the query string"
While seems like there's still no way to increase the rate limit, GitHub now has a GraphQL API that potentially allows you to lower your API call.
Keep in mind that GitHub calculates rate limit differently between GraphQL and REST API. GraphQL API rate limit is 5000 points / hour (not 5000 calls per hour! So 1 GraphQL call can cost you more than 1 point) You can read more here: https://docs.github.com/en/graphql/overview/resource-limitations (TL;DR is more resource to fetch in the query = more points)
For example, if you have similar use case with Christian's answer, instead of doing multiple call to multiple endpoint
GET /repos/{owner}/{repoA}
GET /repos/{owner}/{repoB}
You can just do one GraphQL call to https://api.github.com/graphql with this query:
query {
repoA: repository(owner:"owner", name:"repoA") {
...
}
repoB: repository(owner:"owner", name:"repoB") {
...
}
}
Depending on what's the repository queries, you can still add even more repositories on one call and still using 1 point on each call.
I have observed this error during multibrnach pipeline configuration in jenkins
I had selected the source as github. After changing it to git and passing guthub repo details it worked. (have git executable path configured in jenkins and have a credential set for authentication to github)
May I suggest "become an archiver" https://github.com/github/site-policy/issues/56
BTW even "non-archivers" have access to public data...
All the tools are on github.