go-github
go-github copied to clipboard
requesting reviewers does not work at all
I am about to script some logic we want to do on a regular basis. It is basically about creating PRs automatically. I tried to implement the requesting of reviewers and noticed that this does not do anything AFAICS. See https://godoc.org/github.com/google/go-github/github#PullRequestsService.RequestReviewers. The PR I created with my script is https://github.com/giantswarm/test-operator/pull/1. In the web UI I can add reviewers manually but not using the go-github
library. There is also no error or anything. Note that I can also set some random strings as team reviewers and even then nothing happens. Let me also just drop some snippet I am using in which I experience the described problem.
// Create the copy PR in Github.
{
i := &github.NewPullRequest{
Title: github.String(commitMessage),
Head: github.String(branchName),
Base: github.String("master"),
Body: github.String("This PR got created by `opsctl` in order to automate the creation of a new WIP version bundle. This specific PR is to copy the latest resource package only."),
MaintainerCanModify: github.Bool(true),
}
_, _, err := githubClient.PullRequests.Create(ctx, org, repo, i)
if IsPRAlreadyExists(err) {
// fall through
} else if err != nil {
return microerror.Mask(err)
}
fmt.Printf("Ensured github PR.\n")
}
// Lookup the copy PR in Github. We do this because it may already exist. Then
// the creation above failed and does not return the result we need to
// proceed.
var copyPR *github.PullRequest
{
{
i := &github.PullRequestListOptions{}
o, _, err := githubClient.PullRequests.List(ctx, org, repo, i)
if err != nil {
return microerror.Mask(err)
}
for _, p := range o {
if *p.Title != commitMessage {
continue
}
copyPR = p
break
}
}
}
// Add PR reviewers to the copy PR so we spread knowledge about the things
// that are going on.
{
i := github.ReviewersRequest{
TeamReviewers: []string{
"giantswarm/sig-customer",
"giantswarm/sig-operator",
"giantswarm/sre",
},
}
o, res, err := githubClient.PullRequests.RequestReviewers(ctx, org, repo, copyPR.GetNumber(), i)
fmt.Printf("\n")
fmt.Printf("%#v\n", copyPR.GetAssignee())
fmt.Printf("%#v\n", copyPR.GetNumber())
fmt.Printf("%#v\n", copyPR.GetTitle())
fmt.Printf("%#v\n", copyPR.GetUser())
fmt.Printf("%#v\n", o)
fmt.Printf("%#v\n", res)
fmt.Printf("%#v\n", err)
fmt.Printf("\n")
if err != nil {
return microerror.Mask(err)
}
}
Any idea what is going on? Am I doing something wrong? Is this a bug? I did not find any issue related to this here on Github.
FYI as a workaround I can go with pinging reviewers in the PR description or comments. I would anyway like to get this sorted in a clean way.
I apologize for having missed this issue almost two years ago. Is this still an issue?
Looking at the GitHub docs: https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
I see you have slashes in the name and the example uses team slugs for the TeamReviewers
field. Could it be that you are not using valid team slugs?
Are you able to get the command to work using the GitHub v3 API directly using curl
?
If not, you might want to reach out to [email protected] and they might be able to help.
Additionally, GitHub just recently announced their "gh" command-line tool, which is ironically how I found this issue... that might also be useful for what you are trying to do.
Thanks for getting back eventually. Not an issue ATM. Will get back to this in case I have a specific use case again.
OK, thank you, @xh3b4sd. Closing for now, but please re-open, and definitely feel free to ping me in the future if I don't respond in a day or week.
Hi,
I am having a similar problem. I am attempting to add reviewers to a PR that I have made using the go-github
library. I have created a PR and am trying to add reviewers to it using a very similar method to the one described in the OP.
When I run it, I am not getting any error messages returned yet reviewers are not added to the PR.
When I run it, I am not getting any error messages returned yet reviewers are not added to the PR.
OK, can you please try interacting with the GitHub v3 API directly using curl
and compare the results using this client library?
This tool can help out quite a bit: https://github.com/gmlewis/go-httpdebug/
If the curl
version has the same problems, then we have a GitHub v3 API problem.
However, if you can get the curl
version to work, but this client library still has problems, we have a bug and can fix it with a PR.
Please report back with your findings.
Seeing the same problem: from my side, I can update the reviewers if I provide a single reviewer, but if I provide more than one reviewer the call does nothing. the cURL version works fine, so it must be a bug..
Seeing the same problem: from my side, I can update the reviewers if I provide a single reviewer, but if I provide more than one reviewer the call does nothing. the cURL version works fine, so it must be a bug..
Can you please post both the curl
version and the go-github
version (using go-httpdebug) (making sure to remove any secrets) to this thread so that we can see the differences?
For me, it didn't work for the GitHub Application until I changed the "Organization: Members" to write and read + need to use the slug team name instead of the full Team name
For me, it didn't work for the GitHub Application until I changed the "Organization: Members" to write and read + need to use the slug team name instead of the full Team name
Thank you for the solution, @cheels !
Closing as working.