Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

fix: connection pending alert and alert content alignment#64120

Merged
bahrmichael merged 8 commits intomainfrom
bahrmichael/2024-07-29-fix-user-connections
Jul 29, 2024
Merged

fix: connection pending alert and alert content alignment#64120
bahrmichael merged 8 commits intomainfrom
bahrmichael/2024-07-29-fix-user-connections

Conversation

@bahrmichael
Copy link
Contributor

When there is already a global token, then the notice after installing a personal app is wrong. This PR handles this issue, so that the notice shows up as expected.

We also fix an alignment issue, where the call to refresh the page would be in a distinct column, instead of what we'd expect.

Test plan

Manual testing

Changelog

@bahrmichael bahrmichael requested a review from a team July 29, 2024 08:29
@cla-bot cla-bot bot added the cla-signed label Jul 29, 2024
@bahrmichael bahrmichael enabled auto-merge (squash) July 29, 2024 08:29
Comment on lines +86 to +88
.filter(n => n.credential)
.filter(n => n.credential?.isSiteCredential === (gitHubAppKind === GitHubAppKind.SITE_CREDENTIAL)).length ??
0) === 0
Copy link
Contributor

Choose a reason for hiding this comment

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

We could combine these filters to reduce the amount of loops we do for connection nodes.

CleanShot 2024-07-29 at 10 36 59@2x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the fix. I'm not sure how this solves the problem though. The CodeHostConnections component is used for both USER_CREDENTIAL and SITE_CREDENTIAL.

However, I'm not sure how this logic fixes it. Can you explain the solution for me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! The problem I saw occurred when there was already a global token. When I then added a personal github app, it showed a wrong alert. Before this change, it will consider all credentials (even the site credential) as counting towards the installations that may be in progress. The approach currently used relies on checking if there are any integrations that don't have credentials yet to determine if an installation is in progress. With SRCH-798 we can deprecate this behavior, but that ticket is significantly more work.

So this component gets all the (non-commit-signing) credentials. We then add a check if it matches the gitHubAppKind condition to filter down to only user or site-admin credentials.

gitHubAppKind === GitHubAppKind.SITE_CREDENTIAL yields true if we're in the site-admin page, and that can then be compared with n.credential?.isSiteCredential.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • If there is already a connection from another host, this may yield a false result.

success &&
gitHubAppKindFromUrl !== GitHubAppKind.COMMIT_SIGNING &&
(connection?.nodes.filter(n => n.credential).length ?? 0) === 0
(connection?.nodes.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to check if the connection is a GitHub app so we can check against GitHub apps alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a check to limit it to GitHub apps.

Comment on lines +17 to +21
return (
nodes.filter(
n => n.externalServiceKind === ExternalServiceKind.GITHUB && n.credential?.gitHubApp?.name === appName
).length > 0
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This works, but we could opt for a cool array iterator available in javascript.

Suggested change
return (
nodes.filter(
n => n.externalServiceKind === ExternalServiceKind.GITHUB && n.credential?.gitHubApp?.name === appName
).length > 0
)
return !nodes.some(n => n.externalServiceKind === ExternalServiceKind.GITHUB && n.credential?.gitHubApp?.name === appName)

You can read about it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! some works too in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, just a suggestion. Feel free to discard / put off to a later PR.
THe performance improvement is negligible for now as we dont have customers with a bucket load of codehost connections.

@bahrmichael bahrmichael merged commit 67c9a09 into main Jul 29, 2024
@bahrmichael bahrmichael deleted the bahrmichael/2024-07-29-fix-user-connections branch July 29, 2024 12:46
bahrmichael referenced this pull request Jul 29, 2024
)

This is a follow up to
https://github.com/sourcegraph/sourcegraph/pull/64120 so that it doesn't
mix up alerts between commit signing and code hosts for site admins.

## Test plan

Manual testing + CI

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants