Skip to content

Commit

Permalink
feat: merge-on-green bot (#287)
Browse files Browse the repository at this point in the history
338cce8
commit 338cce8
Author: sofisl <[email protected]>
Date:   Wed Feb 19 11:42:43 2020 -0800

    feat: merge-on-green bot (#287)
  • Loading branch information
yoshi-automation committed Apr 1, 2020
1 parent fd98c98 commit 379073c
Show file tree
Hide file tree
Showing 18 changed files with 1,559 additions and 412 deletions.
320 changes: 218 additions & 102 deletions package-lock.json

Large diffs are not rendered by default.

68 changes: 21 additions & 47 deletions packages/gcf-utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions packages/merge-on-green/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@

Instructions are provided in [googleapis/repo-automation-bots](https://github.com/googleapis/repo-automation-bots/blob/master/README.md) for deploying and testing your bots.

This bot uses nock for mocking requests to GitHub, and snap-shot-it for capturing responses; This allows updates to the API surface to be treated as a visual diff, rather than tediously asserting against each field.
This bot uses nock for mocking requests to GitHub.

## Running tests:

`npm run test`

## To update snapshots:
## Installing:

`npm run test:snap`
`npm i`

## How it works

Once installed, this bot merges PRs once reviews have been approved and tests have passed. Briefly speaking, the bot does the following:

- User kicks off a PR, adds an ‘automerge’ label
- Bot listens to PR and checks to see if appropriate label was added. If so, the PR info is added to Datastore as an entry
- *A cron job will run the logic below every four minutes, until it hits two hours. Once it hits two hours, the job will pass in a status called ‘stop’, which the logic will then use to determine an outcome*
- Merge-on-green begins by checking if there are any reviews on the bot. If there are any non-approved reviews, assigned reviews that have not been fulfilled, or if no one has reviewed the PR, the bot will fail its check
- Merge-on-green then checks to see if there is at least one commit in the PR, if the PR has an ‘automerge’ label (i.e., if theuser has removed it)
- Merge-on-green will then see what checks are required by individual languages according to the file googleapis/slothrequired-checks.json, and will map the repo to the language using the sloth.json file. If any repo has any special requirementsfor status checks, it should note them in the required-checks.json file
- Merge-on-green will look for the required checks in the statuses that have run. If it can’t find a given check in the statuses it will also check under ‘check runs’ as github has two concepts to describe status checks. If it cannot find them,or if anyhas failed, MOG will fail the Status Check
- Three statuses that can result:
- Success: Merge
- If all steps above come out as ‘true’, the bot will update the branch the PR was called from, merge the PR, and remove the Datastore entry so that the bot no longer tries to merge that PR
- Fail: Keep Checking
- If one of the steps fail, then the Datastore entry will remain, and the bot will keep checking the variables above until they become true or the cron job times out
- Fail: Delete
- Once the cron job times out, it will pass a ‘stop’ state to the logic above. If this flag is set to ‘stop’, the bot will post a failed check-run on the PR and ask the user to try again. The bot will also delete the entry from Datastore so it does not keep checking the logic

## Contributing
If you have suggestions for how merge-on-green could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
Expand Down
6 changes: 3 additions & 3 deletions packages/merge-on-green/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"lint": "gts check"
},
"dependencies": {
"gcf-utils": "1.6.1",
"probot": "9.9.4",
"@octokit/rest": "16.41.2"
"@google-cloud/datastore": "^5.0.4",
"@octokit/rest": "16.41.2",
"gcf-utils": "1.6.1"
},
"devDependencies": {
"@types/body-parser": "^1.17.0",
Expand Down
Loading

0 comments on commit 379073c

Please sign in to comment.