@@ -106,48 +106,35 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
106106 }
107107
108108 if team == "" || commitSHA == "" {
109-
110- var preconditionFailed struct {
111- Errors []string
112- }
113-
114- preconditionFailed .Errors = make ([]string , 0 , 1 )
115- preconditionFailed .Errors = append (preconditionFailed .Errors , fmt .Sprintf ("team and commit are required parameters. Team: '%v', commit: '%v'" , team , commitSHA ))
116-
117109 s .log .WithFields (
118110 logrus.Fields {
119111 "team" : team ,
120112 "commit" : commitSHA ,
121113 },
122114 ).Error ("team and commit are required parameters" )
123115
124- w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
125- w .Header ().Set ("X-Content-Type-Options" , "nosniff" )
126116 w .WriteHeader (http .StatusPreconditionFailed )
127- json .NewEncoder (w ).Encode (preconditionFailed )
117+ enc := json .NewEncoder (w )
118+ enc .SetIndent ("" , " " )
119+ enc .Encode (map [string ]string {
120+ "error" : "team and commit are required parameters" ,
121+ })
128122 return
129123 }
130-
131- var errs []error
132-
124+ var err error
133125 switch req .Method {
134126 case "GET" :
135127 var msg struct {
136128 PRs struct {
137129 Labeled []string `json:"labeled"`
138130 Unlabeled []string `json:"unlabeled"`
139131 }
140- Errors []string `json:"errors"`
141- }
142-
143- msg .PRs .Labeled , msg .PRs .Unlabeled , errs = s .handleGetUnmarkedPRs (req .Context (), commitSHA , team )
144-
145- msg .Errors = make ([]string , 0 , len (errs ))
146- for _ , err := range errs {
147- msg .Errors = append (msg .Errors , err .Error ())
132+ Error string `json:"error"`
148133 }
149134
150- if len (msg .Errors ) > 0 {
135+ msg .PRs .Labeled , msg .PRs .Unlabeled , err = s .handleGetUnmarkedPRs (req .Context (), commitSHA , team )
136+ if err != nil {
137+ msg .Error = err .Error ()
151138 w .WriteHeader (http .StatusUnprocessableEntity )
152139 }
153140
@@ -156,14 +143,15 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
156143 enc .Encode (msg )
157144
158145 case "POST" :
146+ var errs []error
159147 var msg struct {
160148 DeployedPRs struct {
161149 Team []string `json:"team"`
162150 All []string `json:"all"`
163151 } `json:"deployedPRs"`
164- Errors []error `json:"errors"`
152+ Errors []string `json:"errors"`
165153 }
166- msg .DeployedPRs .Team , msg .DeployedPRs .All , msg . Errors = s .handleMarkDeployedPRs (req .Context (), commitSHA , team )
154+ msg .DeployedPRs .Team , msg .DeployedPRs .All , errs = s .handleMarkDeployedPRs (req .Context (), commitSHA , team )
167155
168156 msg .Errors = make ([]string , 0 , len (errs ))
169157 for _ , err := range errs {
@@ -194,13 +182,15 @@ func (s *server) handleMarkDeployedPRs(ctx context.Context, commitSHA, team stri
194182 return s .updatePullRequests (prs , team )
195183}
196184
197- func (s * server ) handleGetUnmarkedPRs (ctx context.Context , commitSHA , team string ) (labeledPRs , unlabeledPRs []string , errors [] error ) {
185+ func (s * server ) handleGetUnmarkedPRs (ctx context.Context , commitSHA , team string ) (labeledPRs , unlabeledPRs []string , err error ) {
198186 prs , err := s .getMergedPRs (ctx , commitSHA )
199187 if err != nil {
200- return nil , nil , [] error { err }
188+ return nil , nil , err
201189 }
202190
203- return s .findTeamPullRequests (prs , team )
191+ labeledPRs , unlabeledPRs = s .findTeamPullRequests (prs , team )
192+
193+ return labeledPRs , unlabeledPRs , nil
204194}
205195
206196const (
@@ -257,7 +247,7 @@ func (s *server) updatePullRequests(prs []pullRequest, team string) (teamDeploye
257247}
258248
259249// Find labeled and unlabeled pull requests for the given team.
260- func (s * server ) findTeamPullRequests (prs []pullRequest , team string ) (labeled , unlabeled []string , errs [] error ) {
250+ func (s * server ) findTeamPullRequests (prs []pullRequest , team string ) (labeled , unlabeled []string ) {
261251 for _ , pr := range prs {
262252
263253 lblTeam := teamLabel (team )
0 commit comments