Repository: openshift-pipelines/pipelines-as-code
Pull request #99 (2021-05-31 14:30:50)

Add direct link to TaskRun in CheckRun task list
Adding a clickable full link to the taskrun

GitHUB markdown format was pretty weird to figure out why it wasn't
parsing the links, converting all of this as HTML, you still need some
weird space so link can appears see (https://git.io/JGBZ9)

Will show like this : 

![image](https://user-images.githubusercontent.com/98980/120208597-f2ef0680-c22d-11eb-9125-888c3db38618.png)


We probably should start thinking introducing golden to test template output.

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>


Patch:
diff --git a/pkg/pipelineascode/status.go b/pkg/pipelineascode/status.go
index f7c84abf..eb135f7e 100644
--- a/pkg/pipelineascode/status.go
+++ b/pkg/pipelineascode/status.go
@@ -28,18 +28,30 @@ const checkStatustmpl = `{{.taskStatus}}
 `
 
 const taskStatustmpl = `
-| Status | Duration | Name |
-| --- | --- | --- |
+<table>
+  <tr><th>Status</th><th>Duration</th><th>Name</th></tr>
 
-{{- range $taskrun := .TaskrunList }}
-{{ formatCondition $taskrun.Status.Conditions }} | {{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }} | {{ $taskrun.PipelineTaskName }}
-{{- end }}`
+{{- range $taskrun := .TaskRunList }}
+<tr>
+<td>{{ formatCondition $taskrun.Status.Conditions }}</td>
+<td>{{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }}</td><td>
+
+{{ $taskrun.ConsoleLogURL }}
+
+</td></tr>
+{{- end }}
+</table>`
 
 type tkr struct {
 	TaskrunName string
+	LogURL      string
 	*tektonv1beta1.PipelineRunTaskRunStatus
 }
 
+func (t tkr) ConsoleLogURL() string {
+	return fmt.Sprintf("[%s](%s/%s)", t.PipelineTaskName, t.LogURL, t.PipelineTaskName)
+}
+
 type taskrunList []tkr
 
 func (trs taskrunList) Len() int      { return len(trs) }
@@ -56,11 +68,12 @@ func (trs taskrunList) Less(i, j int) bool {
 	return trs[j].Status.StartTime.Before(trs[i].Status.StartTime)
 }
 
-func newTaskrunListFromMap(statusMap map[string]*tektonv1beta1.PipelineRunTaskRunStatus) taskrunList {
+func newTaskrunListFromMap(statusMap map[string]*tektonv1beta1.PipelineRunTaskRunStatus, consoleURL string) taskrunList {
 	trl := taskrunList{}
 	for taskrunName, taskrunStatus := range statusMap {
 		trl = append(trl, tkr{
 			taskrunName,
+			consoleURL,
 			taskrunStatus,
 		})
 	}
@@ -98,12 +111,12 @@ func ConditionEmoji(c knative1.Conditions) string {
 	return status
 }
 
-func statusOfAllTaskListForCheckRun(pr *tektonv1beta1.PipelineRun) (string, error) {
+func statusOfAllTaskListForCheckRun(pr *tektonv1beta1.PipelineRun, consoleURL string) (string, error) {
 	var trl taskrunList
 	var outputBuffer bytes.Buffer
 
 	if len(pr.Status.TaskRuns) != 0 {
-		trl = newTaskrunListFromMap(pr.Status.TaskRuns)
+		trl = newTaskrunListFromMap(pr.Status.TaskRuns, consoleURL)
 		sort.Sort(sort.Reverse(trl))
 	}
 
@@ -113,9 +126,9 @@ func statusOfAllTaskListForCheckRun(pr *tektonv1beta1.PipelineRun) (string, erro
 	}
 
 	data := struct {
-		TaskrunList taskrunList
+		TaskRunList taskrunList
 	}{
-		TaskrunList: trl,
+		TaskRunList: trl,
 	}
 
 	t := template.Must(template.New("Task Status").Funcs(funcMap).Parse(taskStatustmpl))
@@ -146,7 +159,7 @@ func postFinalStatus(ctx context.Context, cs *cli.Clients, k8int cli.KubeInterac
 		consoleURL = "https://giphy.com/search/cat-reading"
 	}
 
-	taskStatus, err := statusOfAllTaskListForCheckRun(pr)
+	taskStatus, err := statusOfAllTaskListForCheckRun(pr, consoleURL)
 	if err != nil {
 		return pr, err
 	}


Test patch:
diff --git a/pkg/pipelineascode/status_test.go b/pkg/pipelineascode/status_test.go
index 1a993bc7..8d9e1967 100644
--- a/pkg/pipelineascode/status_test.go
+++ b/pkg/pipelineascode/status_test.go
@@ -103,7 +103,7 @@ func TestTaskRunListMapSort(t *testing.T) {
 		"middle": pstatus(10),
 	}
 
-	trlist := newTaskrunListFromMap(status)
+	trlist := newTaskrunListFromMap(status, "http://hello")
 	sort.Sort(trlist)
 	assert.Equal(t, trlist[0].TaskrunName, "last")
 	assert.Equal(t, trlist[1].TaskrunName, "middle")
@@ -111,13 +111,13 @@ func TestTaskRunListMapSort(t *testing.T) {
 
 	// Not sorting the middle one since no status, comes first then
 	status["middle"].Status.TaskRunStatusFields.StartTime = nil
-	trlist = newTaskrunListFromMap(status)
+	trlist = newTaskrunListFromMap(status, "http://moto")
 	sort.Sort(trlist)
 	assert.Equal(t, trlist[0].TaskrunName, "middle")
 
 	// Only last become sorted because middle and first has been removed
 	status["first"].Status.TaskRunStatusFields.StartTime = nil
-	trlist = newTaskrunListFromMap(status)
+	trlist = newTaskrunListFromMap(status, "http://moto")
 	sort.Sort(trlist)
 	assert.Equal(t, trlist[len(trlist)-1].TaskrunName, "last")
 }