Skip to content

Commit

Permalink
Merge pull request #6 from EGT-Ukraine/fix/variables
Browse files Browse the repository at this point in the history
variables fix
  • Loading branch information
Vyacheslav Pryimak authored Feb 13, 2019
2 parents 1c73647 + cac8727 commit 1cc34af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ options:
* `--schema` - (optional. default: https) set http or https connection type;
* `--ref` - (optional) branch for the project. (default: master);
* `--urlPrefix` - (optional) if you are use some prefix for your Gitlab (final URL will be looked like: /prefix/api/v4/...);
* `--variables` - (optional) custom variables for the project (format example: `variable1:value,variable2:value`)
* `--variables` - (optional) custom variables for the project

### Run:

```bash
./gtw --privateToken ${PRIVATE_TOKEN} --token ${TOKEN} --host gitlab.egt.com --projectID 123 run
./gtw --privateToken ${PRIVATE_TOKEN} --token ${TOKEN} --host gitlab.egt.com --projectID 123 --variables KEY1:VALUE1 --variables KEY2:VALUE2 run
```
10 changes: 5 additions & 5 deletions trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (p Trigger) RunPipeline() (*models.CreatePipelineResponse, error) {

vars := p.urlVariables()
if p.token != "" {
vars.Add("token", p.token)
vars.Set("token", p.token)
}
if p.ref != "" {
vars.Add("ref", p.ref)
vars.Set("ref", p.ref)
}

req, err := http.NewRequest(http.MethodPost, u, strings.NewReader(vars.Encode()))
Expand Down Expand Up @@ -126,7 +126,7 @@ func (p Trigger) PollForCompletion(pipelineID int64) (*models.PipelineStatusResp
headers := p.defaultHeaders()
headers["PRIVATE-TOKEN"] = []string{p.privateToken}

req, err := http.NewRequest(http.MethodGet, u, strings.NewReader(p.urlVariables().Encode()))
req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, errors.Wrap(err, "create request failed")
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (p Trigger) PollForCompletion(pipelineID int64) (*models.PipelineStatusResp

func (p Trigger) defaultHeaders() map[string][]string {
return map[string][]string{
"Content-Type": {"multipart/form-data"},
"Content-Type": {"application/x-www-form-urlencoded"},
}
}

Expand All @@ -188,7 +188,7 @@ func (p Trigger) urlVariables() url.Values {
for _, variable := range p.variables {
kv := strings.SplitN(variable, ":", 2)
if len(kv) == 2 {
values.Add(fmt.Sprintf("variables[%s]", kv[0]), kv[1])
values.Set(fmt.Sprintf("variables[%s]", kv[0]), kv[1])
}
}

Expand Down

0 comments on commit 1cc34af

Please sign in to comment.