Skip to content

Commit

Permalink
feat: add option autoMerge
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed May 25, 2019
1 parent f9dc926 commit 534436a
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 68 deletions.
56 changes: 40 additions & 16 deletions dist/index-node10-dev.cjs.js

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

2 changes: 1 addition & 1 deletion dist/index-node10-dev.cjs.js.map

Large diffs are not rendered by default.

56 changes: 40 additions & 16 deletions dist/index-node10.cjs.js

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

2 changes: 1 addition & 1 deletion dist/index-node10.cjs.js.map

Large diffs are not rendered by default.

41 changes: 32 additions & 9 deletions src/pr-handlers/actions/editOpenedPR.ts
Expand Up @@ -119,12 +119,21 @@ export const editOpenedPR = async (
);

const featureBranchLabel = repoContext.labels['feature-branch'];
const automergeLabel = repoContext.labels['merge/automerge'];

const prHasFeatureBranchLabel = Boolean(
featureBranchLabel &&
pr.labels.find((label): boolean => label.id === featureBranchLabel.id),
);

const prHasAutoMergeLabel = Boolean(
automergeLabel &&
pr.labels.find((label): boolean => label.id === automergeLabel.id),
);

const defaultOptions = {
...repoContext.config.prDefaultOptions,
autoMerge: prHasAutoMergeLabel,
featureBranch: prHasFeatureBranchLabel,
};

Expand All @@ -148,17 +157,31 @@ export const editOpenedPR = async (
await context.github.issues.update(context.issue(update));
}

if (options && featureBranchLabel) {
if (prHasFeatureBranchLabel && !options.featureBranch) {
await context.github.issues.removeLabel(
context.issue({ name: featureBranchLabel.name }),
);
if (options && (featureBranchLabel || automergeLabel)) {
if (featureBranchLabel) {
if (prHasFeatureBranchLabel && !options.featureBranch) {
await context.github.issues.removeLabel(
context.issue({ name: featureBranchLabel.name }),
);
}
if (options.featureBranch && !prHasFeatureBranchLabel) {
await context.github.issues.addLabels(
context.issue({ labels: [featureBranchLabel.name] }),
);
}
}

if (options.featureBranch && !prHasFeatureBranchLabel) {
await context.github.issues.addLabels(
context.issue({ labels: [featureBranchLabel.name] }),
);
if (automergeLabel) {
if (prHasAutoMergeLabel && !options.autoMerge) {
await context.github.issues.removeLabel(
context.issue({ name: automergeLabel.name }),
);
}
if (options.autoMerge && !prHasAutoMergeLabel) {
await context.github.issues.addLabels(
context.issue({ labels: [automergeLabel.name] }),
);
}
}
}
};
Expand Up @@ -14,6 +14,7 @@ If needed, explain here the solution you chose for this
<!-- do not edit after this -->
#### Options:
- [ ] <!-- reviewflow-featureBranch -->This PR is a feature branch
- [ ] <!-- reviewflow-autoMerge -->Auto merge when this PR is ready and has no failed statuses. (Also has a queue per repo to prevent multiple useless "Update branch" triggers)
- [x] <!-- reviewflow-deleteAfterMerge -->Automatic branch delete after this PR is merged
<!-- end - don't add anything after this -->
`;
Expand Down
Expand Up @@ -17,6 +17,7 @@ Some informations here, like links.
#### Options:
- [ ] <!-- reviewflow-featureBranch -->This PR is a feature branch
- [ ] <!-- reviewflow-autoMerge -->Auto merge when this PR is ready and has no failed statuses. (Also has a queue per repo to prevent multiple useless "Update branch" triggers)
- [x] <!-- reviewflow-deleteAfterMerge -->Automatic branch delete after this PR is merged
<!-- end - don't add anything after this -->
`;
Expand Down
Expand Up @@ -16,6 +16,7 @@ If needed, explain here the solution you chose for this
<!-- do not edit after this --></td><td width="200" valign="top">
#### Options:
- [ ] <!-- reviewflow-featureBranch -->This PR is a feature branch
- [ ] <!-- reviewflow-autoMerge -->Auto merge when this PR is ready and has no failed statuses. (Also has a queue per repo to prevent multiple useless "Update branch" triggers)
- [x] <!-- reviewflow-deleteAfterMerge -->Automatic branch delete after this PR is merged
</td></tr></table>
<!-- end - don't add anything after this -->
Expand Down
6 changes: 6 additions & 0 deletions src/pr-handlers/actions/utils/parseBody.test.ts
Expand Up @@ -7,6 +7,7 @@ describe('simple', () => {
it('should parse default description', () => {
const defaultConfig = {
featureBranch: false,
autoMerge: false,
deleteAfterMerge: true,
};

Expand All @@ -15,6 +16,7 @@ describe('simple', () => {
expect(parsed).not.toBeFalsy();
expect(parsed && parsed.options).toEqual({
featureBranch: false,
autoMerge: false,
deleteAfterMerge: true,
});
});
Expand All @@ -24,6 +26,7 @@ describe('table', () => {
it('should parse default description', () => {
const defaultConfig = {
featureBranch: false,
autoMerge: false,
deleteAfterMerge: true,
};

Expand All @@ -32,6 +35,7 @@ describe('table', () => {
expect(parsed).not.toBeFalsy();
expect(parsed && parsed.options).toEqual({
featureBranch: false,
autoMerge: false,
deleteAfterMerge: true,
});
});
Expand All @@ -41,6 +45,7 @@ describe('table', () => {
it('should parse edited description', () => {
const defaultConfig = {
featureBranch: true,
autoMerge: false,
deleteAfterMerge: true,
};

Expand All @@ -49,6 +54,7 @@ describe('table', () => {
expect(parsed).not.toBeFalsy();
expect(parsed && parsed.options).toEqual({
featureBranch: false,
autoMerge: false,
deleteAfterMerge: true,
});
});
Expand Down
13 changes: 11 additions & 2 deletions src/pr-handlers/actions/utils/prOptions.ts
@@ -1,6 +1,10 @@
export type Options = 'featureBranch' | 'deleteAfterMerge';
export type Options = 'featureBranch' | 'autoMerge' | 'deleteAfterMerge';

export const options: Options[] = ['featureBranch', 'deleteAfterMerge'];
export const options: Options[] = [
'featureBranch',
'autoMerge',
'deleteAfterMerge',
];
export const optionsRegexps: { name: Options; regexp: RegExp }[] = options.map(
(option) => ({
name: option,
Expand All @@ -10,6 +14,11 @@ export const optionsRegexps: { name: Options; regexp: RegExp }[] = options.map(

export const optionsLabels: { name: Options; label: string }[] = [
{ name: 'featureBranch', label: 'This PR is a feature branch' },
{
name: 'autoMerge',
label:
'Auto merge when this PR is ready and has no failed statuses. (Also has a queue per repo to prevent multiple useless "Update branch" triggers)',
},
{
name: 'deleteAfterMerge',
label: 'Automatic branch delete after this PR is merged',
Expand Down

0 comments on commit 534436a

Please sign in to comment.