@@ -6,16 +6,6 @@ import (
6
6
"encoding/json"
7
7
"errors"
8
8
"fmt"
9
- "log"
10
- "math/rand"
11
- "net/http"
12
- "net/url"
13
- "os"
14
- "path"
15
- "reflect"
16
- "strconv"
17
- "strings"
18
-
19
9
"github.com/diggerhq/digger/backend/ci_backends"
20
10
"github.com/diggerhq/digger/backend/locking"
21
11
"github.com/diggerhq/digger/backend/segment"
@@ -27,6 +17,15 @@ import (
27
17
orchestrator_scheduler "github.com/diggerhq/digger/libs/scheduler"
28
18
"github.com/google/uuid"
29
19
"gorm.io/gorm"
20
+ "log"
21
+ "math/rand"
22
+ "net/http"
23
+ "net/url"
24
+ "os"
25
+ "path"
26
+ "reflect"
27
+ "strconv"
28
+ "strings"
30
29
31
30
"github.com/diggerhq/digger/backend/middleware"
32
31
"github.com/diggerhq/digger/backend/models"
@@ -96,35 +95,16 @@ func (d DiggerController) GithubAppWebHook(c *gin.Context) {
96
95
c .String (http .StatusOK , "OK" )
97
96
return
98
97
}
99
- err = handleIssueCommentEvent (gh , event , d .CiBackendProvider , appId64 )
100
- if err != nil {
101
- log .Printf ("handleIssueCommentEvent error: %v" , err )
102
- c .String (http .StatusAccepted , err .Error ())
103
- return
104
- }
105
-
106
- log .Printf ("executing issue comment event post hooks:" )
107
- for _ , hook := range d .GithubWebhookPostIssueCommentHooks {
108
- err := hook (gh , event , d .CiBackendProvider )
109
- if err != nil {
110
- log .Printf ("handleIssueCommentEvent post hook error: %v" , err )
111
- c .String (http .StatusAccepted , err .Error ())
112
- return
113
- }
114
- }
98
+ handleIssueCommentEvent (gh , event , d .CiBackendProvider , appId64 , d .GithubWebhookPostIssueCommentHooks )
115
99
case * github.PullRequestEvent :
116
100
log .Printf ("Got pull request event for %d" , * event .PullRequest .ID )
117
- err = handlePullRequestEvent (gh , event , d .CiBackendProvider , appId64 )
118
- if err != nil {
119
- log .Printf ("handlePullRequestEvent error: %v" , err )
120
- c .String (http .StatusAccepted , err .Error ())
121
- return
122
- }
101
+ // run it as a goroutine to avoid timeouts
102
+ go handlePullRequestEvent (gh , event , d .CiBackendProvider , appId64 )
123
103
default :
124
104
log .Printf ("Unhandled event, event type %v" , reflect .TypeOf (event ))
125
105
}
126
106
127
- c .JSON (200 , "ok" )
107
+ c .JSON (http . StatusAccepted , "ok" )
128
108
}
129
109
130
110
func GithubAppSetup (c * gin.Context ) {
@@ -641,7 +621,7 @@ func getBatchType(jobs []orchestrator_scheduler.Job) orchestrator_scheduler.Digg
641
621
}
642
622
}
643
623
644
- func handleIssueCommentEvent (gh utils.GithubClientProvider , payload * github.IssueCommentEvent , ciBackendProvider ci_backends.CiBackendProvider , appId int64 ) error {
624
+ func handleIssueCommentEvent (gh utils.GithubClientProvider , payload * github.IssueCommentEvent , ciBackendProvider ci_backends.CiBackendProvider , appId int64 , postCommentHooks [] IssueCommentHook ) error {
645
625
installationId := * payload .Installation .ID
646
626
repoName := * payload .Repo .Name
647
627
repoOwner := * payload .Repo .Owner .Login
@@ -871,6 +851,15 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
871
851
commentReporterManager .UpdateComment (fmt .Sprintf (":x: TriggerDiggerJobs error: %v" , err ))
872
852
return fmt .Errorf ("error triggering Digger Jobs" )
873
853
}
854
+
855
+ log .Printf ("executing issue comment event post hooks:" )
856
+ for _ , hook := range postCommentHooks {
857
+ err := hook (gh , payload , ciBackendProvider )
858
+ if err != nil {
859
+ log .Printf ("handleIssueCommentEvent post hook error: %v" , err )
860
+ return fmt .Errorf ("error during postevent hooks: %v" , err )
861
+ }
862
+ }
874
863
return nil
875
864
}
876
865
0 commit comments