@@ -34,14 +34,16 @@ var (
3434)
3535
3636type Trigger struct {
37- client * http.Client
38- schema Schema
39- host , privateToken , token , ref string
40- projectID int
41- variables []string
37+ client * http.Client
38+ schema Schema
39+ host , urlPrefix , privateToken , token , ref string
40+ projectID int
41+ variables []string
4242}
4343
44- func New (tlsInsecureSkipVerify bool , schema Schema , host , privateToken , token , ref string , projectID int , variables []string ) * Trigger {
44+ func New (tlsInsecureSkipVerify bool , schema Schema ,
45+ host , urlPrefix , privateToken , token , ref string , projectID int , variables []string ) * Trigger {
46+
4547 httpTransport := & http.Transport {
4648 DialContext : (& net.Dialer {
4749 Timeout : httpClientTimeout ,
@@ -57,7 +59,8 @@ func New(tlsInsecureSkipVerify bool, schema Schema, host, privateToken, token, r
5759 Timeout : httpClientTimeout ,
5860 }
5961
60- return & Trigger {client : client , schema : schema , host : host , privateToken : privateToken , token : token , ref : ref , projectID : projectID , variables : variables }
62+ return & Trigger {client : client , schema : schema , host : host , urlPrefix : urlPrefix ,
63+ privateToken : privateToken , token : token , ref : ref , projectID : projectID , variables : variables }
6164}
6265
6366func (p Trigger ) RunPipeline () (* models.CreatePipelineResponse , error ) {
@@ -196,7 +199,7 @@ func (p Trigger) urlVariables() url.Values {
196199}
197200
198201func (p Trigger ) createPipelineTpl () (* template.Template , error ) {
199- urlTpl := "{{.Schema}}://{{.Host}}/api/v4/projects/{{.ProjectID}}/trigger/pipeline"
202+ urlTpl := "{{.Schema}}://{{.Host}}/{{.URLPrefix}} api/v4/projects/{{.ProjectID}}/trigger/pipeline"
200203 tpl , err := template .New ("tpl" ).Parse (urlTpl )
201204 if err != nil {
202205 return nil , errors .New ("failed to parse pipeline url template" )
@@ -206,7 +209,7 @@ func (p Trigger) createPipelineTpl() (*template.Template, error) {
206209}
207210
208211func (p Trigger ) pollPipelineTpl () (* template.Template , error ) {
209- urlTpl := "{{.Schema}}://{{.Host}}/api/v4/projects/{{.ProjectID}}/pipelines"
212+ urlTpl := "{{.Schema}}://{{.Host}}/{{.URLPrefix}} api/v4/projects/{{.ProjectID}}/pipelines"
210213 tpl , err := template .New ("tpl" ).Parse (urlTpl )
211214 if err != nil {
212215 return nil , errors .New ("failed to parse pipeline url template" )
@@ -220,12 +223,17 @@ func (p *Trigger) urlByTemplate(tpl *template.Template) (string, error) {
220223 p .host = DefaultHost
221224 }
222225
226+ if p .urlPrefix != "" && ! strings .HasSuffix (p .urlPrefix , "/" ) {
227+ p .urlPrefix = p .urlPrefix + "/"
228+ }
229+
223230 var buf bytes.Buffer
224231 if err := tpl .ExecuteTemplate (& buf , "tpl" , & struct {
225232 Schema string
226233 Host string
227234 ProjectID int
228- }{Schema : p .schemaName (p .schema ), Host : p .host , ProjectID : p .projectID }); err != nil {
235+ URLPrefix string
236+ }{Schema : p .schemaName (p .schema ), Host : p .host , URLPrefix : p .urlPrefix , ProjectID : p .projectID }); err != nil {
229237 return "" , errors .Wrap (err , "failed to execute pipeline url template" )
230238 }
231239
0 commit comments