How to determine the source branch name in Github webhook push event? - github

The push webhook only contains the target branch name (ref parameter). But I want to extract the source branch name, meaning the branch which was merged in the target one. I haven't found anything like that among the Github push event parameters (https://developer.github.com/v3/activity/events/types/#pushevent).
But maybe I just missed it or there is another method to do so?

Related

How to display GitHub action badge for current running branch?

I need to show the GitHub action badge for the current running branch, instead, it is limited to one branch(default or specified).
As the "Adding a workflow status badge" mentions, displaying the status of a workflow run for a specific branch or event is only done using the branch and event query parameters in the URL.
But those parameters are fixed. Modifying them would mean updating the README every time a new action is running.
Said action can get the name of the branch it operates on (see "How to get the current branch within GitHub Actions?")
But you would then need to combine that action with, for instance, github-update-readme in order to include the right URL for the badge:
![example](https://github.com/github/docs/actions/workflows/main.yml/badge.svg?branch=${GH_BRANCH})
^^^^^^^^^^
(value computed from the previous step by your main action)

Are we able to use GitHub API to create a commit? especially v4?

Are we able to use GitHub API to create a commit?
Can we use API to upload a file/blob, like what we can do using Git command,
especially in API v4?
Presumably yes, using the GitHub Commits API (in the context of a GitHub application)
You can see the all sequence in "GitHub API Git Data":
Get the current commit object
Retrieve the tree it points to
Retrieve the content of the blob object that tree has for that particular file path
Change the content somehow and post a new blob object with that new content, getting a blob SHA back
Post a new tree object with that file path pointer replaced with your new blob SHA getting a tree SHA back
Create a new commit object with the current commit SHA as the parent and the new tree SHA, getting a commit SHA back
Update the reference of your branch to point to the new commit SHA
Each of those steps has its own GitHub API query.

Get the pull request that introduced a commit

In github, when I click on a commit, I can see the pull request that introduced it.
You can see this commit was introduced by PR 15.
How can I get the associated pull request for a particular commit from the Github API?
the #15 indicates the issue/PR number. If you have a commit sha it is possible to find the associated PR# using the GitHub search API (v3).
For example, suppose you have a commit sha - 7dd1bcf5f2f5eeed34cc2ec63053098fba302b6c. To find the PR# from this sha, your query using the GitHub APi can look something like this- https://api.github.com/search/issues?q=sha:7dd1bcf5f2f5eeed34cc2ec63053098fba302b6c. From JSON response, the field 'number' represents the PR# (in this case 16).
Ref. Search Issues

How to change the user name who push with deploy key to github

In my organization of GitHub, my team member (suppose that his name is John) added a deploy key to repository.
We have a bot user account. Suppose this account name is BotUser and email is bot#example.com. I put private key (which is pair of deploy key John added) to /home/botuser/.ssh/ and configure /home/botuser/.gitconfig like this:
[user]
name = BotUser
email = bot#exampe.com
And pushed tags (command is git tag -a tag_name -m 'message' && git push --tags) automatically by this BotUser setting. But GitHub displays that the user who created the tag is John. The message of news feed page (url is https://github.com/) is like John created tag tag_name at org_name/repo_name.
But int tag page (url is https://github.com/org_name/repo_name/releases/tag/tag_name), the tag is supposed to be created by BotUser. The page shows like BotUser tagged this an hour ago.
We want to show as BotUser also in news feed page. How can I do this?
[UPDATED]
In this case, we use deploy key to push tags. So I cannot set GitHub account name of it.
My question is "how can I set (change) the pusher name which pushed with deploy key".
You could set the environment variables (just for the git tag command):
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
That way, the author associated to the pushed tag would be the right one.

Github : Automated tagging on Merging of Pull Requests

Is there a way to trigger an automatic, custom tagging of a repository every time a pull request is merged in github ? for example...
After merging "pull request 8", id like to automatically tag the repository at that state as "$Major_Version.$pr_id".
The result might be "0.1.8".
Is this possible?
Worst case, if someone hasn't written a thing to do that yet, is to use the post-receive webhooks https://help.github.com/articles/post-receive-hooks
You'd need an internet-visible web server to do this, and some code to recognize the merge (it will have two parents) and see if it mentions a pull-request.