Skip to content

Commit

Permalink
making things normal
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Dec 28, 2023
1 parent 1956de7 commit 1c27ef6
Show file tree
Hide file tree
Showing 21 changed files with 11 additions and 188 deletions.
1 change: 0 additions & 1 deletion api/build/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func CreateBuild(c *gin.Context) {
// verify the build has a valid event and the repo allows that event type
if (input.GetEvent() == constants.EventPush && !r.GetAllowPush()) ||
(input.GetEvent() == constants.EventPull && !r.GetAllowPull()) ||
(input.GetEvent() == constants.EventDelete && !r.GetAllowDelete()) ||
(input.GetEvent() == constants.EventTag && !r.GetAllowTag()) ||
(input.GetEvent() == constants.EventDeploy && !r.GetAllowDeploy()) {
retErr := fmt.Errorf("unable to create new build: %s does not have %s events enabled", r.GetFullName(), input.GetEvent())
Expand Down
6 changes: 1 addition & 5 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,13 @@ func CreateRepo(c *gin.Context) {
// set default events if no events are passed in
if !input.GetAllowPull() && !input.GetAllowPush() &&
!input.GetAllowDeploy() && !input.GetAllowTag() &&
!input.GetAllowComment() && !input.GetAllowDelete() {
!input.GetAllowComment() {
for _, event := range defaultRepoEvents {
switch event {
case constants.EventPull:
r.SetAllowPull(true)
case constants.EventPush:
r.SetAllowPush(true)
case constants.EventDelete:
r.SetAllowDelete(true)
case constants.EventDeploy:
r.SetAllowDeploy(true)
case constants.EventTag:
Expand All @@ -195,7 +193,6 @@ func CreateRepo(c *gin.Context) {
r.SetAllowDeploy(input.GetAllowDeploy())
r.SetAllowPull(input.GetAllowPull())
r.SetAllowPush(input.GetAllowPush())
r.SetAllowDelete(input.GetAllowDelete())
r.SetAllowTag(input.GetAllowTag())
}
// -- END DEPRECATED SECTION --
Expand Down Expand Up @@ -269,7 +266,6 @@ func CreateRepo(c *gin.Context) {
r.SetAllowDeploy(dbRepo.GetAllowDeploy())
r.SetAllowPull(dbRepo.GetAllowPull())
r.SetAllowPush(dbRepo.GetAllowPush())
r.SetAllowDelete(dbRepo.GetAllowDelete())
r.SetAllowTag(dbRepo.GetAllowTag())
}

Expand Down
10 changes: 1 addition & 9 deletions api/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@ func UpdateRepo(c *gin.Context) {
eventsChanged = true
}

if input.AllowDelete != nil {
// update allow_delete if set
r.SetAllowDelete(input.GetAllowDelete())

eventsChanged = true
}

if input.AllowDeploy != nil {
// update allow_deploy if set
r.SetAllowDeploy(input.GetAllowDeploy())
Expand All @@ -225,10 +218,9 @@ func UpdateRepo(c *gin.Context) {
// set default events if no events are enabled
if !r.GetAllowPull() && !r.GetAllowPush() &&
!r.GetAllowDeploy() && !r.GetAllowTag() &&
!r.GetAllowComment() && !r.GetAllowDelete() {
!r.GetAllowComment() {
r.SetAllowPull(true)
r.SetAllowPush(true)
r.SetAllowDelete(true)
}
// -- END DEPRECATED SECTION --

Expand Down
20 changes: 1 addition & 19 deletions api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,30 +365,12 @@ func PostWebhook(c *gin.Context) {
b.SetHeadRef(headref)
}

if strings.EqualFold(b.GetEvent(), constants.EventDelete) {
// send API call to capture the commit sha for the branch
_, commit, err := scm.FromContext(c).GetBranch(u, r)
if err != nil {
retErr := fmt.Errorf("failed to get commit for repo %s on %s branch: %w", r.GetFullName(), r.GetBranch(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)

h.SetStatus(constants.StatusFailure)
h.SetError(retErr.Error())

return
}

b.SetCommit(commit)
b.SetRef(r.GetBranch())
}

// variable to store changeset files
var files []string

// check if the build event is not issue_comment or pull_request
if !strings.EqualFold(b.GetEvent(), constants.EventComment) &&
!strings.EqualFold(b.GetEvent(), constants.EventPull) &&
!strings.EqualFold(b.GetEvent(), constants.EventDelete) {
!strings.EqualFold(b.GetEvent(), constants.EventPull) {
// send API call to capture list of files changed for the commit
files, err = scm.FromContext(c).Changeset(ctx, u, repo, b.GetCommit())
if err != nil {
Expand Down
22 changes: 8 additions & 14 deletions compiler/native/environment_test.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion database/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ func testRepo() *library.Repo {
Active: new(bool),
AllowPull: new(bool),
AllowPush: new(bool),
AllowDelete: new(bool),
AllowDeploy: new(bool),
AllowTag: new(bool),
AllowComment: new(bool),
Expand Down
1 change: 0 additions & 1 deletion database/hook/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ func testRepo() *library.Repo {
Active: new(bool),
AllowPull: new(bool),
AllowPush: new(bool),
AllowDelete: new(bool),
AllowDeploy: new(bool),
AllowTag: new(bool),
AllowComment: new(bool),
Expand Down
2 changes: 0 additions & 2 deletions database/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,6 @@ func newResources() *Resources {
repoOne.SetActive(true)
repoOne.SetAllowPull(false)
repoOne.SetAllowPush(true)
repoOne.SetAllowDelete(true)
repoOne.SetAllowDeploy(false)
repoOne.SetAllowTag(false)
repoOne.SetAllowComment(false)
Expand Down Expand Up @@ -2150,7 +2149,6 @@ func newResources() *Resources {
repoTwo.SetActive(true)
repoTwo.SetAllowPull(false)
repoTwo.SetAllowPush(true)
repoTwo.SetAllowDelete(true)
repoTwo.SetAllowDeploy(false)
repoTwo.SetAllowTag(false)
repoTwo.SetAllowComment(false)
Expand Down
1 change: 0 additions & 1 deletion database/repo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ func testRepo() *library.Repo {
Active: new(bool),
AllowPull: new(bool),
AllowPush: new(bool),
AllowDelete: new(bool),
AllowDeploy: new(bool),
AllowTag: new(bool),
AllowComment: new(bool),
Expand Down
2 changes: 0 additions & 2 deletions database/repo/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ repos (
active BOOLEAN,
allow_pull BOOLEAN,
allow_push BOOLEAN,
allow_delete BOOLEAN,
allow_deploy BOOLEAN,
allow_tag BOOLEAN,
allow_comment BOOLEAN,
Expand Down Expand Up @@ -69,7 +68,6 @@ repos (
active BOOLEAN,
allow_pull BOOLEAN,
allow_push BOOLEAN,
allow_delete BOOLEAN,
allow_deploy BOOLEAN,
allow_tag BOOLEAN,
allow_comment BOOLEAN,
Expand Down
1 change: 0 additions & 1 deletion database/schedule/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func testRepo() *library.Repo {
Active: new(bool),
AllowPull: new(bool),
AllowPush: new(bool),
AllowDelete: new(bool),
AllowDeploy: new(bool),
AllowTag: new(bool),
AllowComment: new(bool),
Expand Down
1 change: 0 additions & 1 deletion database/secret/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func testRepo() *library.Repo {
Active: new(bool),
AllowPull: new(bool),
AllowPush: new(bool),
AllowDelete: new(bool),
AllowDeploy: new(bool),
AllowTag: new(bool),
AllowComment: new(bool),
Expand Down
3 changes: 0 additions & 3 deletions mock/server/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const (
"active": true,
"allow_pr": false,
"allow_push": true,
"allow_delete": true,
"allow_deploy": false,
"allow_tag": false
}`
Expand All @@ -56,7 +55,6 @@ const (
"active": true,
"allow_pr": false,
"allow_push": true,
"allow_delete": true,
"allow_deploy": false,
"allow_tag": false
},
Expand All @@ -77,7 +75,6 @@ const (
"active": true,
"allow_pr": false,
"allow_push": true,
"allow_delete": true,
"allow_deploy": false,
"allow_tag": false
}
Expand Down
3 changes: 0 additions & 3 deletions mock/server/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
"active": true,
"allow_pull": false,
"allow_push": true,
"allow_delete": true,
"allow_deploy": false,
"allow_tag": false,
"allow_comment": false,
Expand Down Expand Up @@ -82,7 +81,6 @@ const (
"active": true,
"allow_pull": false,
"allow_push": true,
"allow_delete": true,
"allow_deploy": false,
"allow_tag": false,
"allow_comment": false,
Expand Down Expand Up @@ -119,7 +117,6 @@ const (
"active": true,
"allow_pull": false,
"allow_push": true,
"allow_delete": true,
"allow_deploy": false,
"allow_tag": false,
"allow_comment": false,
Expand Down
1 change: 0 additions & 1 deletion queue/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ var (
Active: Bool(true),
AllowPull: Bool(false),
AllowPush: Bool(true),
AllowDelete: Bool(true),
AllowDeploy: Bool(false),
AllowTag: Bool(false),
}
Expand Down
1 change: 0 additions & 1 deletion router/middleware/org/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestOrg_Establish(t *testing.T) {
r.SetActive(false)
r.SetAllowPull(false)
r.SetAllowPush(false)
r.SetAllowDelete(false)
r.SetAllowDeploy(false)
r.SetAllowTag(false)
r.SetAllowComment(false)
Expand Down
1 change: 0 additions & 1 deletion router/middleware/repo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestRepo_Establish(t *testing.T) {
want.SetActive(false)
want.SetAllowPull(false)
want.SetAllowPush(false)
want.SetAllowDelete(false)
want.SetAllowDeploy(false)
want.SetAllowTag(false)
want.SetAllowComment(false)
Expand Down
1 change: 0 additions & 1 deletion scm/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const (
// events for repo webhooks.
eventPush = "push"
eventPullRequest = "pull_request"
eventDelete = "delete"
eventDeployment = "deployment"
eventIssueComment = "issue_comment"
eventRepository = "repository"
Expand Down
2 changes: 0 additions & 2 deletions scm/github/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ func TestGithub_Enable(t *testing.T) {
r.SetHash("secret")
r.SetAllowPush(true)
r.SetAllowPull(true)
r.SetAllowDelete(true)
r.SetAllowDeploy(true)

client, _ := NewTest(s.URL)
Expand Down Expand Up @@ -666,7 +665,6 @@ func TestGithub_Update(t *testing.T) {
r.SetHash("secret")
r.SetAllowPush(true)
r.SetAllowPull(true)
r.SetAllowDelete(true)
r.SetAllowDeploy(true)

hookID := int64(1)
Expand Down
47 changes: 0 additions & 47 deletions scm/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ func (c *client) ProcessWebhook(ctx context.Context, request *http.Request) (*ty
case *github.PullRequestEvent:
c.Logger.Tracef("pull")
return c.processPREvent(h, event)
case *github.DeleteEvent:
c.Logger.Tracef("help me please dear lord")
return c.processDeleteEvent(h, event)
case *github.DeploymentEvent:
c.Logger.Tracef("deployment")
return c.processDeploymentEvent(h, event)
Expand Down Expand Up @@ -301,50 +298,6 @@ func (c *client) processPREvent(h *library.Hook, payload *github.PullRequestEven
}, nil
}

func (c *client) processDeleteEvent(h *library.Hook, payload *github.DeleteEvent) (*types.Webhook, error) {
c.Logger.WithFields(logrus.Fields{
"org": payload.GetRepo().GetOwner().GetLogin(),
"repo": payload.GetRepo().GetName(),
}).Tracef("processing delete GitHub webhook for %s", payload.GetRepo().GetFullName())

// capture the repo from the payload
repo := payload.GetRepo()

// convert payload to library repo
r := new(library.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
r.SetFullName(repo.GetFullName())
r.SetLink(repo.GetHTMLURL())
r.SetClone(repo.GetCloneURL())
r.SetBranch(repo.GetDefaultBranch())
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)

// convert payload to library build
b := new(library.Build)
b.SetEvent(constants.EventDelete)
b.SetClone(repo.GetCloneURL())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventDelete, repo.GetHTMLURL()))
b.SetSender(payload.GetSender().GetLogin())
b.SetBranch(strings.TrimPrefix(payload.GetRef(), "refs/heads/"))
b.SetRef(payload.GetRef())
b.SetMessage(fmt.Sprintf("Branch %s deleted", b.GetBranch()))

// update the hook object
h.SetBranch(b.GetBranch())
h.SetEvent(constants.EventDelete)
h.SetLink(
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), r.GetFullName()),
)

return &types.Webhook{
Hook: h,
Repo: r,
Build: b,
}, nil
}

// processDeploymentEvent is a helper function to process the deployment event.
func (c *client) processDeploymentEvent(h *library.Hook, payload *github.DeploymentEvent) (*types.Webhook, error) {
c.Logger.WithFields(logrus.Fields{
Expand Down
Loading

0 comments on commit 1c27ef6

Please sign in to comment.