@@ -107,45 +107,32 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
107107
108108 if team == "" || commitSHA == "" {
109109
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-
117110 s .log .WithFields (
118111 logrus.Fields {
119112 "team" : team ,
120113 "commit" : commitSHA ,
121114 },
122115 ).Error ("team and commit are required parameters" )
123116
124- w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
125- w .Header ().Set ("X-Content-Type-Options" , "nosniff" )
126117 w .WriteHeader (http .StatusPreconditionFailed )
127- json .NewEncoder (w ).Encode (preconditionFailed )
118+ enc := json .NewEncoder (w )
119+ enc .SetIndent ("" , " " )
120+ enc .Encode (map [string ]string {
121+ "error" : "team and commit are required parameters" ,
122+ })
128123 return
129124 }
130125
131- var errs []error
132-
133126 switch req .Method {
134- case "GET " :
127+ case "POST " :
135128 var msg struct {
136- PRs struct {
137- Labeled []string `json:"labeled"`
138- Unlabeled []string `json:"unlabeled"`
139- }
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 ())
129+ DeployedPRs struct {
130+ Team []string `json:"team"`
131+ All []string `json:"all"`
132+ } `json:"deployedPRs"`
133+ Errors []error `json:"errors"`
148134 }
135+ msg .DeployedPRs .Team , msg .DeployedPRs .All , msg .Errors = s .handleMarkDeployedPRs (req .Context (), commitSHA , team )
149136
150137 if len (msg .Errors ) > 0 {
151138 w .WriteHeader (http .StatusUnprocessableEntity )
@@ -154,21 +141,16 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
154141 enc := json .NewEncoder (w )
155142 enc .SetIndent ("" , " " )
156143 enc .Encode (msg )
157-
158- case "POST" :
144+ case "GET" :
159145 var msg struct {
160- DeployedPRs struct {
161- Team []string `json:"team "`
162- All []string `json:"all "`
163- } `json:"deployedPRs"`
146+ PRs struct {
147+ Labeled []string `json:"labeled "`
148+ Unlabeled []string `json:"unlabeled "`
149+ }
164150 Errors []error `json:"errors"`
165151 }
166- msg .DeployedPRs .Team , msg .DeployedPRs .All , msg .Errors = s .handleMarkDeployedPRs (req .Context (), commitSHA , team )
167152
168- msg .Errors = make ([]string , 0 , len (errs ))
169- for _ , err := range errs {
170- msg .Errors = append (msg .Errors , err .Error ())
171- }
153+ msg .PRs .Labeled , msg .PRs .Unlabeled , msg .Errors = s .handleGetUnmarkedPRs (req .Context (), commitSHA , team )
172154
173155 if len (msg .Errors ) > 0 {
174156 w .WriteHeader (http .StatusUnprocessableEntity )
@@ -177,6 +159,7 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
177159 enc := json .NewEncoder (w )
178160 enc .SetIndent ("" , " " )
179161 enc .Encode (msg )
162+
180163 default :
181164 w .WriteHeader (http .StatusNotImplemented )
182165 w .Write ([]byte (http .StatusText (http .StatusNotImplemented )))
0 commit comments