Skip to content

Commit

Permalink
automerge filters: fix early return in conventional commit filter
Browse files Browse the repository at this point in the history
  • Loading branch information
meorphis committed Jan 31, 2024
1 parent 9e84ad1 commit fe81a1d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@ export class Manifest {
filter => `${filter.type}:${filter.scope ? filter.scope : '*'}`
)
);
// return true if every commit matches the filter - false otherwise
if (conventionalCommitFilter!.matchBehaviour === 'match-all') {
for (const commit of pullRequest.conventionalCommits) {
if (
Expand All @@ -1702,11 +1703,12 @@ export class Manifest {
);
return false;
}
return true;
}
return true;
} else if (
conventionalCommitFilter!.matchBehaviour === 'match-at-least-one'
) {
// return true if any commit matches the filter - false otherwise
for (const commit of pullRequest.conventionalCommits) {
if (
filterSet.has(`${commit.type}:${commit.scope}`) ||
Expand All @@ -1720,8 +1722,8 @@ export class Manifest {
);
return true;
}
return false;
}
return false;
}
return false;
};
Expand Down
76 changes: 70 additions & 6 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5051,6 +5051,38 @@ version = "3.0.0"
},
],
},
{
title: PullRequestTitle.ofTargetBranch('main', 'main'),
body: new PullRequestBody([]),
updates: [],
labels: [],
headRefName: 'release-please/branches/main/components/b',
draft: false,
version: Version.parse('1.1.0'), // minor bump, match filter
previousVersion: Version.parse('1.0.0'),
conventionalCommits: [
{
type: 'fix', // type match filter
scope: 'api', // scope match filter
notes: [],
references: [],
sha: 'commit123',
message: 'fix(api): something',
bareMessage: 'something',
breaking: false,
},
{
type: 'feat(client)', // type does not match filter
scope: 'api', // scope match filter
notes: [],
references: [],
sha: 'commit123',
message: 'fix(api): something',
bareMessage: 'something',
breaking: false,
},
],
},
{
title: PullRequestTitle.ofTargetBranch('main', 'main'),
body: new PullRequestBody([]),
Expand Down Expand Up @@ -5125,11 +5157,11 @@ version = "3.0.0"

const pullRequestNumbers = await manifest.createPullRequests();

expect(pullRequestNumbers).lengthOf(5);
expect(pullRequestNumbers).lengthOf(6);
sinon.assert.calledOnce(getLabelsStub);
sinon.assert.calledOnce(createLabelsStub);

expect(createPullRequestStub.callCount).to.equal(5);
expect(createPullRequestStub.callCount).to.equal(6);
sinon.assert.calledWith(
createPullRequestStub,
sinon.match.has('headBranchName', sinon.match.string),
Expand All @@ -5143,7 +5175,7 @@ version = "3.0.0"
expect(enablePullRequestAutoMergeStub.callCount).to.equal(1);

// only called when not auto-merged
expect(addPullRequestReviewersStub.callCount).to.equal(4);
expect(addPullRequestReviewersStub.callCount).to.equal(5);
});

it('enables auto-merge when filters are provided (filters: only commit type, match-all)', async () => {
Expand Down Expand Up @@ -5453,6 +5485,38 @@ version = "3.0.0"
},
],
},
{
title: PullRequestTitle.ofTargetBranch('main', 'main'),
body: new PullRequestBody([]),
updates: [],
labels: [],
headRefName: 'release-please/branches/main/components/a',
draft: false,
version: Version.parse('1.0.1'), // version bump match filter
previousVersion: Version.parse('1.0.0'),
conventionalCommits: [
{
type: 'ci', // first type does not match filter
scope: 'something',
notes: [],
references: [],
sha: 'commit123',
message: 'ci(something): something',
bareMessage: 'something',
breaking: false,
},
{
type: 'fix', // type match filter
scope: 'something',
notes: [],
references: [],
sha: 'commit123',
message: 'fix(something): something',
bareMessage: 'something',
breaking: false,
},
],
},
{
title: PullRequestTitle.ofTargetBranch('main', 'main'),
body: new PullRequestBody([]),
Expand Down Expand Up @@ -5621,11 +5685,11 @@ version = "3.0.0"

const pullRequestNumbers = await manifest.createPullRequests();

expect(pullRequestNumbers).lengthOf(6);
expect(pullRequestNumbers).lengthOf(7);
sinon.assert.calledOnce(getLabelsStub);
sinon.assert.calledOnce(createLabelsStub);

expect(createPullRequestStub.callCount).to.equal(6);
expect(createPullRequestStub.callCount).to.equal(7);
sinon.assert.calledWith(
createPullRequestStub,
sinon.match.has('headBranchName', sinon.match.string),
Expand All @@ -5636,7 +5700,7 @@ version = "3.0.0"
sinon.match.object
);

expect(enablePullRequestAutoMergeStub.callCount).to.equal(3);
expect(enablePullRequestAutoMergeStub.callCount).to.equal(4);
// only called when not auto-merged
expect(addPullRequestReviewersStub.callCount).to.equal(3);
});
Expand Down

0 comments on commit fe81a1d

Please sign in to comment.