Skip to content

Commit 719c544

Browse files
committed
deployed-labeler: add GET handler for deployed to indicate label status
1 parent 0c2ffca commit 719c544

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

plugins/deployed-labeler/main.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,21 @@ func (s *server) markDeployedPR(w http.ResponseWriter, req *http.Request) {
128128
}
129129

130130
switch req.Method {
131-
case "POST":
131+
case "GET":
132+
var msg struct {
133+
PRs struct {
134+
Labeled []string `json:"labeled"`
135+
Unlabeled []string `json:"unlabeled"`
136+
}
137+
Errors []error `json:"errors"`
138+
}
139+
msg.PRs.Labeled, msg.PRs.Unlabeled, msg.Errors = s.handleGetUnmarkedPRs(req.Context(), commitSHA, team)
140+
141+
enc := json.NewEncoder(w)
142+
enc.SetIndent("", " ")
143+
enc.Encode(msg)
132144

145+
case "POST":
133146
var msg struct {
134147
DeployedPRs struct {
135148
Team []string `json:"team"`
@@ -159,6 +172,15 @@ func (s *server) handleMarkDeployedPRs(ctx context.Context, commitSHA, team stri
159172
return s.updatePullRequests(prs, team)
160173
}
161174

175+
func (s *server) handleGetUnmarkedPRs(ctx context.Context, commitSHA, team string) (labeledPRs, unlabeledPRs []string, errors []error) {
176+
prs, err := s.getMergedPRs(ctx, commitSHA)
177+
if err != nil {
178+
return nil, nil, []error{err}
179+
}
180+
181+
return s.findTeamPullRequests(prs, team)
182+
}
183+
162184
const (
163185
org = "gitpod-io"
164186
repo = "gitpod"
@@ -206,7 +228,27 @@ func (s *server) updatePullRequests(prs []pullRequest, team string) (teamDeploye
206228
errs = append(errs, err)
207229
}
208230
} else {
209-
s.log.Infof("PR %v already has label %v", pr.Number, labelDeployed)
231+
s.log.Debugf("PR %v already has label %v", pr.Number, labelDeployed)
232+
}
233+
}
234+
return
235+
}
236+
237+
// Find labeled and unlabeled pull requests for the given team.
238+
func (s *server) findTeamPullRequests(prs []pullRequest, team string) (labeled, unlabeled []string, errs []error) {
239+
for _, pr := range prs {
240+
241+
lblTeam := teamLabel(team)
242+
if _, belongs := pr.Labels[lblTeam]; !belongs {
243+
s.log.Debugf("PR %v does not belong to %v, skipping it", pr.Number, team)
244+
continue
245+
}
246+
247+
teamDeployedLabel := deployedLabel(team)
248+
if _, hasLabel := pr.Labels[teamDeployedLabel]; !hasLabel {
249+
unlabeled = append(unlabeled, pr.URL)
250+
} else {
251+
labeled = append(labeled, pr.URL)
210252
}
211253
}
212254
return

0 commit comments

Comments
 (0)