Initiating Github webook based on new branch creation called "Release-XXXX" - github

Does anyone know if you can trigger a webhook based on the github action of creating a new branch called
Release-xxxx where XXXX can be anything? I only want to initiate this webhook on that new branch name.

In general, GitHub webhooks cover a single large category of activities that you are then responsible for filtering. In your case, you can install a webhook to be notified when a new branch or tag is created and then perform the filtering yourself.
GitHub doesn't perform the filtering for you because filtering is expensive and there are a lot of operations to notify about. This is no different than reading an events stream API and having to select only the events that you're interested in.

Related

Github Actions trigger when add user to repository

I am m new in GitHub actions, and unfortunately I did not find any info about trigger on adding user to repo.
Is there somethinglike this in GitHub Actions?
The "Events that trigger workflows" page does not list indeed anything regarding a new user/collaborator being added to a repository.
As such, this does not appear to be a supported event.
You might consider a scheduled event to monitor at regular interval a repository, querying the list of collaborators (GitHub API), and triggering another job if the number changes.

How do I get when a review was requested on a Github PR

I need a way to get when a reviewer for a GitHub PR was requested using their API, but looking through the documentation there seems to be no way to do it. Is there any way that I can get the information I need?
If you want to be notified when a pull request review was requested, you can set up a webhook for the pull_request event. Then, you can listen for the review_requested and review_request_removed actions and do whatever you'd like in response.
Note that with GitHub webhooks, you will get all of the messages for a particular event, and you're responsible for filtering out the ones you want. GitHub doesn't provide filtering capabilities.

Avoid to call Organization level webhook

Currently, we're using an organization-level generic-webhook for all our repo.
Recently we had added new repo repo. which needs to be use only repo level generic-webhook for some reason.
Is there any way, So that i can call only repo level generic-webhook and ignore organization level webhook ?
I don't believe there's any way to do this. GitHub delivers a lot of webhook events and users generally want them delivered right away. In order to make webhook delivery as speedy and efficient as possible, there aren't any filtering options on GitHub's side. You're expected to receive all the events you're subscribed to and filter them yourself.
If you want the organization-level webhook to not operate on this particular repository, you'll need to configure your service that receives the webhook itself not to act on those messages.

Merge PR by Github action if review was approved by a user

Is it possible to configure Github actions workflow to merge pull request if it was approved (submitted review with approve keyword) by one of the users (static fixed list, which can be written in workflow config file)? I tried to find it in documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions#on
- I suppose I can use on: [pull_request_review] trigger for action, but documentation didn't mention how to access event payload in action yaml file, where I need to extract reviewer login from this payload.
I found this in https://help.github.com/en/articles/virtual-environments-for-github-actions#filesystems-on-github-hosted-machines:
workflow/event.json: The POST payload of the webhook event that triggered the workflow. GitHub rewrites this each time an action executes to isolate file content between actions. Use the GITHUB_EVENT_PATH environment variable to access this file.
So the next step will be figuring out how to parse a JSON file and extract some data that a later step can use. For that, looking at GitHub's setup-dotnet action might prove useful. In line 62 of installer.ts, they call a function called core.exportVariable, which as you can see here, causes ##[set-env name=NAME;]value to be printed in the action's output. I've personally verified that this causes the environment variable called NAME to automatically be present in later steps of the same workflow job.
Now, I don't yet know if you can simply do echo "##[set-env name=NAME;]$VALUE" in a run step of a GitHub workflow and have that work; it's possible that you'll have to write a custom action in Typescript to get access to core.exportVariable. But once you have parsed the JSON, that would be one way of passing that information on to later steps in your job.
In addition of rmunn's answer, you might also want to protect your branch:
GitHub Actions: Prevent GitHub Actions from approving pull requests (2022, 14th Jan.)
We have introduced a new policy setting that controls whether GitHub Actions can approve pull requests.
This protects against a user using Actions to satisfy the "Required approvals" branch protection requirement and merging a change that was not reviewed by another user.
To prevent breaking existing workflows, Allow GitHub Actions reviews to count towards required approval is enabled by default.
However, an organization admin can disable it under the organization's Actions settings.
That way, you are sure approvals were made exclusively by users, not by other actions.

Github how to track commits only from certain users

I wish to trigger an action(maybe send a mail/alert) when the code is committed only for my team members which is a very small subset of large number of contributors. Is there a way to track commits only from certain specific users in Github/Gitlab.
Yes! You can even automate this process using a webhook. In case you aren't familiar - a webhook delivers a JSON payload when a certain event occurs.
By setting up a webhook on the GitHub push event you'll create alerts every time a push is made to your repository. You can create a small script that scans the author value. If the value matches one of your team members you can configure your alert/mailer, otherwise you can configure your script to ignore the webhook's payload.