Skip to content

Commit

Permalink
feat: sync feature-branch label with tag
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed May 25, 2019
1 parent 278aa6f commit 0f47044
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 62 deletions.
55 changes: 34 additions & 21 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.

55 changes: 34 additions & 21 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.

3 changes: 0 additions & 3 deletions src/context/repoContext.ts
Expand Up @@ -81,9 +81,6 @@ async function initRepoContext<GroupNames extends string>(
...changesRequestedLabelIds,
...approvedReviewLabelIds,
];
if (labels['feature-branch']) {
protectedLabelIds.push(labels['feature-branch'].id);
}

const labelIdToGroupName = new Map<LabelResponse['id'], GroupNames>();
reviewGroupNames.forEach((key) => {
Expand Down
1 change: 0 additions & 1 deletion src/pr-handlers/actions/editOpenedPR.ts
Expand Up @@ -148,7 +148,6 @@ 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
@@ -0,0 +1,24 @@
export default `
### Context
Explain here why this PR is needed
### Solution
If needed, explain here the solution you chose for this
<!-- Uncomment this if you need a testing plan
### Testing plan
- [ ] Test this
- [ ] Test that
-->
<!-- do not edit after this -->
#### Infos:
Some informations here, like links.
#### Options:
- [ ] <!-- reviewflow-featureBranch -->This PR is a feature branch
- [x] <!-- reviewflow-deleteAfterMerge -->Automatic branch delete after this PR is merged
<!-- end - don't add anything after this -->
`;

// [ONK-0000](https://a;dlkas;dlkas;dk)
6 changes: 4 additions & 2 deletions src/pr-handlers/actions/utils/parseBody.ts
Expand Up @@ -3,7 +3,7 @@ import { Options, optionsRegexps } from './prOptions';
const commentStart = '<!-- do not edit after this -->';
const commentEnd = "<!-- end - don't add anything after this -->";

const regexpCols = /^(.*)(<!---? do not edit after this -?-->.*<!---? end - don't add anything after this -?-->).*$/is;
const regexpCols = /^(.*)(<!---? do not edit after this -?-->(.*)<!---? end - don't add anything after this -?-->).*$/is;
const regexpReviewflowCol = /^(\s*<!---? do not edit after this -?--><\/td><td [^>]*>)\s*(.*)\s*(<\/td><\/tr><\/table>\s*<!---? end - don't add anything after this -?-->)\s*$/is;

const parseOptions = (
Expand All @@ -28,11 +28,12 @@ export const parseBody = (
) => {
const match = regexpCols.exec(description);
if (!match) return null;
const [, content, reviewFlowCol] = match;
const [, content, reviewFlowCol, reviewflowContent] = match;
const reviewFlowColMatch = regexpReviewflowCol.exec(reviewFlowCol);
if (!reviewFlowColMatch) {
return {
content,
reviewflowContentCol: reviewflowContent,
reviewflowContentColPrefix: commentStart,
reviewflowContentColSuffix: commentEnd,
options: parseOptions(reviewFlowCol, defaultConfig),
Expand All @@ -47,6 +48,7 @@ export const parseBody = (

return {
content,
reviewflowContentCol,
reviewflowContentColPrefix,
reviewflowContentColSuffix,
options: parseOptions(reviewflowContentCol, defaultConfig),
Expand Down
28 changes: 28 additions & 0 deletions src/pr-handlers/actions/utils/updateBody.test.ts
@@ -1,6 +1,7 @@
import { updateBody } from './updateBody';
import initialSimple from './mocks/body/initial-simple';
import initialAfterEditSimple from './mocks/body/initialAfterEdit-simple';
import initialAfterEditSimpleWithInfos from './mocks/body/initialAfterEdit-simpleWithInfos';
import initialTable from './mocks/body/initial-table';
import initialAfterEditTable from './mocks/body/initialAfterEdit-table';

Expand All @@ -14,6 +15,33 @@ describe('simple', () => {
initialAfterEditSimple,
);
});

it('should keep infos on update', () => {
const defaultConfig = {
featureBranch: false,
deleteAfterMerge: true,
};
expect(
updateBody(initialAfterEditSimpleWithInfos, defaultConfig).body,
).toEqual(initialAfterEditSimpleWithInfos);
});

it('should update options', () => {
const defaultConfig = {
featureBranch: false,
deleteAfterMerge: true,
};
expect(
updateBody(initialAfterEditSimpleWithInfos, defaultConfig, undefined, {
featureBranch: true,
}).body,
).toEqual(
initialAfterEditSimpleWithInfos.replace(
'- [ ] <!-- reviewflow-featureBranch -->',
'- [x] <!-- reviewflow-featureBranch -->',
),
);
});
});

describe('table', () => {
Expand Down

0 comments on commit 0f47044

Please sign in to comment.