-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
GitHub App: track extra metadata #12829
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Generated by Django 5.2.11 on 2026-03-04 23:02 | ||
|
|
||
| from django.db import migrations | ||
| from django.db import models | ||
| from django_safemigrate import Safe | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| safe = Safe.before_deploy() | ||
| dependencies = [ | ||
| ("oauth", "0018_githubapp"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="githubappinstallation", | ||
| name="all_repositories_selected", | ||
| field=models.BooleanField( | ||
| db_default=False, | ||
| default=False, | ||
| help_text="Whether the installation has access to all repositories or just some of them", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="githubappinstallation", | ||
| name="target_login", | ||
| field=models.CharField( | ||
| default="", | ||
| help_text="The account login the installation belongs to", | ||
| max_length=255, | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,14 +34,26 @@ def get_or_create_installation( | |
| Only the installation_id is unique, the target_id and target_type could change, | ||
| but this should never happen. | ||
| """ | ||
| extra_data = extra_data or {} | ||
| installation, created = self.get_or_create( | ||
| installation_id=installation_id, | ||
| defaults={ | ||
| "target_id": target_id, | ||
| "target_type": target_type, | ||
| "extra_data": extra_data or {}, | ||
| "extra_data": extra_data, | ||
| }, | ||
| ) | ||
|
|
||
| # Keep the extra data about the installation up to date. | ||
| new_installation_data = extra_data.get("installation", {}) | ||
| installation_has_changed = ( | ||
| new_installation_data | ||
| and new_installation_data != installation.extra_data.get("installation", {}) | ||
| ) | ||
| if not created and installation_has_changed: | ||
| installation.extra_data = extra_data | ||
| installation.save() | ||
|
|
||
| # NOTE: An installation can't change its target_id or target_type. | ||
| # This should never happen, unless this assumption is wrong. | ||
| if installation.target_id != target_id or installation.target_type != target_type: | ||
|
|
@@ -78,6 +90,17 @@ class GitHubAppInstallation(TimeStampedModel): | |
| choices=GitHubAccountType, | ||
| max_length=255, | ||
| ) | ||
| target_login = models.CharField( | ||
| help_text=_("The account login the installation belongs to"), | ||
| default="", | ||
| null=True, | ||
| max_length=255, | ||
| ) | ||
|
Comment on lines
+93
to
+97
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the options for this field?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the login of the user/organization.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't follow you.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the username of the user/organization. |
||
| all_repositories_selected = models.BooleanField( | ||
| help_text=_("Whether the installation has access to all repositories or just some of them"), | ||
| db_default=False, | ||
| default=False, | ||
| ) | ||
| extra_data = models.JSONField( | ||
| help_text=_("Extra data returned by the webhook when the installation is created"), | ||
| default=dict, | ||
|
|
@@ -173,6 +196,12 @@ def delete_organization(self, organization_id: int): | |
| target_type=self.target_type, | ||
| ) | ||
|
|
||
| def save(self, *args, **kwargs): | ||
| installation_data = self.extra_data.get("installation", {}) | ||
| self.target_login = installation_data.get("account", {}).get("login") | ||
| self.all_repositories_selected = installation_data.get("repository_selection") == "all" | ||
| super().save(*args, **kwargs) | ||
|
|
||
|
|
||
| class RemoteOrganization(TimeStampedModel): | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the
default=""so it usesNoneby default. Also add blank so we can define it from the admin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All objects in production will have this field populated after the data migration.