@@ -29,6 +29,13 @@ var buildkitdConfig = map[string]map[string]map[string][]string{
2929 },
3030}
3131
32+ const (
33+ ClosedPRStatus = "closed"
34+ MergedPRStatus = "merged"
35+ OpenPRStatus = "open"
36+ CreatedPRStatus = "created"
37+ )
38+
3239// define a struct named Build
3340type Build struct {
3441 Appname string
@@ -255,18 +262,21 @@ func (b *Build) ImageName() (string, error) {
255262
256263func (b * Build ) NewPRStatus () string {
257264 if b .CreateReviewApp {
258- return "created"
265+ return CreatedPRStatus
259266 }
260267 if b .CodebuildWebhookEvent == "PULL_REQUEST_CREATED" || b .CodebuildWebhookEvent == "PULL_REQUEST_REOPENED" {
261- return "open"
268+ return OpenPRStatus
262269 }
263270 if b .CodebuildWebhookEvent == "PULL_REQUEST_MERGED" {
264- return "merged"
271+ return MergedPRStatus
272+ }
273+ if b .CodebuildWebhookEvent == "PULL_REQUEST_CLOSED" {
274+ return ClosedPRStatus
265275 }
266276 _ , err := b .GetPRStatus ()
267277 if err != nil {
268278 b .Log ().Debug ().Err (err ).Msg ("failed to get PR status" )
269- return "open"
279+ return OpenPRStatus
270280 }
271281 return ""
272282}
@@ -280,7 +290,7 @@ func (b *Build) HandlePR() (bool, error) {
280290 }
281291 newStatus := b .NewPRStatus ()
282292 b .Log ().Debug ().Str ("status" , newStatus ).Msg ("PR status" )
283- if newStatus == "merged" {
293+ if newStatus == MergedPRStatus || newStatus == ClosedPRStatus {
284294 hasReviewApp , err := b .ReviewAppStackExists ()
285295 // TODO err is ignored because it usually means the stack doesn't exist
286296 if err != nil {
@@ -310,7 +320,7 @@ func (b *Build) HandlePR() (bool, error) {
310320 return false , err
311321 }
312322 }
313- if status .Status != "created" {
323+ if status .Status != CreatedPRStatus {
314324 err = b .SkipBuild ()
315325 return true , err
316326 }
0 commit comments