Skip to content

Commit

Permalink
feat: don't remove link to PR until new commits landed (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 15, 2019
1 parent 73d9165 commit 6316331
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
30 changes: 30 additions & 0 deletions __snapshots__/candidate-issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exports['CandidateIssue bodySansFooter returns the body with the footer removed 1'] = `
_:robot: Here's what the next release of **@foo/bar** would look like._
---
Features:
* deps: upgrade foo
---
`

exports['CandidateIssue bodyTemplate generates body for issue 1'] = `
_:robot: Here's what the next release of **@foo/bar** would look like._
---
Features:
* deps: upgrade foo
---
[//]: # footer follows.
* [ ] **Should I create this release for you :robot:?**
`
18 changes: 14 additions & 4 deletions src/candidate-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {ReleasePR, ReleasePROptions} from './release-pr';
const parseGithubRepoUrl = require('parse-github-repo-url');

const ISSUE_TITLE = 'chore(release): proposal for next release';
const ISSUE_FOOTER = '[//]: # footer follows.';
const CHECKBOX = '* [ ] **Should I create this release for you :robot:?**';
const CHECK_REGEX = /\[x]/;

Expand Down Expand Up @@ -79,7 +80,8 @@ export class CandidateIssue {

const issue: IssuesListResponseItem|undefined =
await this.gh.findExistingReleaseIssue(ISSUE_TITLE);
let body: string = this.bodyTemplate(changelogEntry);
let body: string =
CandidateIssue.bodyTemplate(changelogEntry, this.packageName);

if (issue) {
if (CHECK_REGEX.test(issue.body)) {
Expand All @@ -98,7 +100,7 @@ export class CandidateIssue {
});
const prNumber = await rp.run();
body = body.replace(CHECKBOX, `**release created at #${prNumber}**`);
} else if (issue.body === body) {
} else if (CandidateIssue.bodySansFooter(issue.body) === CandidateIssue.bodySansFooter(body)) {
// don't update the issue if the content is the same for the release.
checkpoint(
`skipping update to #${issue.number}, no change to body`,
Expand Down Expand Up @@ -143,17 +145,25 @@ export class CandidateIssue {
return new GitHub({token: this.token, owner, repo});
}

private bodyTemplate(changelogEntry: string): string {
static bodyTemplate(changelogEntry: string, packageName: string): string {
return `_:robot: Here's what the next release of **${
this.packageName}** would look like._
packageName}** would look like._
---
${changelogEntry}
---
${ISSUE_FOOTER}
${CHECKBOX}
`;
}

static bodySansFooter(body: string): string {
const footerPosition = body.indexOf(ISSUE_FOOTER);
if (footerPosition === -1) return body;
else return body.slice(0, footerPosition);
}
}
39 changes: 39 additions & 0 deletions test/candidate-issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2019 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as snapshot from 'snap-shot-it';

import {CandidateIssue} from '../src/candidate-issue';

const fixturesPath = './test/fixtures';

describe('CandidateIssue', () => {
describe('bodyTemplate', () => {
it('generates body for issue', () => {
const body = CandidateIssue.bodyTemplate(
'Features:\n* deps: upgrade foo\n', '@foo/bar');
snapshot(body);
});
});

describe('bodySansFooter', () => {
it('returns the body with the footer removed', () => {
const body = CandidateIssue.bodyTemplate(
'Features:\n* deps: upgrade foo\n', '@foo/bar');
snapshot(CandidateIssue.bodySansFooter(body));
})
})
});

0 comments on commit 6316331

Please sign in to comment.