Skip to content

Commit

Permalink
fix: skip ci label to ensure it stays after renovate rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Aug 24, 2019
1 parent 3345e2b commit 90f1375
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 35 deletions.
53 changes: 44 additions & 9 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.

53 changes: 44 additions & 9 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.

4 changes: 4 additions & 0 deletions src/orgsConfigs/christophehurpeau.ts
Expand Up @@ -65,6 +65,10 @@ const config: Config<'dev', never> = {
name: ':soon: automerge',
color: '#64DD17',
},
'merge/skip-ci': {
name: 'automerge/skip-ci',
color: '#e1e8ed',
},

/* feature-branch */
'feature-branch': {
Expand Down
4 changes: 4 additions & 0 deletions src/orgsConfigs/ornikar.ts
Expand Up @@ -180,6 +180,10 @@ const config: Config<'dev' | 'design', 'archis' | 'frontends' | 'backends'> = {
name: ':soon: automerge',
color: '#64DD17',
},
'merge/skip-ci': {
name: 'automerge/skip-ci',
color: '#e1e8ed',
},

/* feature-branch */
'feature-branch': {
Expand Down
38 changes: 31 additions & 7 deletions src/pr-handlers/actions/editOpenedPR.ts
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import { PullsGetResponse } from '@octokit/rest';
import Webhooks from '@octokit/webhooks';
import { Context } from 'probot';
Expand Down Expand Up @@ -70,7 +71,7 @@ export const editOpenedPR = async (
ref: pr.head.sha,
}),
)).data.check_runs.find(
(check) => check.name === `${process.env.REVIEWFLOW_NAME}/lint-pr`,
(check): boolean => check.name === `${process.env.REVIEWFLOW_NAME}/lint-pr`,
);

await Promise.all<any>(
Expand Down Expand Up @@ -122,21 +123,28 @@ export const editOpenedPR = async (

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

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

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

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

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

const { body, options } = updateBody(pr.body, defaultOptions, statuses
Expand All @@ -160,17 +168,33 @@ export const editOpenedPR = async (
}

if (options && (featureBranchLabel || automergeLabel)) {
if (featureBranchLabel) {
if (prHasFeatureBranchLabel && !options.featureBranch) {
const syncLabel = async (
label: any,
prHasLabel: boolean,
optionKey: keyof typeof options,
) => {
if (prHasLabel && !options[optionKey]) {
await context.github.issues.removeLabel(
context.issue({ name: featureBranchLabel.name }),
context.issue({ name: label.name }),
);
}
if (options.featureBranch && !prHasFeatureBranchLabel) {
if (options[optionKey] && !prHasLabel) {
await context.github.issues.addLabels(
context.issue({ labels: [featureBranchLabel.name] }),
context.issue({ labels: [label.name] }),
);
}
};

if (featureBranchLabel) {
await syncLabel(
featureBranchLabel,
prHasFeatureBranchLabel,
'featureBranch',
);
}

if (skipCiLabel) {
await syncLabel(skipCiLabel, prHasSkipCiLabel, 'autoMergeWithSkipCi');
}

if (automergeLabel) {
Expand Down
26 changes: 18 additions & 8 deletions src/pr-handlers/labelsChanged.ts
Expand Up @@ -23,6 +23,7 @@ export default function labelsChanged(app: Application): void {
if (fromRenovate) {
const codeApprovedLabel = repoContext.labels['code/approved'];
const autoMergeLabel = repoContext.labels['merge/automerge'];
const autoMergeSkipCiLabel = repoContext.labels['merge/skip-ci'];
if (context.payload.action === 'labeled') {
if (codeApprovedLabel && label.id === codeApprovedLabel.id) {
// const { data: reviews } = await context.github.pulls.listReviews(
Expand All @@ -32,6 +33,11 @@ export default function labelsChanged(app: Application): void {
await context.github.pulls.createReview(
context.issue({ event: 'APPROVE' }),
);
if (autoMergeSkipCiLabel) {
await context.github.issues.addLabels(
context.issue({ labels: [autoMergeSkipCiLabel.name] }),
);
}
await updateStatusCheckFromLabels(pr, context, repoContext);
await updatePrBody(pr, context, repoContext, {
autoMergeWithSkipCi: true,
Expand Down Expand Up @@ -77,15 +83,19 @@ export default function labelsChanged(app: Application): void {

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

if (
(featureBranchLabel && label.id === automergeLabel.id) ||
(automergeLabel && label.id === automergeLabel.id)
) {
const option: 'featureBranch' | 'autoMerge' =
featureBranchLabel && label.id === featureBranchLabel.id
? 'featureBranch'
: 'autoMerge';
const option = (() => {
if (featureBranchLabel && label.id === automergeLabel.id)
return 'featureBranch';
if (automergeLabel && label.id === automergeLabel.id)
return 'autoMerge';
if (skipCiLabel && label.id === skipCiLabel.id)
return 'autoMergeWithSkipCi';
return null;
})();

if (option) {
await updatePrBody(pr, context, repoContext, {
[option]: context.payload.action === 'labeled',
});
Expand Down

0 comments on commit 90f1375

Please sign in to comment.