Skip to content

Commit

Permalink
Add user-agent string
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
  • Loading branch information
saswatamcode committed May 31, 2021
1 parent 0e2b12a commit af2c1ce
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/mdformatter/linktransformer/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,16 @@ func getGitHubRegex(repoRe string) (*regexp.Regexp, int, error) {
var pullNum []GitHubResponse
var issueNum []GitHubResponse
max := 0
// All GitHub API reqs need to have User-Agent: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required.
client := &http.Client{}

// Check latest pull request number.
respPull, err := http.Get(fmt.Sprintf(gitHubAPIURL, reponame, "pulls"))
reqPull, err := http.NewRequest("GET", fmt.Sprintf(gitHubAPIURL, reponame, "pulls"), nil)
if err != nil {
return nil, math.MaxInt64, err
}
reqPull.Header.Set("User-Agent", "mdox")
respPull, err := client.Do(reqPull)
if err != nil {
return nil, math.MaxInt64, err
}
Expand All @@ -103,7 +111,12 @@ func getGitHubRegex(repoRe string) (*regexp.Regexp, int, error) {
}

// Check latest issue number and return whichever is greater.
respIssue, err := http.Get(fmt.Sprintf(gitHubAPIURL, reponame, "issues"))
reqIssue, err := http.NewRequest("GET", fmt.Sprintf(gitHubAPIURL, reponame, "issues"), nil)
if err != nil {
return nil, math.MaxInt64, err
}
reqIssue.Header.Set("User-Agent", "mdox")
respIssue, err := client.Do(reqIssue)
if err != nil {
return nil, math.MaxInt64, err
}
Expand Down

0 comments on commit af2c1ce

Please sign in to comment.