Skip to content

Commit

Permalink
fix(api): add git hash short param on manual run (#4140)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored and fsamin committed Apr 3, 2019
1 parent 90aba33 commit ddf14fe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
6 changes: 5 additions & 1 deletion engine/api/workflow/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ func setValuesGitInBuildParameters(run *sdk.WorkflowNodeRun, vcsInfos vcsInfos)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitBranch, sdk.StringParameter, run.VCSBranch)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitTag, sdk.StringParameter, run.VCSTag)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitHash, sdk.StringParameter, run.VCSHash)
hashShort := run.VCSHash
if len(hashShort) >= 7 {
hashShort = hashShort[:7]
}
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitHashShort, sdk.StringParameter, hashShort)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitAuthor, sdk.StringParameter, vcsInfos.Author)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitMessage, sdk.StringParameter, vcsInfos.Message)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitURL, sdk.StringParameter, vcsInfos.URL)
sdk.ParameterAddOrSetValue(&run.BuildParameters, tagGitHTTPURL, sdk.StringParameter, vcsInfos.HTTPUrl)
}

func checkNodeRunCondition(wr *sdk.WorkflowRun, conditions sdk.WorkflowNodeConditions, params []sdk.Parameter) bool {

var conditionsOK bool
var errc error
if conditions.LuaScript == "" {
Expand Down
1 change: 1 addition & 0 deletions engine/api/workflow/run_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
tagTriggeredBy = "triggered_by"
tagEnvironment = "environment"
tagGitHash = "git.hash"
tagGitHashShort = "git.hash.short"
tagGitRepository = "git.repository"
tagGitBranch = "git.branch"
tagGitTag = "git.tag"
Expand Down
6 changes: 4 additions & 2 deletions engine/hooks/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ func fillPayload(pushEvent sdk.VCSPushEvent) map[string]string {
payload["git.author.email"] = pushEvent.Commit.Author.Email
payload["git.branch"] = strings.TrimPrefix(strings.TrimPrefix(pushEvent.Branch.DisplayID, "refs/heads/"), "refs/tags/")
payload["git.hash"] = pushEvent.Commit.Hash
if len(pushEvent.Commit.Hash) >= 7 {
payload["git.hash.short"] = pushEvent.Commit.Hash[:7]
hashShort := pushEvent.Commit.Hash
if len(hashShort) >= 7 {
hashShort = hashShort[:7]
}
payload["git.hash.short"] = hashShort
payload["git.repository"] = pushEvent.Repo
payload["cds.triggered_by.username"] = pushEvent.Commit.Author.DisplayName
payload["cds.triggered_by.fullname"] = pushEvent.Commit.Author.Name
Expand Down
18 changes: 12 additions & 6 deletions engine/hooks/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ func executeRepositoryWebHook(t *sdk.TaskExecution) ([]sdk.WorkflowNodeRunHookEv
}
payload["git.hash.before"] = pushEvent.Before
payload["git.hash"] = pushEvent.After
if len(pushEvent.After) >= 7 {
payload["git.hash.short"] = pushEvent.After[:7]
hashShort := pushEvent.After
if len(hashShort) >= 7 {
hashShort = hashShort[:7]
}
payload["git.hash.short"] = hashShort
payload["git.repository"] = pushEvent.Repository.FullName
payload["cds.triggered_by.username"] = pushEvent.HeadCommit.Author.Username
payload["cds.triggered_by.fullname"] = pushEvent.HeadCommit.Author.Name
Expand Down Expand Up @@ -102,9 +104,11 @@ func executeRepositoryWebHook(t *sdk.TaskExecution) ([]sdk.WorkflowNodeRunHookEv
}
payload["git.hash.before"] = pushEvent.Before
payload["git.hash"] = pushEvent.After
if len(pushEvent.After) >= 7 {
payload["git.hash.short"] = pushEvent.After[:7]
hashShort := pushEvent.After
if len(hashShort) >= 7 {
hashShort = hashShort[:7]
}
payload["git.hash.short"] = hashShort
payload["git.repository"] = pushEvent.Project.PathWithNamespace

payload["cds.triggered_by.username"] = pushEvent.UserUsername
Expand Down Expand Up @@ -145,9 +149,11 @@ func executeRepositoryWebHook(t *sdk.TaskExecution) ([]sdk.WorkflowNodeRunHookEv
}
payload["git.hash.before"] = pushChange.FromHash
payload["git.hash"] = pushChange.ToHash
if len(pushChange.ToHash) >= 7 {
payload["git.hash.short"] = pushChange.ToHash[:7]
hashShort := pushChange.ToHash
if len(hashShort) >= 7 {
hashShort = hashShort[:7]
}
payload["git.hash.short"] = hashShort
payload["git.repository"] = fmt.Sprintf("%s/%s", pushEvent.Repository.Project.Key, pushEvent.Repository.Slug)

payload["cds.triggered_by.username"] = pushEvent.Actor.Name
Expand Down
24 changes: 13 additions & 11 deletions engine/worker/builtin_gitclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,19 @@ func extractInfo(w *currentWorker, dir string, params *[]sdk.Parameter, tag, bra
return fmt.Errorf("Error on addVariableInPipelineBuild (hash): %s", err)
}

if len(info.Hash) >= 7 {
if _, err := w.addVariableInPipelineBuild(
sdk.Variable{
Name: "git.hash.short",
Type: sdk.StringVariable,
Value: info.Hash[:7],
},
params,
); err != nil {
return fmt.Errorf("Error on addVariableInPipelineBuild (hash): %s", err)
}
hashShort := info.Hash
if len(hashShort) >= 7 {
hashShort = hashShort[:7]
}
if _, err := w.addVariableInPipelineBuild(
sdk.Variable{
Name: "git.hash.short",
Type: sdk.StringVariable,
Value: hashShort,
},
params,
); err != nil {
return fmt.Errorf("Error on addVariableInPipelineBuild (hash): %s", err)
}
sendLog(fmt.Sprintf("git.hash: %s", info.Hash))
} else {
Expand Down

0 comments on commit ddf14fe

Please sign in to comment.