-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0bd7bc
commit f40dd05
Showing
17 changed files
with
5,918 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"trailingComma": "none", | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid", | ||
"parser": "typescript" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
}, | ||
"[javascriptreact]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DOCKER_TAG = pr-labeled:local | ||
|
||
build: | ||
docker build -t $(DOCKER_TAG) . | ||
|
||
run: build | ||
docker run -t $(DOCKER_TAG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,45 @@ | ||
# merge-pr-to-branch | ||
# About | ||
|
||
`merge-pr-to-branch` is a Github action that will reset the `target-branch` (defaults to `staging`) to the base branch (eg. `master`) and merge every pull request with the `deploy` label. This is triggered as defined in the Github workflow. | ||
|
||
# Getting started | ||
|
||
## Add Github Workflow | ||
To enable this github action, add the following workflow to your repo: | ||
|
||
`.github/workflows/merge-pr-to-branch.yml`: | ||
|
||
```yaml | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: [labeled, unlabeled, closed, reopened] | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: master | ||
- uses: deliveroo/merge-pr-to-branch@v1 | ||
``` | ||
## Use the action | ||
1. To merge a pull request to the `target-branch`, add the `deploy` label. | ||
2. `merge-pr-to-branch` will run and attempt to merge the pull request | ||
* If successful, the `deployed` label will be added along with a comment | ||
* If unsuccessful, a comment with the error will be added and the `deploy` label will be removed | ||
|
||
# Contributing | ||
|
||
Before commiting your change, ensure you build the distributed js file. Github Actions require bundled output in the repo. | ||
|
||
``` | ||
npm run build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createGithubClient, mergeDeployablePullRequests } from "../src/githubHelpers"; | ||
|
||
describe("main", () => { | ||
it("mergeDeployablePullRequests intergration test", async () => { | ||
const client = createGithubClient(); | ||
await mergeDeployablePullRequests(client, "deliveroo", "dev-glue", "sandbox", "master"); | ||
}, 100000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as githubHelpers from "../src/githubHelpers"; | ||
|
||
describe("githubHelpers", () => { | ||
it("getBranchFromRef returns last segment of ref", () => { | ||
expect(githubHelpers.getBranchFromRef("foo/bar")).toBe("bar"); | ||
}); | ||
it("getBranchFromRef returns ref when no separators", () => { | ||
expect(githubHelpers.getBranchFromRef("foo")).toBe("foo"); | ||
}); | ||
it("hasLabel returns true when exists in array of strings", () => { | ||
expect(githubHelpers.hasLabel(["bar"], "bar")).toBeTruthy(); | ||
}); | ||
it("hasLabel returns true when exists in array of objects", () => { | ||
expect(githubHelpers.hasLabel([{ name: "a" }], "a")).toBeTruthy(); | ||
}); | ||
it("hasLabel returns false when not exists in array of strings", () => { | ||
expect(githubHelpers.hasLabel(["bar"], "foo")).toBeFalsy(); | ||
}); | ||
it("hasLabel returns false when not exists in array of objects", () => { | ||
expect(githubHelpers.hasLabel([{ name: "foo" }], "a")).toBeFalsy(); | ||
}); | ||
it("getBranchRef calls getRef as expected", async () => { | ||
const expectedResult = {}; | ||
const githubClient = { | ||
git: { | ||
getRef: jest.fn().mockResolvedValue(expectedResult) | ||
} | ||
}; | ||
const owner = "owner"; | ||
const repo = "repo"; | ||
const branch = "branch"; | ||
const result = await githubHelpers.getBranchRef(githubClient as any, owner, repo, branch); | ||
expect(githubClient.git.getRef).toBeCalledTimes(1); | ||
expect(githubClient.git.getRef).lastCalledWith({ | ||
owner, | ||
repo, | ||
ref: `heads/${branch}` | ||
}); | ||
expect(result).toBe(expectedResult); | ||
}); | ||
it("getBranchRef does not throw 404s", async () => { | ||
const expectedResult = { status: 404 }; | ||
const githubClient = { | ||
git: { | ||
getRef: jest.fn().mockRejectedValue(expectedResult) | ||
} | ||
}; | ||
const owner = "owner"; | ||
const repo = "repo"; | ||
const branch = "branch"; | ||
const result = await githubHelpers.getBranchRef(githubClient as any, owner, repo, branch); | ||
expect(githubClient.git.getRef).toBeCalledTimes(1); | ||
expect(githubClient.git.getRef).lastCalledWith({ | ||
owner, | ||
repo, | ||
ref: `heads/${branch}` | ||
}); | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: 'Merge PR to Branch' | ||
description: "Handles merging PRs with 'deploy' label to a target branch." | ||
author: 'Deliveroo' | ||
inputs: | ||
target-branch: | ||
description: 'The target branch to merge PRs to' | ||
default: staging | ||
repo-token: | ||
description: 'The access token used to access github api' | ||
default: ${{ github.token }} | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
moduleFileExtensions: ['js', 'ts'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
testRunner: 'jest-circus/runner', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
verbose: true | ||
} |
Oops, something went wrong.