@@ -94,16 +94,19 @@ func main() {
9494func (s * server ) markDeployedPR (w http.ResponseWriter , req * http.Request ) {
9595 var commitSHA string
9696 var team string
97+
9798 for k , v := range req .URL .Query () {
9899 switch k {
99100 case "commit" :
100101 commitSHA = v [0 ]
101102 case "team" :
102103 team = v [0 ]
104+
103105 default :
104106 s .log .Warnf ("Unrecognized parameter received: %s" , k )
105107 }
106108 }
109+
107110 if team == "" || commitSHA == "" {
108111
109112 var preconditionFailed struct {
@@ -127,16 +130,28 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
127130 return
128131 }
129132
133+ var errs []error
134+
130135 switch req .Method {
131136 case "GET" :
132137 var msg struct {
133138 PRs struct {
134139 Labeled []string `json:"labeled"`
135140 Unlabeled []string `json:"unlabeled"`
136141 }
137- Errors []error `json:"errors"`
142+ Errors []string `json:"errors"`
143+ }
144+
145+ msg .PRs .Labeled , msg .PRs .Unlabeled , errs = s .handleGetUnmarkedPRs (req .Context (), commitSHA , team )
146+
147+ msg .Errors = make ([]string , 0 , len (errs ))
148+ for _ , err := range errs {
149+ msg .Errors = append (msg .Errors , err .Error ())
150+ }
151+
152+ if len (msg .Errors ) > 0 {
153+ w .WriteHeader (http .StatusUnprocessableEntity )
138154 }
139- msg .PRs .Labeled , msg .PRs .Unlabeled , msg .Errors = s .handleGetUnmarkedPRs (req .Context (), commitSHA , team )
140155
141156 enc := json .NewEncoder (w )
142157 enc .SetIndent ("" , " " )
@@ -150,8 +165,18 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
150165 } `json:"deployedPRs"`
151166 Errors []error `json:"errors"`
152167 }
168+
153169 msg .DeployedPRs .Team , msg .DeployedPRs .All , msg .Errors = s .handleMarkDeployedPRs (req .Context (), commitSHA , team )
154170
171+ msg .Errors = make ([]string , 0 , len (errs ))
172+ for _ , err := range errs {
173+ msg .Errors = append (msg .Errors , err .Error ())
174+ }
175+
176+ if len (msg .Errors ) > 0 {
177+ w .WriteHeader (http .StatusUnprocessableEntity )
178+ }
179+
155180 enc := json .NewEncoder (w )
156181 enc .SetIndent ("" , " " )
157182 enc .Encode (msg )
0 commit comments