github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/azure/notify.go (about) 1 // Copyright 2019 The WPT Dashboard Project. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package azure 6 7 import ( 8 "fmt" 9 "net/http" 10 "strconv" 11 12 "github.com/gorilla/mux" 13 "github.com/web-platform-tests/wpt.fyi/shared" 14 ) 15 16 func notifyHandler(w http.ResponseWriter, r *http.Request) { 17 vars := mux.Vars(r) 18 id := vars["id"] 19 var buildID int64 20 var err error 21 if buildID, err = strconv.ParseInt(id, 0, 0); err != nil { 22 http.Error(w, fmt.Sprintf("Invalid build id: %s", id), http.StatusBadRequest) 23 24 return 25 } 26 27 ctx := r.Context() 28 aeAPI := shared.NewAppEngineAPI(ctx) 29 azureAPI := NewAPI(ctx) 30 log := shared.GetLogger(ctx) 31 32 processed, err := processBuild( 33 aeAPI, 34 azureAPI, 35 shared.WPTRepoOwner, 36 shared.WPTRepoName, 37 "", // No sender info. 38 r.FormValue("artifact"), // artifact=foo will only process foo. 39 buildID) 40 41 if err != nil { 42 log.Errorf("%v", err.Error()) 43 http.Error(w, err.Error(), http.StatusInternalServerError) 44 45 return 46 } 47 if processed { 48 w.WriteHeader(http.StatusOK) 49 fmt.Fprintln(w, "Azure build artifacts retrieved successfully") 50 } else { 51 w.WriteHeader(http.StatusNoContent) 52 fmt.Fprintln(w, "Notification of build artifacts was ignored") 53 } 54 }