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

fix(autofix): Fix draft PR button not using settings repos #88167

Merged
merged 7 commits into from
Apr 2, 2025

Conversation

jennmueng
Copy link
Member

@jennmueng jennmueng commented Mar 27, 2025

Fixes all uses of repository access to use a new useAutofixRepos hook that uses the codebases and repos list from the autofix state instead of using code mappings

also removes references to code mappings in set up instructions and notices!

CleanShot 2025-04-02 at 10 55 51@2x

@jennmueng jennmueng requested a review from roaga March 27, 2025 22:54
@jennmueng jennmueng requested a review from a team as a code owner March 27, 2025 22:54
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 27, 2025
Copy link

codecov bot commented Mar 27, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
10085 1 10084 5
View the top 1 failed test(s) by shortest run time
AutofixChanges passes correct analytics props for Create Branch button when write access is enabled
Stack Traces | 0.055s run time
Error: expect(received).toEqual(expected) // deep equality

Expected: ObjectContaining {"analyticsEventKey": "autofix.push_to_branch_clicked", "analyticsEventName": "Autofix: Push to Branch Clicked", "analyticsParams": {"group_id": "123"}}
Received: undefined
    at Object.<anonymous> (.../events/autofix/autofixChanges.analytics.spec.tsx:219:41)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@jennmueng jennmueng marked this pull request as draft April 1, 2025 20:20
auto-merge was automatically disabled April 1, 2025 20:20

Pull request was converted to draft

@jennmueng jennmueng force-pushed the jenn/autofix/fix-draft-pr-button branch from f6cd236 to 6710b8f Compare April 1, 2025 22:42
@jennmueng jennmueng requested a review from roaga April 1, 2025 23:07
@jennmueng jennmueng marked this pull request as ready for review April 1, 2025 23:09
@jennmueng jennmueng requested a review from a team as a code owner April 1, 2025 23:09
@jennmueng jennmueng force-pushed the jenn/autofix/fix-draft-pr-button branch from 7e85bbc to 309a871 Compare April 1, 2025 23:10
Comment on lines 44 to +62
mockButton.mockClear();
jest.mocked(useAutofixRepos).mockReset();
jest.mocked(useAutofixData).mockReset();
jest.mocked(useAutofixRepos).mockReturnValue({
repos: [],
codebases: {},
});
jest.mocked(useAutofixData).mockReturnValue({
data: {
request: {
repos: [],
},
codebases: {},
created_at: '2024-01-01T00:00:00Z',
run_id: '456',
status: AutofixStatus.COMPLETED,
},
isPending: false,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it better to mock API responses rather than hooks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm i remember why I did it this way, the mock api response doesn't work because useAutofixData is enabled:false and only fetches from cache, mocking that would be difficult

Comment on lines +41 to +44
jest.mocked(useAutofixRepos).mockReset();
jest.mocked(useAutofixRepos).mockReturnValue({
repos: [],
codebases: {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, I couldn't get it to use the mocked api response through useAutofixData, and mocking useAutofixData directly, useAutofixRepos wouldn't use the internal representation for some reason...

@@ -474,6 +473,8 @@ function AutofixSolutionDisplay({
const containerRef = useRef<HTMLDivElement>(null);
const iconFixRef = useRef<HTMLDivElement>(null);

const changesDisabled = repos.every(repo => repo.is_readable === false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be disabled if any repo is not accessible? (I can see an argument both ways I guess, so up to you)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could have the case for example, that the fix is in seer, but you have the sentry repo leftover as context that isn't readable...ideally we can just pinpoint which repos the solution is in to make this condition better.

I should also update the guard message here to make it more clear...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the solution timeline does include relevant repo names in its payload, so we could use that, but might not be reliable and might not work with human instructions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah right now it's inconsistent, we should update the solution formatter to output repo names/ids for each step, for now I guess this should be sufficient

return (
<AnimatePresence initial={props.isSolutionFirstAppearance}>
<AnimationWrapper key="card" {...cardAnimationProps}>
<AutofixSolutionDisplay {...props} changesDisabled={changesDisabled} />
<AutofixSolutionDisplay {...props} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you doing with changesDisabled if not passing it here? is it an unused var?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above code for changesDisabled is inside AutofixSolutionDisplay

autofixRepositories,
hasGithubIntegration,
}: SeerNoticesProps) {
export function SeerNotices({groupId, hasGithubIntegration}: SeerNoticesProps) {
Copy link
Member

@roaga roaga Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a notice for the case where (you have no repos in settings AND no repos from code mappings AND you do have the github integration)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out, I'll do that in a follow up PR where I do the flow for onboarding the repo settings

@jennmueng jennmueng force-pushed the jenn/autofix/fix-draft-pr-button branch from e57056f to ed6c6e3 Compare April 2, 2025 18:38
@jennmueng jennmueng enabled auto-merge (squash) April 2, 2025 19:44
@jennmueng jennmueng merged commit 0c5725b into master Apr 2, 2025
40 checks passed
@jennmueng jennmueng deleted the jenn/autofix/fix-draft-pr-button branch April 2, 2025 20:00
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
Fixes all uses of repository access to use a new `useAutofixRepos` hook
that uses the codebases and repos list from the autofix state instead of
using code mappings

also removes references to code mappings in set up instructions and
notices!

![CleanShot 2025-04-02 at 10 55
51@2x](https://github.com/user-attachments/assets/099d64a1-0aec-4ec0-ad5e-b3bb2f849505)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants