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

bug(repo sync): ignore inactive repos #953

Merged
merged 14 commits into from
Sep 7, 2023
Merged

bug(repo sync): ignore inactive repos #953

merged 14 commits into from
Sep 7, 2023

Conversation

KellyMerrick
Copy link
Contributor

@KellyMerrick KellyMerrick commented Sep 1, 2023

This closes go-vela/community#852.

Add bool to track if webhook has been deleted from SCM:

server/scm/github/repo.go

Lines 263 to 274 in f89e929

// track if webhook cannot be captured from GitHub (no longer found),
// indicating the webhook has been manually deleted from GitHub
isWebhookDel := false
if resp.StatusCode == http.StatusNotFound {
isWebhookDel = true
}
if err != nil {
return isWebhookDel, err
}
return isWebhookDel, nil

And then update status to inactive in the database:

server/api/scm/sync_org.go

Lines 140 to 164 in f89e929

// update webhook
isWebhookDel, err := scm.FromContext(c).Update(u, repo, lastHook.GetWebhookID())
if err != nil {
retErr := fmt.Errorf("unable to update repo webhook for %s: %w", repo.GetFullName(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)
// if webhook has been manually deleted from GitHub,
// set to inactive in database
if isWebhookDel {
repo.SetActive(false)
_, err := database.FromContext(c).UpdateRepo(ctx, repo)
if err != nil {
retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err)
util.HandleError(c, http.StatusInternalServerError, retErr)
return
}
}
return
}

@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Merging #953 (08a7db6) into main (0464cb5) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #953      +/-   ##
==========================================
+ Coverage   70.95%   70.97%   +0.02%     
==========================================
  Files         312      312              
  Lines       12923    12922       -1     
==========================================
+ Hits         9170     9172       +2     
+ Misses       3287     3285       -2     
+ Partials      466      465       -1     
Files Changed Coverage Δ
scm/github/repo.go 76.99% <100.00%> (+0.64%) ⬆️

📢 Have feedback on the report? Share it here.

@KellyMerrick KellyMerrick self-assigned this Sep 6, 2023
@KellyMerrick KellyMerrick marked this pull request as ready for review September 6, 2023 20:44
@KellyMerrick KellyMerrick requested a review from a team as a code owner September 6, 2023 20:44
api/scm/sync.go Outdated Show resolved Hide resolved
scm/github/repo.go Outdated Show resolved Hide resolved
api/scm/sync.go Outdated Show resolved Hide resolved
api/scm/sync_org.go Outdated Show resolved Hide resolved
api/scm/sync_org.go Show resolved Hide resolved
scm/github/repo.go Outdated Show resolved Hide resolved
ecrupper
ecrupper previously approved these changes Sep 7, 2023
wass3rw3rk
wass3rw3rk previously approved these changes Sep 7, 2023
ecrupper
ecrupper previously approved these changes Sep 7, 2023
wass3r
wass3r previously approved these changes Sep 7, 2023
scm/github/repo.go Outdated Show resolved Hide resolved
@KellyMerrick KellyMerrick dismissed stale reviews from wass3r and ecrupper via 08a7db6 September 7, 2023 19:24
@KellyMerrick KellyMerrick merged commit bb79525 into main Sep 7, 2023
11 checks passed
@KellyMerrick KellyMerrick deleted the bug/repo_sync branch September 7, 2023 19:29
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.

Repos with manually deleted hooks should be handled appropriately in the database and via vela sync command
4 participants