@@ -107,16 +107,37 @@ func (c *Client) GetArchive(project *Project, ref string) ([]byte, error) {
107
107
// for v4 file_path is not a parameter but part of URI. Should be encoded anyway.
108
108
// update, right now this one doesn't seem's to work.
109
109
//
110
- // KEEP EYE ON THIS METHOD, v4 right now doesn't work as expected.
110
+ // GitLab < v9.4.2: v4 method doesn't work as documented, uses v3 signature.
111
+ // GitLab >= v9.4.2: v4 work as documented.
112
+ //
113
+ // To maintain compatibility between all v3, v4-pre and v4 versions,
114
+ // one extra HEAD request should be executed.
111
115
//
112
116
func (c * Client ) GetFile (project * Project , path , ref string ) ([]byte , error ) {
117
+ var endpoint string
113
118
114
- endpoint := fmt .Sprintf (
119
+ // v3 and v4:legacy method for accessing files
120
+ endpoint = fmt .Sprintf (
115
121
"projects/%d/repository/files?file_path=%s&ref=%s" ,
116
122
project .ID ,
117
123
url .QueryEscape (path ),
118
124
url .QueryEscape (ref ),
119
125
)
126
+
127
+ if c .HasV4Support {
128
+ // check broken v4 api
129
+ r , _ := c .executeHead (endpoint )
130
+ if r .StatusCode () != 200 {
131
+ // ok, gitlab has correct v4 support
132
+ endpoint = fmt .Sprintf (
133
+ "projects/%d/repository/files/%s?ref=%s" ,
134
+ project .ID ,
135
+ url .QueryEscape (path ),
136
+ url .QueryEscape (ref ),
137
+ )
138
+ }
139
+ }
140
+
120
141
pageList , err := c .executeAPIMethod (endpoint )
121
142
if err != nil {
122
143
return nil , err
0 commit comments