Skip to content

Commit

Permalink
fix: if we generate a CHANGELOG with only a header, don't open a PR (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 17, 2019
1 parent c4b2a08 commit ba68930
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

28 changes: 14 additions & 14 deletions src/github.ts
Expand Up @@ -139,20 +139,20 @@ export class GitHub {
});
for (let i = 0, pull; i < pullsResponse.data.length; i++) {
pull = pullsResponse.data[i];
for (let ii = 0, label; ii < pull.labels.length; ii++) {
label = pull.labels[ii];
if (labels.indexOf(label.name) !== -1) {
// it's expected that a release PR will have a
// HEAD matching the format repo:release-v1.0.0.
if (!pull.head) continue;
const match = pull.head.label.match(VERSION_FROM_BRANCH_RE);
if (!match || !pull.merged_at) continue;
return {
number: pull.number,
sha: pull.merge_commit_sha,
version: match[1]
} as GitHubReleasePR;
}
// we look for a PR that has autorelease: pending, and type: process; once
// a release occurs, the autorelease: pending label is removed.
if (pull.labels.map(l => l.name).sort().join(',') ===
labels.slice(0).sort().join(',')) {
// it's expected that a release PR will have a
// HEAD matching the format repo:release-v1.0.0.
if (!pull.head) continue;
const match = pull.head.label.match(VERSION_FROM_BRANCH_RE);
if (!match || !pull.merged_at) continue;
return {
number: pull.number,
sha: pull.merge_commit_sha,
version: match[1]
} as GitHubReleasePR;
}
}
return undefined;
Expand Down
21 changes: 11 additions & 10 deletions src/release-pr.ts
Expand Up @@ -93,16 +93,6 @@ export class ReleasePR {
const commits: string[] =
await this.commits(latestTag ? latestTag.sha : undefined);

// don't create a release candidate until user facing changes
// (fix, feat, BREAKING CHANGE) have been made.
if (commits.length === 0) {
checkpoint(
`no user facing commits found since ${
latestTag ? latestTag.sha : 'beginning of time'}`,
CheckpointType.Failure);
return undefined;
}

const cc = new ConventionalCommits({
commits,
githubRepoUrl: this.repoUrl,
Expand All @@ -117,6 +107,17 @@ export class ReleasePR {
previousTag: candidate.previousTag
});

// don't create a release candidate until user facing changes
// (fix, feat, BREAKING CHANGE) have been made; a CHANGELOG that's
// one line is a good indicator that there were no interesting commits.
if (changelogEntry.split('\n').length === 1) {
checkpoint(
`no user facing commits found since ${
latestTag ? latestTag.sha : 'beginning of time'}`,
CheckpointType.Failure);
return undefined;
}

const updates: Update[] = [];

updates.push(new Changelog({
Expand Down
21 changes: 11 additions & 10 deletions system-test/github.ts
Expand Up @@ -155,18 +155,19 @@ describe('GitHub', () => {
});

describe('latestReleasePR', () => {
it('returns the latest closed PR with "autorelease: pending" tag',
it('returns the latest closed PR with "autorelease: pending"/"type: process" tag',
async () => {
const gh = new GitHub({owner: 'bcoe', repo: 'node-25650-bug'});
const pr =
await nockBack('latest-release-pr.json')
.then((nbr: NockBackResponse) => {
return gh.findMergedReleasePR(['autorelease: pending'])
.then((res) => {
nbr.nockDone();
return res;
});
});
const pr = await nockBack('latest-release-pr.json')
.then((nbr: NockBackResponse) => {
return gh
.findMergedReleasePR(
['type: process', 'autorelease: pending'])
.then((res) => {
nbr.nockDone();
return res;
});
});
pr.should.eql({
version: 'v1.1.0',
sha: 'f52c585f1319b789ff75e864fe9bf7479f72ae0e',
Expand Down

0 comments on commit ba68930

Please sign in to comment.