From 0410ae0e53931d134fe0fcb1e5f5d936898c5d0c Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Fri, 21 Apr 2023 11:32:16 -0600 Subject: [PATCH] fix(scm): correct init hook status and send accurate events (#825) --- api/repo/create.go | 10 ++++++++++ scm/github/repo.go | 1 + scm/github/repo_test.go | 1 + 3 files changed, 12 insertions(+) diff --git a/api/repo/create.go b/api/repo/create.go index 295fe2b74..d196c2a48 100644 --- a/api/repo/create.go +++ b/api/repo/create.go @@ -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 diff --git a/scm/github/repo.go b/scm/github/repo.go index 7ecd53341..13bd1cc1d 100644 --- a/scm/github/repo.go +++ b/scm/github/repo.go @@ -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: diff --git a/scm/github/repo_test.go b/scm/github/repo_test.go index 9f95fb12a..3dba1bac3 100644 --- a/scm/github/repo_test.go +++ b/scm/github/repo_test.go @@ -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)