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

[STA-3724] automerge filters: fix early return in conventional commit filter #60

Merged
merged 1 commit into from
Jan 31, 2024
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
6 changes: 4 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,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 @@ -1700,11 +1701,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 @@ -1718,8 +1720,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
Loading