Skip to content

Commit

Permalink
fix(webhook): keep parent and build number synced (#936)
Browse files Browse the repository at this point in the history
* fix(webhook): keep parent and build number synced

currently, build number is always +1 to parent.
for any new hooks coming in, parent and build number should be in sync.

build restarts are the only instance where these should diverge
to indicate which build was restarted.

* enhance: use replaceall

* forgot to include change in hunk

* do not set parent build number

* revert comment change

---------

Co-authored-by: Easton Crupper <65553218+ecrupper@users.noreply.github.com>
Co-authored-by: wass3rw3rk <49894298+wass3rw3rk@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent 6a15df6 commit 236eb9e
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,6 @@ func PostWebhook(c *gin.Context) {
logrus.Debugf("updating build number to %d", repo.GetCounter())
b.SetNumber(repo.GetCounter())

logrus.Debugf("updating parent number to %d", b.GetNumber())
b.SetParent(b.GetNumber())

logrus.Debug("updating status to pending")
b.SetStatus(constants.StatusPending)

Expand All @@ -362,7 +359,7 @@ func PostWebhook(c *gin.Context) {
}

b.SetCommit(commit)
b.SetBranch(strings.Replace(branch, "refs/heads/", "", -1))
b.SetBranch(strings.ReplaceAll(branch, "refs/heads/", ""))
b.SetBaseRef(baseref)
b.SetHeadRef(headref)
}
Expand Down Expand Up @@ -470,15 +467,6 @@ func PostWebhook(c *gin.Context) {
repo.SetTopics(r.GetTopics())
repo.SetBranch(r.GetBranch())

// set the parent equal to the current repo counter
b.SetParent(repo.GetCounter())

// check if the parent is set to 0
if b.GetParent() == 0 {
// parent should be "1" if it's the first build ran
b.SetParent(1)
}

// update the build numbers based off repo counter
inc := repo.GetCounter() + 1
repo.SetCounter(inc)
Expand Down

0 comments on commit 236eb9e

Please sign in to comment.