Skip to content

Commit 2192857

Browse files
committed
change []string to []error as its not needed
Signed-off-by: Tarun Pothulapati <[email protected]>
1 parent 13ea160 commit 2192857

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

plugins/deployed-labeler/main.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,45 +107,33 @@ 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 {
134127
case "GET":
135128
var msg struct {
136129
PRs struct {
137130
Labeled []string `json:"labeled"`
138131
Unlabeled []string `json:"unlabeled"`
139132
}
140-
Errors []string `json:"errors"`
133+
Errors []error `json:"errors"`
141134
}
142135

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())
148-
}
136+
msg.PRs.Labeled, msg.PRs.Unlabeled, msg.Errors = s.handleGetUnmarkedPRs(req.Context(), commitSHA, team)
149137

150138
if len(msg.Errors) > 0 {
151139
w.WriteHeader(http.StatusUnprocessableEntity)
@@ -165,11 +153,6 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
165153
}
166154
msg.DeployedPRs.Team, msg.DeployedPRs.All, msg.Errors = s.handleMarkDeployedPRs(req.Context(), commitSHA, team)
167155

168-
msg.Errors = make([]string, 0, len(errs))
169-
for _, err := range errs {
170-
msg.Errors = append(msg.Errors, err.Error())
171-
}
172-
173156
if len(msg.Errors) > 0 {
174157
w.WriteHeader(http.StatusUnprocessableEntity)
175158
}

0 commit comments

Comments
 (0)