do retry when connecting github failed
This commit is contained in:
parent
4e614b18d1
commit
89efcb2215
1
go.mod
1
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
|
||||
|
6
go.sum
6
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=
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user