diff --git a/cmd/build.go b/cmd/build.go index 65a6df5..360f5bf 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -35,7 +35,7 @@ var buildCmd = &cobra.Command{ Long: ` First of all, this build command will copy the project code and its necessary dependencies to a temporary directory, then do cover for the target in this temporary directory, finally go build command will be executed and binaries generated to their original place. -To pass origial go build flags to goc command, place them after "--", see examples below for reference. +To pass original go build flags to goc command, place them after "--", see examples below for reference. `, Example: ` # Build the current binary with cover variables injected. The binary will be generated in the current folder. diff --git a/cmd/diff.go b/cmd/diff.go index 561aec4..e756823 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -33,7 +33,7 @@ import ( var diffCmd = &cobra.Command{ Use: "diff", - Short: "do coverage profile diff analysis, it can also work with prow and post comments to github pull request if needed", + Short: "Do coverage profile diff analysis, it can also work with prow and post comments to github pull request if needed", Example: ` # Diff two local coverage profile and display goc diff --new-profile= --base-profile= diff --git a/go.mod b/go.mod index 4d7daeb..79e1eca 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.13 require ( github.com/gin-gonic/gin v1.6.3 github.com/google/go-github v17.0.0+incompatible + github.com/hashicorp/go-retryablehttp v0.6.6 github.com/julienschmidt/httprouter v1.2.0 github.com/magiconair/properties v1.8.1 github.com/mattn/go-runewidth v0.0.9 // indirect diff --git a/go.sum b/go.sum index 5bc5442..c1b07ba 100644 --- a/go.sum +++ b/go.sum @@ -397,8 +397,14 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/h2non/gock v1.0.9/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= +github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM= +github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= diff --git a/pkg/github/github.go b/pkg/github/github.go index ae699a7..76fd990 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/google/go-github/github" + "github.com/hashicorp/go-retryablehttp" "github.com/olekukonko/tablewriter" "github.com/sirupsen/logrus" "golang.org/x/oauth2" @@ -46,9 +47,13 @@ type PrComment struct { GithubClient *github.Client } +// NewPrClient creates an Client which be able to comment on Github Pull Request func NewPrClient(githubTokenPath, repoOwner, repoName, prNumStr, botUserName, commentFlag string) *PrComment { var client *github.Client - var ctx = context.Background() + + // performs automatic retries when connection error occurs or a 500-range response code received (except 501) + retryClient := retryablehttp.NewClient() + ctx := context.WithValue(context.Background(), oauth2.HTTPClient, retryClient.StandardClient()) prNum, err := strconv.Atoi(prNumStr) if err != nil { @@ -133,7 +138,7 @@ func (c *PrComment) EraseHistoryComment(commentPrefix string) error { return nil } -//get github pull request changes file list +//GetPrChangedFiles get github pull request changes file list func (c *PrComment) GetPrChangedFiles() (files []string, err error) { var commitFiles []*github.CommitFile for {