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

batches: save installation id on github apps install#52618

Merged
BolajiOlajide merged 2 commits into
batches/commit-signingfrom
bo/save-github-apps-installation-id
Jun 1, 2023
Merged

batches: save installation id on github apps install#52618
BolajiOlajide merged 2 commits into
batches/commit-signingfrom
bo/save-github-apps-installation-id

Conversation

@BolajiOlajide

Copy link
Copy Markdown
Contributor

This PR is a revert of 52136. It creates a github_app_installs table that tracks the installation of every GitHub app on the Sourcegraph instance.

Closes #52494

Test plan

  • Execute the latest migrations with the command sg migration up
  • Install a GitHub app via the GitHub apps page the attempt to install the app.
  • if the installation is successful, the installation ID will be saved in the installation_id column in the github_app_installs table.

@BolajiOlajide BolajiOlajide requested review from a team, kopancek and pjlast May 30, 2023 14:20
@BolajiOlajide BolajiOlajide self-assigned this May 30, 2023
@cla-bot cla-bot Bot added the cla-signed label May 30, 2023
@sourcegraph-bot

sourcegraph-bot commented May 30, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 046709c...aa79c78.

Notify File(s)
@unknwon enterprise/cmd/frontend/internal/auth/githubappauth/middleware.go

@sourcegraph-buildkite

Copy link
Copy Markdown
Collaborator

Bundle size report 📦

Initial size Total size Async size Modules
0.01% (+0.22 kb) 0.00% (+0.65 kb) 0.00% (+0.43 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 05884be and 9ee59be or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@sourcegraph-bot

sourcegraph-bot commented May 30, 2023

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@BolajiOlajide BolajiOlajide changed the title batches: Add domain column to github_apps migration (#52332) batches: save installation ids on github apps install May 30, 2023
@BolajiOlajide BolajiOlajide changed the title batches: save installation ids on github apps install batches: save installation id on github apps install May 30, 2023

@courier-new courier-new left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this! The revert looks good, but two comments:

  1. I know it's possible to uninstall an App from the GitHub side, so the opportunity exists for SG and GH to get out of sync with each other when that happens. Are we concerned about that happening at all? I guess worst case it might lead to semi-cryptic auth error messages surfacing in the UI? This could be in a follow up PR, but I'm wondering if it makes sense to setup a very simple cron-like background worker that once every [day? hour?] refetches that list of installations from the GitHub API and makes sure that whatever we have in the DB matches. This serves a secondary purpose, which is...
  2. Even if the repo syncing GH Apps don't rely on the installation IDs being set in the DB, we probably ought to backfill them for completeness. The background worker I suggested would take care of that automatically, but if we decide not to proceed with that plan then we'll want to do something else to address this.

@BolajiOlajide

Copy link
Copy Markdown
Contributor Author

Thanks for this! The revert looks good, but two comments:

  1. I know it's possible to uninstall an App from the GitHub side, so the opportunity exists for SG and GH to get out of sync with each other when that happens. Are we concerned about that happening at all? I guess worst case it might lead to semi-cryptic auth error messages surfacing in the UI? This could be in a follow up PR, but I'm wondering if it makes sense to setup a very simple cron-like background worker that once every [day? hour?] refetches that list of installations from the GitHub API and makes sure that whatever we have in the DB matches. This serves a secondary purpose, which is...
  2. Even if the repo syncing GH Apps don't rely on the installation IDs being set in the DB, we probably ought to backfill them for completeness. The background worker I suggested would take care of that automatically, but if we decide not to proceed with that plan then we'll want to do something else to address this.

#52648 takes care of that.

@BolajiOlajide BolajiOlajide force-pushed the bo/save-github-apps-installation-id branch from 05884be to aa79c78 Compare June 1, 2023 17:29
@BolajiOlajide BolajiOlajide linked an issue Jun 1, 2023 that may be closed by this pull request
@BolajiOlajide BolajiOlajide merged commit 284027d into batches/commit-signing Jun 1, 2023
@BolajiOlajide BolajiOlajide deleted the bo/save-github-apps-installation-id branch June 1, 2023 17:48
BolajiOlajide added a commit that referenced this pull request Jun 9, 2023
This PR introduces a background worker that runs every 24 hours. This background worker adds data for new installations of a GitHub app to the database and removes installations that no longer exist on GitHub.

This ensures that Sourcegraph has some level of sync consistency with GitHub.

## Test plan

<!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles -->
* Create a GitHub app and ensure the installation information isn't saved in the database. If you have pre-existing apps before the introduction of #52618 then you already have GitHub apps without installation data saved.
* Starting your SG instance instantiates a background worker that'll backfill the installation information and save it in the `github_app_installs`  table.
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.

Save installation ID for GitHub Apps

4 participants