Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acceptInvalidCommits formatter #38

Merged
merged 2 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/steps/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function addPullRequestCommits(pkg, commits, pr) {
href: info.user.html_url,
};
pr.href = info.html_url;
pr.title = info.title;
pr.title = info.title || info.header;
var shas = pr.shas = _.map(prCommits, 'sha');
pr.commits = commits.filter(function isPartOfPR(commit) {
return shas.indexOf(commit.sha) !== -1;
Expand Down Expand Up @@ -134,9 +134,13 @@ function generateChangeLog(cwd, pkg, options) {
}

function formatCommit(commit) {
return getCommitLink(commit) +
' **' + commit.type + ':** ' +
commit.subject +
var subject;
if (commit.type) {
subject = '**' + commit.type + ':** ' + commit.subject;
} else {
subject = commit.header;
}
return getCommitLink(commit) + ' ' + subject +
formatReferences(commit.references);
}

Expand Down
19 changes: 18 additions & 1 deletion test/steps/changelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,13 @@ describe('generateChangeLog', function () {
pullId: '2',
},
];
var sloppyCommits = commits.map(function (commit) {
if (commit.type === 'pr') return commit;
return { sha: commit.sha, header: commit.subject };
});
var options = { commits: commits };
var changelog = null;
var sloppyChangelog = null;

before('generateChangeLog', function () {
return generateChangeLog(null, pkg, options)
Expand All @@ -299,14 +304,26 @@ describe('generateChangeLog', function () {
});
});

before('generateSloppyChangeLog', function () {
return generateChangeLog(null, pkg, { commits: sloppyCommits })
.then(function (_changelog) {
sloppyChangelog = _changelog;
});
});

it('calls out to github to get PR info', function () {
assert.equal(2, httpCalls.length);
assert.equal(4, httpCalls.length);
});

it('ignores the PR', function () {
assert.notInclude('* PR #2 Title', changelog);
assert.include('* [`1234567`]', changelog);
});

it('handles poorly formatted commit messages too', function () {
assert.include(') Stop doing the wrong thing\n', sloppyChangelog);
assert.include(') Do more things', sloppyChangelog);
});
});

describe('with a missing PR', function () {
Expand Down