Skip to content

Commit

Permalink
fix(scm): correct init hook status and send accurate events (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Apr 21, 2023
1 parent 519876b commit 0410ae0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,18 @@ func CreateRepo(c *gin.Context) {
}

h := new(library.Hook)

// err being nil means we have a record of this repo (dbRepo)
if err == nil {
h, _ = database.FromContext(c).LastHookForRepo(dbRepo)

// make sure our record of the repo allowed events matches what we send to SCM
// what the dbRepo has should override default events on enable
r.SetAllowComment(dbRepo.GetAllowComment())
r.SetAllowDeploy(dbRepo.GetAllowDeploy())
r.SetAllowPull(dbRepo.GetAllowPull())
r.SetAllowPush(dbRepo.GetAllowPush())
r.SetAllowTag(dbRepo.GetAllowTag())
}

// check if we should create the webhook
Expand Down
1 change: 1 addition & 0 deletions scm/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func (c *client) Enable(u *library.User, r *library.Repo, h *library.Hook) (*lib
webhook.SetCreated(hookInfo.GetCreatedAt().Unix())
webhook.SetEvent(eventInitialize)
webhook.SetNumber(h.GetNumber() + 1)
webhook.SetStatus(constants.StatusSuccess)

switch resp.StatusCode {
case http.StatusUnprocessableEntity:
Expand Down
1 change: 1 addition & 0 deletions scm/github/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ func TestGithub_Enable(t *testing.T) {
wantHook.SetCreated(1315329987)
wantHook.SetNumber(1)
wantHook.SetEvent("initialize")
wantHook.SetStatus("success")

r := new(library.Repo)
r.SetID(1)
Expand Down

0 comments on commit 0410ae0

Please sign in to comment.