GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — return a status so that application does not timeout · esalinascl/CodeEngine@d230b5c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • github
    • github.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎github/github.go‎

Copy file name to clipboardExpand all lines: github/github.go
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ func VerifyEvent(req *http.Request, body []byte, secret string) bool {
3030
}
3131

3232
// Do whatever logic we need for the incoming event
33-
func ProcessEvent(eventType string, eventBody []byte) {
33+
func ProcessEvent(eventType string, eventBody []byte) int {
3434
log.Printf("Event Type: %s", eventType)
3535

36-
// Only care about "push" events
37-
if eventType != "push" {
36+
// Only care about "push" events and "ping" for webhook creation
37+
if eventType == "ping" {
38+
return http.StatusOK
39+
} else if eventType != "push" {
3840
log.Print("Not a 'push' event so exit")
39-
return
41+
return http.StatusBadRequest
4042
}
4143

4244
pretty, _ := json.MarshalIndent(json.RawMessage(eventBody), "", " ")
@@ -79,13 +81,7 @@ func ProcessEvent(eventType string, eventBody []byte) {
7981
err := json.Unmarshal(eventBody, &PushEvent)
8082
if err != nil {
8183
log.Printf("Error parsing:\n%s\n%s", err, string(eventBody))
82-
return
83-
}
84-
85-
// Only care about pushes to the "main" branch
86-
if PushEvent.Ref != "refs/heads/main" {
87-
log.Printf("Skipping branch: %s", PushEvent.Ref)
88-
return
84+
return http.StatusBadRequest
8985
}
9086

9187
log.Printf("%s committed %q to %q branch",
@@ -95,6 +91,7 @@ func ProcessEvent(eventType string, eventBody []byte) {
9591
// To see how to kick off CodeEngine CLI commands from inside of an app
9692
// see the "cecli" sample.
9793
log.Print("ibmcloud ce buildrun submit ...")
94+
return http.StatusOK
9895
}
9996

10097
// Simple web server that waits for incoming events, verifies they're
@@ -110,7 +107,8 @@ func main() {
110107
return
111108
}
112109

113-
ProcessEvent(r.Header.Get("X-Github-Event"), body)
110+
status := ProcessEvent(r.Header.Get("X-Github-Event"), body)
111+
w.WriteHeader(status)
114112
})
115113

116114
log.Printf("Listening on port 8080")

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.