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

Track whether GitHub App is installed on org #2947

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

eleftherias
Copy link
Member

Summary

In preparation for https://github.com/stacklok/epics/issues/280, we need to know whether an app was installed on an organization or a personal user account, to know which API to call.
This adds an isOrg column to the installations DB table, similar to what we have for access tokens.

Note: I don't think keeping track of the owner / org in the credentials is the right place. Eventually it could move to a GitHub metadata table that is specific to GitHub providers. This warrants further discussion and a design document. For now, I've followed the same pattern we're already using for access tokens.

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@eleftherias eleftherias requested a review from a team as a code owner April 4, 2024 19:37
@JAORMX
Copy link
Contributor

JAORMX commented Apr 4, 2024

I agree it should be a provider setting and not this, but oh well.

@evankanderson
Copy link
Member

I seem to recall that some (many?) of the GitHub operations had endpoints that worked for both users and orgs. I'm assuming that packages aren't one of those endpoints, given the other limitations. 😢


BEGIN;

ALTER TABLE provider_github_app_installations RENAME COLUMN organization_id TO owner_id;
Copy link
Member

Choose a reason for hiding this comment

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

So, renaming a column like this will cause a brief outage between the migration apply and the updated code.

I'm not sure we need to worry about this yet, but it feels like the safer thing to do would be to add a new column (owner_id) and copy all the values (possibly with a default) into it if we need to change the name.

I'm not blocking this PR, but I'd like us to start thinking more about how to make sure our migrations are downtime-free given that we've had a few misses in the last month.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I can remove the rename, it's not necessary.

BEGIN;

ALTER TABLE provider_github_app_installations RENAME COLUMN organization_id TO owner_id;
ALTER TABLE provider_github_app_installations ADD COLUMN is_org BOOLEAN NOT NULL DEFAULT FALSE;
Copy link
Member

Choose a reason for hiding this comment

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

This looks safe to me because the default should apply for existing binaries that don't know about the column, allowing them to pass the NOT NULL constraint.

@eleftherias
Copy link
Member Author

I seem to recall that some (many?) of the GitHub operations had endpoints that worked for both users and orgs. I'm assuming that packages aren't one of those endpoints, given the other limitations.

That's right. Packages only have per-user or per-org endpoints.

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

The code makes sense to me and I think @evankanderson 's suggestions have been addressed. I think this PR is ready to be approved once rebased.

@@ -58,6 +58,9 @@ type ProviderService interface {
DeleteProvider(ctx context.Context, provider *db.Provider) error
}

// TypeGitHubOrganization is the type returned from the GitHub API when the owner is an organization
const TypeGitHubOrganization = "Organization"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: doesn't have to be exported
(not needed in this PR even if you agree the const doesn't have to be exported)

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

I think the code is good now and all the tests failures are a result of github having a bad day.

@eleftherias eleftherias merged commit 9e8dc84 into stacklok:main Apr 5, 2024
19 of 20 checks passed
@eleftherias eleftherias deleted the is-org-github-app branch April 5, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants