Skip to content

Commit 9ecabc4

Browse files
authored
fix: do not attempt to create pull request when no changes detected (#2722)
1 parent c56e4ec commit 9ecabc4

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/github.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,20 @@ export class GitHub {
11691169
draft: !!options?.draft,
11701170
labels: pullRequest.labels,
11711171
});
1172+
if (prNumber === 0) {
1173+
this.logger.warn(
1174+
'no code changes detected, skipping pull request creation'
1175+
);
1176+
return {
1177+
headBranchName: pullRequest.headBranchName,
1178+
baseBranchName: targetBranch,
1179+
number: 0,
1180+
title: pullRequest.title,
1181+
body: pullRequest.body,
1182+
labels: pullRequest.labels,
1183+
files: [],
1184+
};
1185+
}
11721186
return await this.getPullRequest(prNumber);
11731187
}
11741188
);

test/github.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,33 @@ describe('GitHub', () => {
11421142
});
11431143
});
11441144

1145+
describe('createPullRequest', () => {
1146+
it('should not call getPullRequest when no code changes detected', async () => {
1147+
const createPullRequestStub = sandbox
1148+
.stub(codeSuggester, 'createPullRequest')
1149+
.resolves(0);
1150+
const getPullRequestStub = sandbox.stub(github, 'getPullRequest');
1151+
1152+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1153+
const pullRequest = await (github as any).createPullRequest(
1154+
{
1155+
headBranchName: 'release-please--branches--main',
1156+
baseBranchName: 'main',
1157+
title: 'Release v1.0.0',
1158+
body: 'Release body',
1159+
labels: ['release-please'],
1160+
},
1161+
'main',
1162+
'commit message',
1163+
[]
1164+
);
1165+
1166+
expect(pullRequest.number).to.eql(0);
1167+
sinon.assert.calledOnce(createPullRequestStub);
1168+
sinon.assert.notCalled(getPullRequestStub);
1169+
});
1170+
});
1171+
11451172
describe('buildChangeSet', () => {
11461173
it('should merge updates for the same file', async () => {
11471174
const manifestPath = '.release-please-manifest.json';

0 commit comments

Comments
 (0)