Skip to content
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
2 changes: 1 addition & 1 deletion dist/431.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/431.index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/helpers/check-merge-safety.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const getDiff = async (compareBase: DiffRefs, compareHead: DiffRefs, basehead: s
core.info(`Failed to fetch diff: ${(err as GithubError).message} Status: ${(err as GithubError).status}`);

// diff too large error
if ((err as GithubError)?.status === 406) {
if ((err as GithubError)?.status === 406 || (err as GithubError)?.message.includes('diff is taking too long to generate')) {
core.info(`Attempting to generate diff using local git command`);
if (compareBase.repo?.html_url) {
changedFileNames = await getDiffUsingGitCommand(compareBase.repo?.html_url, compareBase.sha, compareHead.sha);
Expand Down
28 changes: 26 additions & 2 deletions test/helpers/check-merge-safety.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type MockGithubRequests = (
filesOutOfDate: string[],
changedFilesOnPr: string[],
branch?: string,
error?: { status: number; message?: string } | null
error?: { status: number | string; message?: string } | null
) => void;
const mockGithubRequests: MockGithubRequests = (filesOutOfDate, changedFilesOnPr, branch = branchName, error = null) => {
(octokit.repos.compareCommitsWithBasehead as unknown as Mocktokit).mockImplementation(async ({ basehead }) => {
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('checkMergeSafety', () => {
expect(core.setFailed).toHaveBeenCalledWith('This branch has one or more outdated projects. Please update with main.');
});

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

it('should allow merge when branch is only out of date for an unchanged project - diff too large error message', async () => {
const filesOutOfDate = ['packages/package-2/src/another-file.ts'];
const changedFilesOnPr = ['packages/package-1/src/some-file.ts'];
mockGithubRequests(filesOutOfDate, changedFilesOnPr, branchName, {
status: 'not_available',
message: 'yadda yadda diff is taking too long to generate yadda yadda'
});
mockGitInteractions(filesOutOfDate, changedFilesOnPr);

await checkMergeSafety({
paths: allProjectPaths,
...context.repo
});
expect(setCommitStatus).toHaveBeenCalledWith({
sha,
state: 'success',
context: 'Merge Safety',
description: 'Branch username:some-branch-name is safe to merge!',
repo: 'repo',
owner: 'owner'
});
expect(core.setFailed).not.toHaveBeenCalled();
});

it('should prevent merge when branch is out of date for a changed project - diff too large error', async () => {
const filesOutOfDate = ['packages/package-1/src/another-file.ts'];
const changedFilesOnPr = ['packages/package-1/src/some-file.ts'];
Expand Down