Repository: openshift-pipelines/pipelines-as-code
Pull request #29 (2021-05-04 12:17:45)

Make sure we catch errors when we can't get the console url

codecov-commenter: # [Codecov](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#29](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (5e12850) into [main](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/commit/963f34300ad1d30bd2c98eeacac009d9317a9a21?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (963f343) will **not change** coverage.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29/graphs/tree.svg?width=650&height=150&src=pr&token=XOBPWX11IU&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

```diff
@@           Coverage Diff           @@
##             main      #29   +/-   ##
=======================================
  Coverage   63.18%   63.18%           
=======================================
  Files           7        7           
  Lines         459      459           
=======================================
  Hits          290      290           
  Misses        136      136           
  Partials       33       33           
```


| [Impacted Files](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [pkg/cmd/pipelineascode/pipelineascode.go](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cGtnL2NtZC9waXBlbGluZWFzY29kZS9waXBlbGluZWFzY29kZS5nbw==) | `21.15% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [963f343...5e12850](https://codecov.io/gh/openshift-pipelines/pipelines-as-code/pull/29?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/config/200-role.yaml b/config/200-role.yaml
index 86554e27..28579d18 100644
--- a/config/200-role.yaml
+++ b/config/200-role.yaml
@@ -95,7 +95,6 @@ rules:
   - apiGroups: ["tekton.dev"]
     resources: ["taskruns"]
     verbs: ["get"]
-
 ---
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
diff --git a/pkg/cli/interface.go b/pkg/cli/interface.go
index 1873b35e..d916d358 100644
--- a/pkg/cli/interface.go
+++ b/pkg/cli/interface.go
@@ -36,7 +36,7 @@ type Params interface {
 }
 
 type KubeInteractionIntf interface {
-	GetConsoleUI(string, string) string
+	GetConsoleUI(string, string) (string, error)
 	GetNamespace(string) error
 	TektonCliPRDescribe(string, string) (string, error)
 	TektonCliFollowLogs(string, string) (string, error)
diff --git a/pkg/cmd/pipelineascode/pipelineascode.go b/pkg/cmd/pipelineascode/pipelineascode.go
index 8e9aac7a..0d47812c 100644
--- a/pkg/cmd/pipelineascode/pipelineascode.go
+++ b/pkg/cmd/pipelineascode/pipelineascode.go
@@ -13,6 +13,10 @@ import (
 	"github.com/spf13/cobra"
 )
 
+const (
+	defaultURL = "https://giphy.com/explore/cat"
+)
+
 func Command(p cli.Params) *cobra.Command {
 	opts := &pacpkg.Options{}
 	var cmd = &cobra.Command{
@@ -91,7 +95,12 @@ func runWrap(p cli.Params, opts *pacpkg.Options) error {
 	}
 
 	// Get webconsole url as soon as possible to have a link to click there
-	runinfo.WebConsoleURL = kinteract.GetConsoleUI("", "")
+	url, err := kinteract.GetConsoleUI("", "")
+	if err != nil {
+		cs.Log.Error(err)
+		url = defaultURL
+	}
+	runinfo.WebConsoleURL = url
 
 	err = pacpkg.Run(cs, kinteract, runinfo)
 	if err != nil && !strings.Contains(err.Error(), "403 Resource not accessible by integration") {
diff --git a/pkg/consoleui/consoleui.go b/pkg/consoleui/consoleui.go
index b8c2f940..bfcabf6a 100644
--- a/pkg/consoleui/consoleui.go
+++ b/pkg/consoleui/consoleui.go
@@ -23,6 +23,7 @@ const (
 func getOpenshiftConsole(cs *cli.Clients, ns, pr string) (string, error) {
 	gvr := schema.GroupVersionResource{Group: openShiftRouteGroup, Version: openShiftRouteVersion, Resource: openShiftRouteResource}
 	route, err := cs.Dynamic.Resource(gvr).Namespace(openShiftConsoleNS).Get(context.Background(), openShiftConsoleRouteName, metav1.GetOptions{})
+
 	if err != nil {
 		return "", err
 	}
@@ -49,14 +50,13 @@ func getOpenshiftConsole(cs *cli.Clients, ns, pr string) (string, error) {
 
 // GetConsoleURL Get a Console URL, OpenShift Console or Tekton Dashboard.
 // don't error if we can't find it.
-func GetConsoleUI(cs *cli.Clients, ns, pr string) string {
+func GetConsoleUI(cs *cli.Clients, ns, pr string) (string, error) {
 	var url string
 	var err error
-	if url, err = getOpenshiftConsole(cs, ns, pr); err != nil {
-		cs.Log.Debug("cannot find an openshift console on this cluster: %v", err)
+	url, err = getOpenshiftConsole(cs, ns, pr)
+	if err != nil {
+		return "", err
 	}
-
-	cs.Log.Info(url)
-
-	return url
+	cs.Log.Info("Console view url: %s", url)
+	return url, nil
 }
diff --git a/pkg/kubeinteraction/kubeinteraction.go b/pkg/kubeinteraction/kubeinteraction.go
index 88398b44..b9650da4 100644
--- a/pkg/kubeinteraction/kubeinteraction.go
+++ b/pkg/kubeinteraction/kubeinteraction.go
@@ -12,7 +12,7 @@ type Interaction struct {
 	TektonCliLogsOptions clioptions.LogOptions
 }
 
-func (k Interaction) GetConsoleUI(ns, pr string) string {
+func (k Interaction) GetConsoleUI(ns, pr string) (string, error) {
 	return consoleui.GetConsoleUI(k.Clients, ns, pr)
 }
 
diff --git a/pkg/pipelineascode/pipelineascode.go b/pkg/pipelineascode/pipelineascode.go
index 5febab3c..dc73d2e2 100644
--- a/pkg/pipelineascode/pipelineascode.go
+++ b/pkg/pipelineascode/pipelineascode.go
@@ -146,10 +146,16 @@ func Run(cs *cli.Clients, k8int cli.KubeInteractionIntf, runinfo *webvcs.RunInfo
 		return err
 	}
 
-	runinfo.WebConsoleURL = k8int.GetConsoleUI(repo.Spec.Namespace, pr.GetName())
+	consoleURL, err := k8int.GetConsoleUI(repo.Spec.Namespace, pr.GetName())
+	if err != nil {
+		// Don't bomb out if we can't get the console UI
+		consoleURL = "https://giphy.com/explore/cat-exercise-wheel"
+	}
+
 	_, err = cs.GithubClient.CreateStatus(runinfo, "in_progress", "",
-		fmt.Sprintf("Starting Pipelinerun <b>%s</b> in namespace <b>%s</b>", pr.GetName(), repo.Spec.Namespace),
-		runinfo.WebConsoleURL)
+		fmt.Sprintf(`Starting Pipelinerun <b>%s</b> in namespace <b>%s</b><br><br>You can follow the execution on the command line with : <br><br><code>tkn pr logs -f -n %s %s</code>`,
+			pr.GetName(), repo.Spec.Namespace, repo.Spec.Namespace, pr.GetName()),
+		consoleURL)
 	if err != nil {
 		return nil
 	}
diff --git a/pkg/pipelineascode/status.go b/pkg/pipelineascode/status.go
index 357f9da0..3577198d 100644
--- a/pkg/pipelineascode/status.go
+++ b/pkg/pipelineascode/status.go
@@ -141,7 +141,10 @@ func postFinalStatus(ctx context.Context, cs *cli.Clients, k8int cli.KubeInterac
 		return pr, err
 	}
 
-	runinfo.WebConsoleURL = k8int.GetConsoleUI(namespace, pr.Name)
+	consoleURL, err := k8int.GetConsoleUI(namespace, pr.Name)
+	if err != nil {
+		consoleURL = "https://giphy.com/search/cat-reading"
+	}
 
 	taskStatus, err := statusOfAllTaskListForCheckRun(pr)
 	if err != nil {
@@ -161,7 +164,7 @@ func postFinalStatus(ctx context.Context, cs *cli.Clients, k8int cli.KubeInterac
 
 	_, err = cs.GithubClient.CreateStatus(runinfo,
 		"completed", pipelineRunStatus(pr),
-		outputBuffer.String(), runinfo.WebConsoleURL)
+		outputBuffer.String(), consoleURL)
 
 	return pr, err
 }


Test patch:
diff --git a/pkg/test/kubernetesintf.go b/pkg/test/kubernetesintf.go
index ffb63272..d4490054 100644
--- a/pkg/test/kubernetesintf.go
+++ b/pkg/test/kubernetesintf.go
@@ -9,8 +9,8 @@ type KinterfaceTest struct {
 	prDescribe string
 }
 
-func (k *KinterfaceTest) GetConsoleUI(ns string, pr string) string {
-	return k.ConsoleURL
+func (k *KinterfaceTest) GetConsoleUI(ns string, pr string) (string, error) {
+	return k.ConsoleURL, nil
 }
 
 func (k *KinterfaceTest) GetNamespace(ns string) error {