Skip to content

Commit

Permalink
feat: add the link of target template (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen authored Jan 8, 2023
1 parent 516bd15 commit 232e69b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 13 additions & 0 deletions cmd/argoworkflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,20 @@ func (e *DefaultPluginExecutor) Execute(args executor.ExecuteTemplateArgs, wf *w
if wf.Annotations == nil {
wf.Annotations = map[string]string{}
}

var templatePath string
if wf.Spec.WorkflowTemplateRef.ClusterScope {
templatePath = "cluster-workflow-templates"
} else {
templatePath = "workflow-templates"
}
targetTemplateAddress := fmt.Sprintf("%s/%s/%s/%s",
opt.Option.Target,
templatePath,
args.Workflow.ObjectMeta.Namespace,
wf.Spec.WorkflowTemplateRef.Name)
wf.Annotations["workflow.link"] = targetAddress
wf.Annotations["workflow.templatelink"] = targetTemplateAddress

var message string
message, err = template.RenderTemplate(tplText, wf)
Expand Down
2 changes: 1 addition & 1 deletion cmd/argoworkflow/template/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

// CommentTemplate is the default comment template
const CommentTemplate = `
{{.Spec.WorkflowTemplateRef.Name}} is {{.Status.Phase}}. It takes {{duration .Status.FinishedAt .Status.StartedAt}}. Please check log output from [here]({{get .Annotations "workflow.link"}}).
[{{.Spec.WorkflowTemplateRef.Name}}]({{get .Annotations "workflow.templatelink"}}) is {{.Status.Phase}}. It takes {{duration .Status.FinishedAt .Status.StartedAt}}. Please check log output from [here]({{get .Annotations "workflow.link"}}).
| Stage | Status | Duration |
|---|---|---|
Expand Down
5 changes: 3 additions & 2 deletions cmd/argoworkflow/template/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func TestCommentTemlate(t *testing.T) {
object := map[string]interface{}{}
object["Status"] = status
object["Annotations"] = map[string]string{
"workflow.link": "https://github.com/linxusuren/gogit",
"workflow.link": "https://github.com/linxusuren/gogit",
"workflow.templatelink": "https://github.com/linxusuren/gogit.git",
}
object["Spec"] = map[string]interface{}{
"WorkflowTemplateRef": map[string]string{
Expand All @@ -45,7 +46,7 @@ func TestCommentTemlate(t *testing.T) {
result, err := template.RenderTemplate(template.CommentTemplate, object)
assert.Nil(t, err)
assert.Equal(t, `
Sample is Failed. It takes 5s. Please check log output from [here](https://github.com/linxusuren/gogit).
[Sample](https://github.com/linxusuren/gogit.git) is Failed. It takes 5s. Please check log output from [here](https://github.com/linxusuren/gogit).
| Stage | Status | Duration |
|---|---|---|
Expand Down

0 comments on commit 232e69b

Please sign in to comment.