@@ -6,14 +6,29 @@ import (
66 "io/ioutil"
77 "net/http"
88 "os"
9+ "strings"
910)
1011
1112var (
12- gitHubCommitsApi = "https://api.github.com/repos/gohugoio/hugo /commits/%s"
13- gitHubRepoApi = "https://api.github.com/repos/gohugoio/hugo "
14- gitHubContributorsApi = "https://api.github.com/repos/gohugoio/hugo /contributors"
13+ gitHubCommitsAPI = "https://api.github.com/repos/gohugoio/REPO /commits/%s"
14+ gitHubRepoAPI = "https://api.github.com/repos/gohugoio/REPO "
15+ gitHubContributorsAPI = "https://api.github.com/repos/gohugoio/REPO /contributors"
1516)
1617
18+ type gitHubAPI struct {
19+ commitsAPITemplate string
20+ repoAPI string
21+ contributorsAPITemplate string
22+ }
23+
24+ func newGitHubAPI (repo string ) * gitHubAPI {
25+ return & gitHubAPI {
26+ commitsAPITemplate : strings .Replace (gitHubCommitsAPI , "REPO" , repo , - 1 ),
27+ repoAPI : strings .Replace (gitHubRepoAPI , "REPO" , repo , - 1 ),
28+ contributorsAPITemplate : strings .Replace (gitHubContributorsAPI , "REPO" , repo , - 1 ),
29+ }
30+ }
31+
1732type gitHubCommit struct {
1833 Author gitHubAuthor `json:"author"`
1934 HtmlURL string `json:"html_url"`
@@ -42,10 +57,10 @@ type gitHubContributor struct {
4257 Contributions int `json:"contributions"`
4358}
4459
45- func fetchCommit (ref string ) (gitHubCommit , error ) {
60+ func ( g * gitHubAPI ) fetchCommit (ref string ) (gitHubCommit , error ) {
4661 var commit gitHubCommit
4762
48- u := fmt .Sprintf (gitHubCommitsApi , ref )
63+ u := fmt .Sprintf (g . commitsAPITemplate , ref )
4964
5065 req , err := http .NewRequest ("GET" , u , nil )
5166 if err != nil {
@@ -57,10 +72,10 @@ func fetchCommit(ref string) (gitHubCommit, error) {
5772 return commit , err
5873}
5974
60- func fetchRepo () (gitHubRepo , error ) {
75+ func ( g * gitHubAPI ) fetchRepo () (gitHubRepo , error ) {
6176 var repo gitHubRepo
6277
63- req , err := http .NewRequest ("GET" , gitHubRepoApi , nil )
78+ req , err := http .NewRequest ("GET" , g . repoAPI , nil )
6479 if err != nil {
6580 return repo , err
6681 }
@@ -75,7 +90,7 @@ func fetchRepo() (gitHubRepo, error) {
7590 for {
7691 page ++
7792 var currPage []gitHubContributor
78- url := fmt .Sprintf (gitHubContributorsApi + "?page=%d" , page )
93+ url := fmt .Sprintf (g . contributorsAPITemplate + "?page=%d" , page )
7994
8095 req , err = http .NewRequest ("GET" , url , nil )
8196 if err != nil {
0 commit comments