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

feat: introduce database fields for github apps <-> batch changes integration, and update database layer#63577

Merged
BolajiOlajide merged 38 commits intomainfrom
06-28-add_github_app_id_field_to_site_credential_struct
Jul 2, 2024
Merged

feat: introduce database fields for github apps <-> batch changes integration, and update database layer#63577
BolajiOlajide merged 38 commits intomainfrom
06-28-add_github_app_id_field_to_site_credential_struct

Conversation

@bahrmichael
Copy link
Contributor

@bahrmichael bahrmichael commented Jul 1, 2024

Closes SRCH-659

This PR introduces new database fields to site_credentials and user_credentials. The goal is to enable an integration between regular batch change activity and github apps.

We have implemented db migrations to add the new fields, and updated the database layer to work with those. There's a new skipped test that can be unskipped once we implement the new could that errors out with "not implemented".

This should be safe to merge as long as no one is creating github apps and credentials directly in the database. There is no exposed feature yet through which users could do this themselves.

Test plan

  • Updated existing tests, and added new tests that can be unskipped once we implement parts that are intentionally not implemented yet
  • Manual database testing

Changelog

@cla-bot cla-bot bot added the cla-signed label Jul 1, 2024
@bahrmichael bahrmichael marked this pull request as ready for review July 1, 2024 11:13
Copy link
Contributor

@BolajiOlajide BolajiOlajide left a comment

Choose a reason for hiding this comment

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

A couple things to take care of here @bahrmichael

We should be good to merge soon.

&c.ExternalServiceID,
&encryptedCredential,
&keyID,
&dbutil.NullInt{N: &c.GitHubAppID},
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually want to use a NullInt here? In the case that GitHubAppID is null, it will set the ID to zero. Do we check everywhere we use it that the ID is non-zero? Personally, it feels more natural to use *int as an optional int.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can see, GitHubAppId will never be zero if it's set. Checking against a zero-value feels more golang to me than having a nullable value. We have checks in place already that the id has to be something else than 0 (internal/batches/types/site_credential.go). @BolajiOlajide what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, both approaches work. Considering GitHubAppID is a foreign key, there'd never be a zero value in the database, so this is pretty safe. I'd be more worried if it wasn't a foreign key.

}

func (uc *UserCredential) githubAppAuthenticator() (auth.Authenticator, error) {
return nil, errors.New("not implemented")
Copy link
Member

Choose a reason for hiding this comment

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

Will any batch changes have a github app associated with it by default when this PR is merged? Mostly, I just don't want us to merge this and start seeing "not implemented" errors unless someone tries to specifically opt in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With migrations/frontend/1719498091_add_github_app_id_user_credentials/up.sql and migrations/frontend/1719498032_add_github_app_batch_changes_site_credential/up.sql we introduce the new column, but don't set a value. Unless someone goes into the database and manually sets a value, there should never be one, and therefore no failure. I'm rather confident about this, and would prefer seeing a hard value on s2 if that assumption turns out to be false.

The implementation of this is going to be one of the immediate next steps, so it should never be rolled out to customers.

We prefer to ship this, so that we can base future work on it instead of piling up more work in one big PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup. Also to add, the UI implementation for this isn't done yet so there's no way for someone to add a GitHub app yet.

@BolajiOlajide BolajiOlajide merged commit fcff7a2 into main Jul 2, 2024
@BolajiOlajide BolajiOlajide deleted the 06-28-add_github_app_id_field_to_site_credential_struct branch July 2, 2024 11:12
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.

3 participants