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

feat: extend ConnitNotification #225

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ In order to run tests from within your docker container, run:
make test
```

## Running migrations

If you make changes to the models in `shared/django_apps/` you will need to create migrations to reflect those changes in the database.

Make sure the shared container is running and shell into it
```bash
$ docker compose up
$ docker compose exec -it shared /bin/bash
```

Now you can create a migration (from within the container)

```bash
$ cd shared/django_apps/
$ python manage.py makemigrations
```

To learn more about migrations visit [Django Docs](https://docs.djangoproject.com/en/5.0/topics/migrations/)

## Managing shared dependencies

As a normal python package, `shared` can include dependencies of its own.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 4.2.13 on 2024-05-21 19:33

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("codecov_auth", "0055_session_login_session"),
("core", "0049_increment_version"),
]

# BEGIN;
# --
# -- Add field gh_app to commitnotification
# --
# ALTER TABLE "commit_notifications" ADD COLUMN "gh_app_id" bigint NULL CONSTRAINT "commit_notifications_gh_app_id_8714fedd_fk_codecov_a" REFERENCES "codecov_auth_githubappinstallation"("id") DEFERRABLE INITIALLY DEFERRED; SET CONSTRAINTS "commit_notifications_gh_app_id_8714fedd_fk_codecov_a" IMMEDIATE;
# --
# -- Alter field notification_type on commitnotification
# --
# -- (no-op)
# CREATE INDEX "commit_notifications_gh_app_id_8714fedd" ON "commit_notifications" ("gh_app_id");
# COMMIT;

operations = [
migrations.AddField(
model_name="commitnotification",
name="gh_app",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="commit_notifications",
to="codecov_auth.githubappinstallation",
),
),
migrations.AlterField(
model_name="commitnotification",
name="notification_type",
field=models.TextField(
choices=[
("comment", "Comment"),
("gitter", "Gitter"),
("hipchat", "Hipchat"),
("irc", "Irc"),
("slack", "Slack"),
("status_changes", "Status Changes"),
("status_patch", "Status Patch"),
("status_project", "Status Project"),
("webhook", "Webhook"),
("codecov_slack_app", "Codecov Slack App"),
("checks_project", "Checks Project"),
("checks_changes", "Checks Changes"),
("checks_patch", "Checks Patch"),
]
),
),
]
9 changes: 9 additions & 0 deletions shared/django_apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ class NotificationTypes(models.TextChoices):
STATUS_PROJECT = "status_project"
WEBHOOK = "webhook"
CODECOV_SLACK_APP = "codecov_slack_app"
CHECKS_PROJECT = "checks_project"
CHECKS_CHANGES = "checks_changes"
CHECKS_PATCH = "checks_patch"

class DecorationTypes(models.TextChoices):
STANDARD = "standard"
Expand All @@ -468,6 +471,12 @@ class States(models.TextChoices):
commit = models.ForeignKey(
"core.Commit", on_delete=models.CASCADE, related_name="notifications"
)
gh_app = models.ForeignKey(
"codecov_auth.GithubAppInstallation",
on_delete=models.CASCADE,
related_name="commit_notifications",
null=True,
)
notification_type = models.TextField(
choices=NotificationTypes.choices
) # Really an ENUM in db
Expand Down
1 change: 1 addition & 0 deletions shared/typings/torngit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RepoInfo(TypedDict):
class GithubInstallationInfo(TypedDict):
"""Required info to get a token from Github for a given installation"""

id: int
installation_id: int
# The default app (configured via yaml) doesn't need this info.
# All other apps need app_id and pem_path
Expand Down
Loading