github new local branch event for Jira webhook - github

I am noticing that when i create a new local branch, it doesn't get picked up in Github, and therefore the Jira webhook also doesn't create a transition trigger:
git branch -b new-local-branch
The Jira trigger is supposed to recognize "Branch created" event from Github webhook, but that doesn't exist until I push, which also then shows the new branch for the first time in the <>Code tab.
So, is this performing as expected, or is there another way to create a branch which gets pickedup without a push?

So, is this performing as expected
Yes: a webhook reacts to an event (here a push event).
As long as your branch remains local, said webhook has no reason to be activated.
But once created, you could push your branch immediately (before making any new commit in it): that would allow the webhook and Jira to pick up on it.
Is there another way to create a branch which gets picked-up without a push?
If you are creating your local branch from a commit which is already pushed, you could consider the reverse approach: creating your branch directly from GitHub web GUI. But that might not trigger the webhook though.

Related

Trigger github action on push to multiple branches [duplicate]

I have created on my main branch with
on:
push:
branches: [ test ]
I have noticed, that while I can trigger it manually, and it will work, it will not actually trigger if I push to test. For that, I needed to create that same action file on test. Now, it seems like I don't even need to have the action on the main branch, is that correct?
So why does even the option so specify the branch that it should trigger on exist? It only triggers on the branches the file exists anyway. That said, I found it frustrating that I have to merge my one file from main to my test branch, is there a way to trigger the action automatically on push even if I do not have it on my test branch, only on main?
No, it's not possible. The order of operations in a workflow run triggered by push or pull request is described in the reference documentation:
An event occurs on your repository. The event has an associated commit SHA and Git ref.
GitHub searches the .github/workflows directory in your repository for workflow files that are present in the associated commit SHA or Git ref of the event.
A workflow run is triggered for any workflows that have on: values that match the triggering event. Some events also require the workflow file to be present on the default branch of the repository in order to run.

To enable commit button in github

My commit button is not getting enabled after editing Readme file in github.
The reason why the commit button is not enabled is because you are trying to commit to the master branch of the repo, which is protected from making direct commits/push. Only those who have access to make direct commits to master can do that, and you might not have that access. Hence you need to select the second option there to create a new branch to make the commit and create a pull request to the master branch, or get access to directly contribute to that branch.
The branch protection is to ensure that collaborators don't directly push or make commits to the particular branch or delete it, and also allows enabling status checks or required reviews. You can read more about GitHub's branch protection here.

github API code repository state after each commit

Is there any way to have the full source code repo after each commit?
I mean for example using
https://api.github.com/repos/highcharts/highcharts/commits
would give me a list of commits, but I want to realize what was the effect of that commit to whole repo (I want to check whether any code duplication is added to whole project or not using some automatic tools). Is that possible?
I want to see the code effect, so having repo even after merging each commit would be fine.
Simply implement a listener to a webhook (see "Creating a Webhook"). Set it up to ball your listener at each push event.
You can then do a pull when called by the webhook, and get a fresh updated copy of the repo locally.
For other repos you don't have any control or whose owner is in your team, that webhook approach is not possible.
You would need to implement a scheduled polling approach, through a regular cron job for instance.
That would possible multiple commits, so you need to wrap that pull with a git log as in here.
git checkout master
git fetch
refs=$(git log --format='%H' ..origin/master)
for ref in ${refs}; do
# do your analysis commit by commit
done
git merge origin/master

VSTS GitHub Pull Request Trigger Not Firing

I can't seem to get my VSTS build to trigger for GitHub pull requests. It works fine when i commit to the master branch, but not when i open the pull requests to the master branch.
Here's the screenshot from VSTS:
I can also see the 2x Webhooks in GitHub:
I can see the pull_request webhook fires successfully when i open a PR too (returns 200 ok), but VSTS doesn't seem to be triggering the build.
I'm guessing there's something obvious i've missed. Can someone help please?
As auto trigger is enabled only for master branch, I would suggest you add one more branch filter. Click on the add button and include other branches also.

Commit message hook on github

I am trying to setup a pre-receive hook in github that I used to use on STASH. In STASH, I had a pre-receive hook that used to enforce "A custom commit message that should have a JIRA number included in it".
Now, I am trying to understand what would be the best way to do something similar on github. If I split it up, it would be:
Requiring a custom commit message.
Every commit should include an existing JIRA.
Enforce this on any pull request as well.
Eg: TEST-1 Adding the first commit message.
Can anybody here help me, how can this be done ?
GitHub only offers webhooks, which allows you to listen to and react to certain events, including the push.
But that only allows you to react to a push (like a post-receive hook would), not to prevent it.
You could build a listener to that push event which would:
examine the latest commit just pushed
reset to HEAD~1 if the commit doesn't follow the expected policy (push --force)
But that would be tricky for the user who initially pushed that commit to realize that said commit just disappeared from the GitHub repo.
A better solution would be to setup a bare repo in a server where you could setup that pre-receive hook: if that commit passes, then a post-receive hook would push it to the intended GitHub repo.
But depending on your team, it might be difficult to setup a repo which is accessible by everyone.