@@ -11,6 +11,7 @@ import (
1111 "os"
1212 "os/exec"
1313 "path/filepath"
14+ "time"
1415
1516 "github.com/ONSdigital/git-diff-check/diffcheck"
1617)
@@ -21,8 +22,13 @@ const (
2122 rejected = 1
2223)
2324
24- // Repository defines the github repo where the source code is located
25- const Repository = "ONSdigital/git-diff-check"
25+ const (
26+ // Repository defines the github repo where the source code is located
27+ Repository = "ONSdigital/git-diff-check"
28+
29+ // LatestVersion gives the api location of the most recent tag in github
30+ LatestVersion = "https://api.github.com/repos/" + Repository + "/releases/latest"
31+ )
2632
2733var target = flag .String ("p" , "" , "(optional) path to repository" )
2834var showVersion bool
@@ -127,30 +133,31 @@ type VersionResponse struct {
127133
128134func versionCheck () bool {
129135
130- // TODO
131- // Set default client timeouts etc
136+ var netClient = & http.Client {
137+ Timeout : time .Second * 2 ,
138+ }
132139
133- resp , err := http .Get ("https://api.github.com/repos/" + Repository + "/releases/latest" )
140+ resp , err := netClient .Get (LatestVersion )
134141 if err != nil {
135- fmt .Println (errors . New ( "Failed to check for new versions" + err .Error () ))
142+ fmt .Println ("Failed to check for new versions" + err .Error ())
136143 return false
137144 }
138145
139146 body , err := ioutil .ReadAll (resp .Body )
140147 if err != nil {
141- fmt .Println (errors . New ( "Failed to read response from version check " + err .Error () ))
148+ fmt .Println ("Failed to check for new versions " + err .Error ())
142149 return false
143150 }
144151
145152 var v VersionResponse
146153 err = json .Unmarshal (body , & v )
147154 if err != nil {
148- fmt .Println (errors . New ( "Failed to read response from version check " + err .Error () ))
155+ fmt .Println ("Failed to check for new versions " + err .Error ())
149156 return false
150157 }
151158
152159 if len (v .TagName ) == 0 {
153- fmt .Println (errors . New ( "Failed to parse version from github response" ) )
160+ fmt .Println ("Failed to parse version from github response" )
154161 return false
155162 }
156163
0 commit comments