Skip to content

Commit

Permalink
Fix: check if requested team has been assigned to the PR (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek committed Aug 6, 2020
1 parent 3d330bd commit 92ff9ca
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions dev/update-package-storage/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ type searchIssuesResponse struct {
}

type createPullRequestResponse struct {
Number int
Number int `json:"number"`
RequestedTeams []interface{} `json:"requested_teams"`
RequestedUsers []interface{} `json:"requested_users"`
}

type pullRequest struct {
Expand Down Expand Up @@ -133,13 +135,24 @@ func updatePullRequestReviewersWithoutFallback(pullRequestID int, reviewer strin
return false, errors.Wrap(err, "making HTTP call failed")
}

if response.StatusCode == 422 {
return false, nil // reviewer is not project collaborator
}

if response.StatusCode < 200 || response.StatusCode > 299 {
return false, fmt.Errorf("unexpected status code return while opening a pull request: %d", response.StatusCode)
}

var data createPullRequestResponse
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return false, errors.Wrap(err, "can't read response body")
}

if err := json.Unmarshal(body, &data); err != nil {
return false, errors.Wrap(err, "unmarshalling response failed")
}

if len(data.RequestedTeams) == 0 && len(data.RequestedUsers) == 0 {
return false, nil // no reviewers were found (not contributing)
}
return true, nil
}

Expand Down

0 comments on commit 92ff9ca

Please sign in to comment.