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

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?

Related

Add, Commit & Push to git repository on save

In one git repository (workspace), I want every save committed ASAP. What is the easiest way to achieve that with VSCode?
So, when I press CTRL + S, it gets pushed upstream.
This can be done with plugin Run on Save
Here is the example that auto commits and pushes upstream any changes in the directory mydir:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "cd ${fileDirname}",
},
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "git add -A",
},
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "git commit -a -m \"vscode autosave\"",
},
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "git push",
}
]
}
One way to achieve that is via terminal on VSCode. Change to the topmost directory containing the .git file and run the following commands:
git status
This shall show you the uncommitted changes. Then run the following for the new added changes (except for the remove changes)
git add <fileName>
This shall add all the added contents to index.
Run below for the remove changes.
git rm <filename>
Then, git commit -m <commit msg> to commit the changes.

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.

Composer requiring github repository fork branch still checks all tags

Short question: How can I make composer require my branch from my fork without checking all tags?
Long question:
I want composer to require a specific branch that I created of a fork I created from twig.
My assumption was, that, when defined correctly, composer directly requires the branch.
Instead first it checks all the tags and after that it loads the branch.
I don't want composer to check the tags, I just want to use the branch.
Is this the correct behaviour or am I requiring the branch incorreclty?
My fork would be github.com/myfork/Twig
My branch would be mybranchname
This is my composer.json
{
"require": {
"twig/twig": "dev-mybranchname"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/myfork/Twig"
}
]
...
...
This is the correct behavior. Composer checks for all tags first before it could get to your branch name.
You can check if your code is fetched from the right repository by checking your composer.lock
Your composer.lock should be like this.
{
"name": "twig/twig",
"version": "dev-mybranchname",
"source": {
"type": "git",
"url": "https://github.com/myfork/Twig",
"reference": <your_revision_number>
},
...
}

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="
}

Read PR Title of a project on 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"
}
]