Skip to content

Commit 36bd2b0

Browse files
fix(check-merge-safety): expand error type handling (#704)
Co-authored-by: bensbigolbeard <[email protected]>
1 parent f8c66ec commit 36bd2b0

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

dist/431.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/431.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/check-merge-safety.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const getDiff = async (compareBase: DiffRefs, compareHead: DiffRefs, basehead: s
130130
core.info(`Failed to fetch diff: ${(err as GithubError).message} Status: ${(err as GithubError).status}`);
131131

132132
// diff too large error
133-
if ((err as GithubError)?.status === 406) {
133+
if ((err as GithubError)?.status === 406 || (err as GithubError)?.message.includes('diff is taking too long to generate')) {
134134
core.info(`Attempting to generate diff using local git command`);
135135
if (compareBase.repo?.html_url) {
136136
changedFileNames = await getDiffUsingGitCommand(compareBase.repo?.html_url, compareBase.sha, compareHead.sha);

test/helpers/check-merge-safety.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type MockGithubRequests = (
6262
filesOutOfDate: string[],
6363
changedFilesOnPr: string[],
6464
branch?: string,
65-
error?: { status: number; message?: string } | null
65+
error?: { status: number | string; message?: string } | null
6666
) => void;
6767
const mockGithubRequests: MockGithubRequests = (filesOutOfDate, changedFilesOnPr, branch = branchName, error = null) => {
6868
(octokit.repos.compareCommitsWithBasehead as unknown as Mocktokit).mockImplementation(async ({ basehead }) => {
@@ -136,7 +136,7 @@ describe('checkMergeSafety', () => {
136136
expect(core.setFailed).toHaveBeenCalledWith('This branch has one or more outdated projects. Please update with main.');
137137
});
138138

139-
it('should allow merge when branch is only out of date for an unchanged project - diff too large error', async () => {
139+
it('should allow merge when branch is only out of date for an unchanged project - diff too large error status', async () => {
140140
const filesOutOfDate = ['packages/package-2/src/another-file.ts'];
141141
const changedFilesOnPr = ['packages/package-1/src/some-file.ts'];
142142
mockGithubRequests(filesOutOfDate, changedFilesOnPr, branchName, { status: 406 });
@@ -157,6 +157,30 @@ describe('checkMergeSafety', () => {
157157
expect(core.setFailed).not.toHaveBeenCalled();
158158
});
159159

160+
it('should allow merge when branch is only out of date for an unchanged project - diff too large error message', async () => {
161+
const filesOutOfDate = ['packages/package-2/src/another-file.ts'];
162+
const changedFilesOnPr = ['packages/package-1/src/some-file.ts'];
163+
mockGithubRequests(filesOutOfDate, changedFilesOnPr, branchName, {
164+
status: 'not_available',
165+
message: 'yadda yadda diff is taking too long to generate yadda yadda'
166+
});
167+
mockGitInteractions(filesOutOfDate, changedFilesOnPr);
168+
169+
await checkMergeSafety({
170+
paths: allProjectPaths,
171+
...context.repo
172+
});
173+
expect(setCommitStatus).toHaveBeenCalledWith({
174+
sha,
175+
state: 'success',
176+
context: 'Merge Safety',
177+
description: 'Branch username:some-branch-name is safe to merge!',
178+
repo: 'repo',
179+
owner: 'owner'
180+
});
181+
expect(core.setFailed).not.toHaveBeenCalled();
182+
});
183+
160184
it('should prevent merge when branch is out of date for a changed project - diff too large error', async () => {
161185
const filesOutOfDate = ['packages/package-1/src/another-file.ts'];
162186
const changedFilesOnPr = ['packages/package-1/src/some-file.ts'];

0 commit comments

Comments
 (0)