Skip to content

Commit

Permalink
fix: remove install_id when app is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 22, 2024
1 parent c1197eb commit f9e7d77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scm/github/installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func (c *client) ProcessInstallation(ctx context.Context, request *http.Request,

errs := []error{}

// if action is "deleted" then the RepositoriesAdded field will indicate the repositories that
// need to have install_id set to zero

// set install_id for repos added to the installation
for _, repo := range webhook.Installation.RepositoriesAdded {
r, err := db.GetRepoForOrg(ctx, webhook.Installation.Org, repo)
Expand All @@ -34,7 +37,14 @@ func (c *client) ProcessInstallation(ctx context.Context, request *http.Request,
continue
}

err = updateRepoInstallationID(ctx, webhook, r, db, webhook.Installation.ID)
installID := webhook.Installation.ID

// clear install_id if the installation is deleted
if webhook.Installation.Action == "deleted" {
installID = 0
}

err = updateRepoInstallationID(ctx, webhook, r, db, installID)
if err != nil {
errs = append(errs, err)
}
Expand Down
2 changes: 2 additions & 0 deletions scm/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ func (c *client) processRepositoryEvent(h *api.Hook, payload *github.RepositoryE
}, nil
}

// processInstallationEvent is a helper function to process the installation event.
func (c *client) processInstallationEvent(ctx context.Context, h *api.Hook, payload *github.InstallationEvent) (*internal.Webhook, error) {
h.SetEvent(constants.EventRepository)
h.SetEventAction(payload.GetAction())
Expand All @@ -563,6 +564,7 @@ func (c *client) processInstallationEvent(ctx context.Context, h *api.Hook, payl
}, nil
}

// processInstallationRepositoriesEvent is a helper function to process the installation repositories event.
func (c *client) processInstallationRepositoriesEvent(ctx context.Context, h *api.Hook, payload *github.InstallationRepositoriesEvent) (*internal.Webhook, error) {
install := new(internal.Installation)

Expand Down

0 comments on commit f9e7d77

Please sign in to comment.