Require deployments to succeed before merging API REST - github

I'm working on a GitHub Entreprise Project and in my approach of automating some branches policy configuration, I wanted to use GitHub REST API to automatically :
Require a pull request before merging
Allow specified actors to bypass required pull requests
Require status checks to pass before merging
Restrict who can push to matching branches
Require deployments to succeed before merging
All of these point succedded using the Update branch protection API REST but the last point.
It seems that the REST API doesn't make it possible to check this point.
Does anyone know if there is a hidden way to do that with API REST or GitHub CLI integrated to GitHub Action ?
Thanking you for any help :)

Related

How can I search only for issues in github repository through github rest api?

I want to get only issues and not pull requests from GitHub rest api in a specific repository, but https://api.github.com/repos/user/repo/issues endpoint returns both issues and pull requests. Github rest api docs don't say anything about searching in a specific repository. Adding q parameter to the above method does not do anything. I can't filter response to find only issues because my repository contains much more pull requests than issues.
What is the way to get only issues?
You can use the search issues/PR API and filter with your repo path and is:issue :
GET https://api.github.com/search/issues?q=is:issue%20repo:owner/repo
For example
Note that type:issue also works, checkout this
The more compact option would be (March 2022) to use gh 2.7.0, and it new command gh search issues
Adds the search issues and search prs command.
The search issues command includes a --include-prs flag that allows for including pull requests in the search results.

Automatically adding comments to all Pull Requests in Azure DevOps

Is there a way to automatically add comments to any pull requests created in Azure DevOps within a repository?
Is there a way to automatically add comments to any pull requests created in Azure DevOps within a repository?
I am afraid there is no such way to automatically add comments to any pull requests created in Azure DevOps within a repository.
That because we are currently unable to monitor the creation of pull requests in real time. And there is no similar extension to detect the creation of pull requests. In this case, we could set the action to add comment to the all pull requests.
To achieve this, we could try to add a Build Validation for each branch, and use the REST API Pull Request Thread Comments - Create to add comments to the pull requests.
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/threads/{threadId}/comments?api-version=5.1
You could check this thread for the details info about how to use this REST API.
In this case, if we create any pull request, it will invoke the Build Validation to use REST API to add comments to the pull request.
Our team had similar needs so I created an Azure DevOps task to do just that:
PR Auto-Comment (GitHub)
Just add the task to your PR build and you're good to go.
Depending on your exact need, you may be able to use the "Automatically included reviewers" functionality that you get with branch policy. It has a custom message that can be configured to be included in every PR.

Is there any way to trigger a Google Cloud build ONLY when a merge request is accepted on a specific branch?

Basically I just started using Google Cloud and I'm looking for a way to trigger a deployment ONLY when a pull request is accepted on a distant github repository.
I'm currently using the google "Cloud Build Trigger" to execute my 'cloudbuild.yaml' as soon as a push is detected on my master branch, but simply attempting a merge request seems to trigger my build process.
This is troublesome as a merge request will be reviewed by peers and I don't want my cloud application to rebuild if the merge request is to be denied after being reviewed.
As this feature is still in beta, I assume this is not supported yet and that there is a better way to handle such task, but when I heard of the trigger feature it seemed like the most straightforward way to connect my github repository to the build process on google cloud. Anyway, hope someone had to face this issue or can help me figure this one out.
Thanks !
Based on the documentation, Cloud Build triggers currently only support changes pushed to the build source (a remote Github repo in this case). There doesn't seem to be a way to distinguish between a merge resulting from a (remote) pull request or a local one from the Google Cloud Console GUI.
However, you are not without options. One alternative is to leverage Github's PullRequestEvent Webhook and deploy a GAS Web App or Cloud Function to serve as a web-hook endpoint. The GAS Web App or Cloud Function could then parse the event payload for GitHub's PullRequestEvent and if the pull request is closed and merged then you call the REST API for the Cloud Build service to start your build.

Overcoming GitHub API Rate-Limiting from a Public Project?

I have a public repository which is an Ansible role. This Ansible role uses the GitHub API in order to get the most recent release for a given repository. I use this metadata in order to then subsequently download the latest release binary for the given project.
Unfortunately, I'm hitting GitHub's API rate-limit when running my tests in Travis and occasionally on my local machine. Since this is a public-facing project, what are my options for overcoming this rate limit?
I could use some kind of secret management system in Ansible or expose the value via Travis environment variables, but is there a standard practice for dealing with these kinds of scenarios for public code?
Unauthenticated requests only get 60/hour. Authenticated requests get 5000/hour.
To authenticate, generate a personal API access token for use by the project. Put it either in an encrypted Travis environment variable or some other way to store encrypted secrets (for example, Rails has built in encrypted credentials. Use that token to access the API.
Make a separate Github account for the project and use an API token for that. This avoids sharing its rate limit with anyone else.
Use Git commands on a local clone where possible. For example, if you want to look up a commit instead of doing it via the API, clone the repository and use normal Git commands. Cache the clones and git fetch periodically to keep them up to date.
Finally, make use of conditional requests. These use HTTP headers so you can safely use cached queries. These do not count against your rate limit. A good Github authentication library should have an option for caching.

How to auto merge pull request on github?

Is it possible to merge pull request automaticaly to master branch on github after success of travis test webhook?
You can use Mergify to do this.
It allows to configure rules and define criteria for your pull request to be automatically merged. In your case, setting something like "Travis check is OK and one reviewer approved the PR" would allow the PR to be automatically merged.
(Disclosure: I'm part of the Mergify team.)
You can most probably add an after_success action to your .travis.yml that would merge the PR using GitHub API. I do not know of any ready to use script for this, but there is no reason for it to be hard. Special care needed for authentication ...
GitHub recently shipped this auto-merge feature in beta. To use this, you can enable it in the repo settings. Just keep in mind you will need to add branch protection rules as well.
See the documentation for more info.
https://docs.github.com/en/free-pro-team#latest/github/collaborating-with-issues-and-pull-requests/automatically-merging-a-pull-request
I work on a project that requires pull requests to be up to date with the target branch, and also to have passed all the checks before merging.
This means we can often be waiting for checks to finish, only to find a new commit has been made to the target branch, which requires the pull request to be synchronised and the checks to run all over again. I wanted a simple app to merge the PR automatically once the checks are successful, so I created one.
Mergery is:
Free, including for private repositories.
Fast. It's event-driven, it doesn't run on a schedule.
Simple. No configuration required. Just label your PRs with automerge.