Read PR Title of a project on github - github

Is it possible to read the PR Title of a github repo?
I want to do some analysis over the data, currently I go and manually check the title and sometimes PR are very large in number
Any guidance will be helpful.

One way to do that is using the GitHub API. For example,
to get the pull request URLs and their titles in JSON format of someuser in somerepo, using curl and jq you could do:
curl -s https://api.github.com/repos/someuser/somerepo/pulls | jq '[.[] | { url: .url, title: .title }]'
The output will look something like:
[
{
"url": "https://api.github.com/repos/SonarSource/sonarlint-visualstudio/pulls/159",
"title": "Remove the locally copied Alm.Authentication classes and use the NuGe…"
},
{
"url": "https://api.github.com/repos/SonarSource/sonarlint-visualstudio/pulls/108",
"title": "New settings for Nuget package installation"
}
]

Related

How can I get the user name of committer in each commit in a project in Git?

I am trying to make analysis between issues and commits of a project in git.
I am getting the name and email of the committer and author from git using the command below:
git log --pretty="%an %ae %cn %ce"
I am using 'curl -i "https://api.github.com/repos/<repo-owner>/<repo-name>/issues"' to download the issues. This returns the username[login name] for each issue not the name of the user as it is in the git log report:
{ "url": "https://api.github.com/repos/<repo-owner>/<repo-name>/issues/17625",
"node_id": "MDExOlB1bGxSZXF1ZXN0NTA5NDYyMjgz",
"number": 17625,
"title": "......",
"user": {
**"login": "xxxxxx",**
"id": 43045863,
....
"type": "User",
},
I check if the issue and commit has been made by the same user. Since I cannot get the username of committer, I cannot relate them. Is there a way to get the username of each commit on a project in git?

GitHub Actions: How to access to the log of current build via Terminal

I'm trying to get familiar with Github Actions. I have configured my workflow in a way, that every time I push my code to GitHub, the code will automatically be built and pushed to heroku.
How can I access the build log information in terminal without going to github.com?
With the latest cli/cli tool named gh (1.9.0+), you can simply do
(from your terminal, without going to github.com):
gh run view <jobId> --log
# or
gh run view <jobId> --log-failed
See "Work with GitHub Actions in your terminal with GitHub CLI"
With the new gh run list, you receive an overview of all types of workflow runs whether they were triggered via a push, pull request, webhook, or manual event.
To drill down into the details of a single run, you can use gh run view, optionally going into as much detail as the individual steps of a job.
For more mysterious failures, you can combine a tool like grep with gh run view --log to search across a run’s entire log output.
If --log is too much information, gh run --log-failed will output only the log lines for individual steps that failed.
This is great for getting right to the logs for a failed step instead of having to run grep yourself.
And with GitHub CLI 2.4.0 (Dec. 2021), gh run list comes with a --json flag for JSON export.
Use
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/<github-user>/<repository>/actions/workflows/<workflow.yaml>/runs
https://docs.github.com/en/free-pro-team#latest/rest/reference/actions#list-workflow-runs
This will return a JSON with the following structure:
{
"total_count": 1,
"workflow_runs": [
{
"id": 30433642,
"node_id": "MDEyOldvcmtmbG93IFJ1bjI2OTI4OQ==",
"head_branch": "master",
"head_sha": "acb5820ced9479c074f688cc328bf03f341a511d",
"run_number": 562,
"event": "push",
"status": "queued",
"conclusion": null,
"workflow_id": 159038,
"url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642",
"html_url": "https://github.com/octo-org/octo-repo/actions/runs/30433642",
"pull_requests": [],
"created_at": "2020-01-22T19:33:08Z",
"updated_at": "2020-01-22T19:33:08Z",
"jobs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs",
"logs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs",
"check_suite_url": "https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374",
"artifacts_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts",
"cancel_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel",
"rerun_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun",
"workflow_url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038",
"head_commit": {...},
"repository": {...},
"head_repository": {...}
]
}
Access the jobs_url with a PAT that has repository admin rights.

Github REST API full example

I would like to create a new file in the my github repository by using github REST API. I've found following link, but honestly I don't understand it((
As I understand, I could do POST
url: https://api.github.com/repos/MyUserName/MyRepositoryName
headers:
Accept: application/vnd.github.v3+json
body:
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}
But it doesn't work. Could you please, write
1) which url should I call
2) which headers this request should contains
3) what body should be
You were close:) Lets assume, that
1) your login: YourUsername
2) your access token: 123a321
3) repository to be updated: YourRepo
4) file to be created: file.txt
5) folder that will contains new file: f1/f2
According to those assumptions your request should be following:
type : PUT
url : https://api.github.com/repos/YourUsername/YourRepo/contents/f1/f2/file.txt
headers :
{
"Content-Type" : "application/vnd.github.v3+json",
"Authorization" : "token 123a321"
}
body :
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}
UPD
If you write in java, you can use GitHubFileAPI library, that I recently pushed to the maven central repository.
Solution: In order to perform action on github api you can use curl
according to Github doc:
first make sure you have specific privileges and authentication token generated to your account in order to interact with Github api:
profile Settings -> Developer Settings -> Personal access tokens -> Generate new token
the command should be in http PUT method on path /repos/:owner/:repo/contents/:path
The required params for editing or adding new files (according to api)
message (String), Content (String) and sha(String), additional params are branch(String) commiter(String) and author(String)
Lets perform some curl message in order to perform your action, the simple formula for this case would be:
curl --user <userName>:<token>
--data '{"key":"value"}'
--header <HeaderType>
--request <HTTPMethod>
<fullURL>
for demonstration lets fill some details:
curl --user johnDoe:abc123!##
--data '{"message":"my message","content":"my content","sha":"abcjfhtenf736gd843ji43903"}'
--header Content-Type:application/json
--request PUT
https://api.github.com/repos/MyOrganization/MyCoolApp/contents/app/models
Verify on Github the content has been inserted correctly to your branch

Upload a file to my github repo from postman

I would like to upload a file to my Github repo from Postman. What I have tried is:
Generate token from PAT: https://github.com/settings/tokens.
Method PUT URL: https://github.com/username/test2/info/lfs/objects/cd00e292c5970d3c5e2f0ffa5171e555bc46bfc4faddfb4a418b6840b86e79a2
Body is a 1 MB file.
I am receiving the following error: Your browser did something unexpected. Please contact us if the problem persists.
According to the API Reference you can't simply PUT a file to that URL. Rather, you need to encode the file as Base64, and put it within a JSON object with the following inputs:
{
"message": "my commit message",
"committer": {
"name": "Scott Chacon",
"email": "schacon#gmail.com"
},
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}

Track number of download of a release (binaries) on Github

So now you can manage and publish your binaries directly on Github, the feature is back from early this month (source).
I've been looking around Github interface and I haven't seen a download tracker. This is a feature Google Code offer and I was wondering if Github has the same.
Please note, I am not interested to know the number of download of a repo, this is a different topic.
Based on Petros answer, I used the two following curl command:
To get the list of all releases including their id and number of
download:
curl -i https://api.github.com/repos/:owner/:repo/releases -H "Accept: application/vnd.github.manifold-preview+json"
For example to list all the release for the OpenRefine project:
curl -i https://api.github.com/repos/openrefine/openrefine/releases -H "Accept: application/vnd.github.manifold-preview+json"
Then to get details on each release (you will need to run the first query to get the release id)
curl -i https://api.github.com/repos/:owner/:repo/releases/assets/:release_id -H "Accept: application/vnd.github.manifold-preview+json"
With the same example to list the details including download number for google-refine-2.5-r2407.zip
curl -i https://api.github.com/repos/openrefine/openrefine/releases/assets/6513 -H "Accept: application/vnd.github.manifold-preview+json"
You can use the GitHub API to get the download_count among other things for a single release asset:
http://developer.github.com/v3/repos/releases/#get-a-single-release-asset
This is how it looks currently, but please check the link above just in case anything changed since this answer was written.
GET /repos/:owner/:repo/releases/assets/:id
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1",
"id": 1,
"name": "example.zip",
"label": "short description",
"state": "uploaded",
"content_type": "application/zip",
"size": 1024,
"download_count": 42,
"created_at": "2013-02-27T19:35:32Z",
"updated_at": "2013-02-27T19:35:32Z"
}
You can add a badge to your github repo. See this answer for more details.
Also, there is a nifty project that shows all of this data in a nice website which is over here: https://www.somsubhra.com/github-release-stats/