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

Revert "Remove old autofix logic" #1699

Merged
merged 3 commits into from
Oct 6, 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
9 changes: 9 additions & 0 deletions .changeset/little-carpets-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'skuba': patch
---

lint, format: Put back [logic](https://github.com/seek-oss/skuba/pull/1226/) which skips autofixing Renovate branches when there is no open pull request.

Previously, this was put in place to prevent an issue where a Renovate branch can get stuck in the `Edited/Blocked` state without a pull request being raised. This was subsequently removed because Skuba's default autofix commits [were ignored by skuba's recommended renovate configuration](https://github.com/seek-oss/rynovate/pull/121).

However, this has resulted in some build-rebase-build-rebase-... loops, and so the [Renovate config change has been reverted](https://github.com/seek-oss/rynovate/pull/125), and requires investigation before reinstating.
19 changes: 19 additions & 0 deletions src/cli/lint/autofix.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import simpleGit from 'simple-git';

import * as Buildkite from '../../api/buildkite';
import * as Git from '../../api/git';
import * as GitHub from '../../api/github';
import { runESLint } from '../adapter/eslint';
Expand All @@ -16,6 +17,7 @@ import { internalLint } from './internal';
jest.mock('simple-git');
jest.mock('../../api/git');
jest.mock('../../api/github');
jest.mock('../../api/buildkite');
jest.mock('../adapter/eslint');
jest.mock('../adapter/prettier');
jest.mock('./internal');
Expand Down Expand Up @@ -123,6 +125,23 @@ describe('autofix', () => {
expectNoAutofix();
});

it('bails on a renovate branch when there is no open pull request', async () => {
jest.mocked(Git.currentBranch).mockResolvedValue('renovate-skuba-7.x');
jest
.mocked(GitHub.getPullRequestNumber)
.mockRejectedValue(
new Error(
`Commit cdd1520 is not associated with an open GitHub pull request`,
),
);

await expect(autofix(params)).resolves.toBeUndefined();

expect(Buildkite.annotate).toHaveBeenCalled();

expectNoAutofix();
});

it('suceeds on a renovate branch when there is an open pull request associated with the commit', async () => {
jest.mocked(Git.currentBranch).mockResolvedValue('renovate-skuba-7.x');
jest.mocked(GitHub.getPullRequestNumber).mockResolvedValue(6);
Expand Down
18 changes: 18 additions & 0 deletions src/cli/lint/autofix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inspect } from 'util';

import simpleGit from 'simple-git';

import * as Buildkite from '../../api/buildkite';
import * as Git from '../../api/git';
import * as GitHub from '../../api/github';
import { isCiEnv } from '../../utils/env';
Expand All @@ -15,6 +16,8 @@ import { createDestinationFileReader } from '../configure/analysis/project';
import { internalLint } from './internal';
import type { Input } from './types';

const RENOVATE_DEFAULT_PREFIX = 'renovate';

const AUTOFIX_COMMIT_MESSAGE = 'Run `skuba format`';

export const AUTOFIX_IGNORE_FILES_BASE: Git.ChangedFile[] = [
Expand Down Expand Up @@ -63,6 +66,21 @@ const shouldPush = async ({
return false;
}

if (currentBranch?.startsWith(RENOVATE_DEFAULT_PREFIX)) {
try {
await GitHub.getPullRequestNumber();
} catch {
const warning =
'An autofix is available, but it was not pushed because an open pull request for this Renovate branch could not be found. If a pull request has since been created, retry the lint step to push the fix.';
log.warn(warning);
try {
await Buildkite.annotate(Buildkite.md.terminal(warning));
} catch {}

return false;
}
}

let headCommitMessage;
try {
headCommitMessage = await Git.getHeadCommitMessage({ dir });
Expand Down