Skip to content

Commit

Permalink
feat: sync feature-branch label
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed May 25, 2019
1 parent f0558d4 commit 278aa6f
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 16 deletions.
20 changes: 17 additions & 3 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.

20 changes: 17 additions & 3 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.

17 changes: 11 additions & 6 deletions src/context/repoContext.ts
Expand Up @@ -16,7 +16,7 @@ export interface LockedMergePr {

interface RepoContextWithoutTeamContext<GroupNames extends string> {
labels: Labels;
protectedLabelIds: LabelResponse['id'][];
protectedLabelIds: readonly LabelResponse['id'][];

hasNeedsReview: (labels: LabelResponse[]) => boolean;
hasRequestedReview: (labels: LabelResponse[]) => boolean;
Expand Down Expand Up @@ -76,6 +76,15 @@ async function initRepoContext<GroupNames extends string>(
.filter(Boolean)
.map((name) => labels[name].id);

const protectedLabelIds = [
...requestedReviewLabelIds,
...changesRequestedLabelIds,
...approvedReviewLabelIds,
];
if (labels['feature-branch']) {
protectedLabelIds.push(labels['feature-branch'].id);
}

const labelIdToGroupName = new Map<LabelResponse['id'], GroupNames>();
reviewGroupNames.forEach((key) => {
const reviewGroupLabels = config.labels.review[key] as any;
Expand Down Expand Up @@ -147,11 +156,7 @@ async function initRepoContext<GroupNames extends string>(

return Object.assign(repoContext, {
labels,
protectedLabelIds: [
...requestedReviewLabelIds,
...changesRequestedLabelIds,
...approvedReviewLabelIds,
],
protectedLabelIds,
hasNeedsReview,
hasRequestedReview,
hasChangesRequestedReview,
Expand Down
1 change: 1 addition & 0 deletions src/pr-handlers/actions/editOpenedPR.ts
Expand Up @@ -148,6 +148,7 @@ export const editOpenedPR = async (
await context.github.issues.update(context.issue(update));
}

console.log(options);
if (options && featureBranchLabel) {
if (prHasFeatureBranchLabel && !options.featureBranch) {
await context.github.issues.removeLabel(
Expand Down
18 changes: 18 additions & 0 deletions src/pr-handlers/actions/utils/parseBody.test.ts
@@ -1,6 +1,7 @@
import { parseBody } from './parseBody';
import initialSimple from './mocks/body/initial-simple';
import initialTable from './mocks/body/initial-table';
import initialAfterEditSimple from './mocks/body/initialAfterEdit-simple';

describe('simple', () => {
it('should parse default description', () => {
Expand Down Expand Up @@ -35,3 +36,20 @@ describe('table', () => {
});
});
});

describe('table', () => {
it('should parse edited description', () => {
const defaultConfig = {
featureBranch: true,
deleteAfterMerge: true,
};

const parsed = parseBody(initialAfterEditSimple, defaultConfig);

expect(parsed).not.toBeFalsy();
expect(parsed && parsed.options).toEqual({
featureBranch: false,
deleteAfterMerge: true,
});
});
});
2 changes: 1 addition & 1 deletion src/pr-handlers/actions/utils/parseBody.ts
Expand Up @@ -15,7 +15,7 @@ const parseOptions = (
const match = regexp.exec(content);
acc[name] = !match
? defaultConfig[name] || false
: match[1] === 'x' || match[2] === 'X';
: match[1] === 'x' || match[1] === 'X';
return acc;
},
{} as any,
Expand Down
2 changes: 1 addition & 1 deletion src/pr-handlers/actions/utils/prOptions.ts
Expand Up @@ -4,7 +4,7 @@ export const options: Options[] = ['featureBranch', 'deleteAfterMerge'];
export const optionsRegexps: { name: Options; regexp: RegExp }[] = options.map(
(option) => ({
name: option,
regexp: new RegExp(`\\[[ xX]]\\s*<!-- renovate-${option} -->`),
regexp: new RegExp(`\\[([ xX]?)]\\s*<!-- reviewflow-${option} -->`),
}),
);

Expand Down
6 changes: 6 additions & 0 deletions src/teamconfigs/christophehurpeau.ts
Expand Up @@ -62,6 +62,12 @@ const config: Config<'dev'> = {
name: ':soon: automerge',
color: '#64DD17',
},

/* feature-branch */
'feature-branch': {
name: 'feature-branch',
color: '#7FCEFF',
},
},

review: {
Expand Down

0 comments on commit 278aa6f

Please sign in to comment.