Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hack/operatorhub/internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ func (c *Client) createPullRequest(repo githubRepository, branchName string) err
}
if res.StatusCode < 200 || res.StatusCode > 299 {
log.Println("ⅹ")
// 422 is returned when the PR already exists.
if res.StatusCode == http.StatusUnprocessableEntity {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

422 could be returned for other reasons as well, see https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api?apiVersion=2022-11-28#invalid-request

Would it be more robust to list PRs from that user that try to pull from the same branch name? https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something along the lines of

 curl -i  -H  "Accept: application/vnd.github+json" -H -H "Authorization: Bearer $GITHUB_TOKEN"  "https://api.github.com/repos/k8s-operatorhub/community-operators/pulls?head=rhr323:eck-community-operators-3.2.0"

log.Printf("Pull request for (%s) seems to exist already. Status code: %d. Ignored\n", repo.repository, res.StatusCode)
return nil // ignore the error and return nil
}
if bodyBytes, err := io.ReadAll(res.Body); err != nil {
return fmt.Errorf("while creating draft pr for (%s), body: %s, code: %d", repo.repository, string(bodyBytes), res.StatusCode)
}
Expand Down