How do I query the Github API using gh CLI for a PRs with specific keyword in title? - github

I am trying to query the Github API using gh CLI for all PRs with the word Bump in the title however I fail to figure how...
I have tried:
api --method GET /repos/my_name/my_project/pulls -H "Accept: application/vnd.github+json" -f q="Bump in:title"
and
api --method GET '/repos/my_name/my_project/pulls?q=Bump in:title' -H "Accept: application/vnd.github+json"
however the filtering does not apply

I needed to use the search api instead:
gh api '/search/issues?q=is:pr+repo:my_name/my_project+Bump+in:title

Related

How to get stats for Github PRs code reviews

I want to get a list of people who did some PR code reviews in my organization in the past month. Also how many code reviews were done by each one of them. It would also be helpful if I can know how many comments each person made. Is there a way to get these stats in UI without doing any code changes?
You have a few options including: the Github API or a proprietary service like PR Stats.
With the Github API you can use the following:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/reviews
With PR Stats you'll need to create a Github Action to include a table of PR stats in each PR you create within Github.

Do GitHub CLI commnds use REST APIs of GitHub? Is there any rate limit for using the commands?

I am using the GitHub CLI tool to get some pull-request information from my local repository. Mainly using the following commands from - https://cli.github.com/
gh pr list
gh pr view
But sometimes I get - graphql error: 'API rate limit exceeded'. Is there anyone who knows about the CLI rate limit? I could not find anything from their CLI documentation.
The CLI uses the REST as well as the GraphQL API. The rate limit depends on the kind of account you're using and whether you're signed in.
The graphql rate limit is 5000 when authenticated.
You can check all the rate limits for your account/current gh login, by querying https://api.github.com/rate_limit
First check your gh token in ~/.config/gh/hosts.yml
Query the api by e.g. curl -H "Authorization: Bearer <your token>" -H "Accept: application/vnd.github.v3+json" \ https://api.github.com/rate_limit
And you will see all the limits and current usage.

How to use ghs_* token in github API?

I'm trying to build an integration between two repositories. For that I've decided to use Github Apps.
I was able to sign working JWT and use it to get an access token (from https://api.github.com/app/installations/{{INST_ID}}/access_tokens). It looks like this: ghs_tVGHE4l5i4kjhasslirerno666222.
Now I'm trying to use it to trigger an dispatches event for a project workflow with on: workflow_dispatch: trigger.
But I just can't find a way to put ghs* token to use.
Examples I saw say:
curl -X POST https://api.github.com/repos/{{user}}/{{repo}}/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-u ${{ ACCESS_TOKEN }} \
--data '{...}'
But it does not work, -u option is for 'user', not for token.
How to use ghs* token with github api?
The easiest way to do this is to just use the Token TOKEN Authorization header:
-H 'Authorization: Token ghs_tVGHE4l5i4kjhasslirerno666222
You may also try using Basic authentication with the x-token username. While that worked in the past, GitHub has disabled Basic authentication for the API, so that syntax may or may not function anymore.

How to check if we are the owners of the repository?

I'm using Github API to fetch data from my repository like below:
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world
documentation: https://docs.github.com/en/rest/reference/repos#get-a-repository
to run this query, in header, I'm also using my access token,
and I have one question, is there any way to check from github api response, that I'm the owner of the repository? I want to create a simple statement that check if responsed repository from github api is my or not(different public repo),
thanks for any help!

How do I POST to a Google Cloud Storage bucket via API

I'm attempting to do a POST to a bucket via API. I have an API key, and I have a client-id and secret. What should be included in the header for authentication to my bucket for a simple post?
If you are trying to do a POST with the RESTful API you should add an "Authorization: Bearer [OAUTH2_TOKEN]". I recommend on following the Quickstart on Uploading Objects with Rest API which guides you on how to achieve this and searching the OAuth 2.0 playground to get the Token
Taken from the guide:
curl -X POST --data-binary #[OBJECT] \
-H "Authorization: Bearer [OAUTH2_TOKEN]" \
-H "Content-Type: [OBJECT_CONTENT_TYPE]" \
"https://www.googleapis.com/upload/storage/v1/b/[BUCKET_NAME]/o?uploadType=media&name=[OBJECT_NAME]"