Created
January 4, 2017 15:43
-
-
Save haya14busa/6eae0c71a6dbbb652e90d227817dc8fd to your computer and use it in GitHub Desktop.
testing GitHub review API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"github.com/google/go-github/github" | |
"golang.org/x/oauth2" | |
) | |
func main() { | |
ts := oauth2.StaticTokenSource( | |
&oauth2.Token{AccessToken: os.Getenv("GITHUB_API_TOKEN")}, | |
) | |
tc := oauth2.NewClient(oauth2.NoContext, ts) | |
client := github.NewClient(tc) | |
if err := run(client); err != nil { | |
fmt.Println(err) | |
} | |
} | |
const ( | |
// https://github.com/haya14busa/github-sandbox/pull/1 | |
owner = "haya14busa" | |
repo = "github-sandbox" | |
number = 1 | |
) | |
func run(cli *github.Client) error { | |
// listReviews(cli) | |
reviewID := 15115841 | |
// create a pending review | |
if true { | |
req := &github.PullRequestReviewRequest{ | |
Body: github.String("create review body"), | |
} | |
review, _, err := cli.PullRequests.CreateReview(owner, repo, number, req) | |
if err != nil { | |
return err | |
} | |
log.Printf("ID: %#v", *review.ID) | |
log.Printf("Body: %#v", *review.Body) | |
reviewID = *review.ID | |
} | |
// submit | |
if true { | |
log.Println("submit") | |
req := &github.PullRequestReviewRequest{ | |
Event: github.String("REQUEST_CHANGES"), | |
} | |
fmt.Println(req) | |
review, _, err := cli.PullRequests.SubmitReview(owner, repo, number, reviewID, req) | |
if err != nil { | |
return err | |
} | |
log.Printf("ID: %#v", reviewID) | |
log.Printf("Body: %#v", *review.Body) | |
} | |
// dissmiss | |
if true { | |
log.Println("dissmiss") | |
review, _, err := cli.PullRequests.DismissReview(owner, repo, number, reviewID, &github.PullRequestReviewDismissalRequest{Message: github.String("dissmiss!")}) | |
if err != nil { | |
return err | |
} | |
log.Printf("dissmissed %#v", review) | |
} | |
return nil | |
} | |
func listReviews(cli *github.Client) error { | |
log.Println("list reviews") | |
prs, _, err := cli.PullRequests.ListReviews(owner, repo, number) | |
if err != nil { | |
return err | |
} | |
for _, r := range prs { | |
log.Printf("%+v", r) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment