Repository: openshift-pipelines/pipelines-as-code
Pull request #170 (2021-06-30 07:28:16)

Let's make sure it's called Pipelines as Code
- Let's make sure it's called Pipelines as Code
- Allow symlink tkn-pac to pipelines-as-code



Patch:
diff --git a/Dockerfile b/Dockerfile
index 9f399a30..8f1eb282 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,17 +3,16 @@ FROM registry.access.redhat.com/ubi8/go-toolset:latest	 AS builder
 COPY . /src
 WORKDIR /src
 RUN go build -mod=vendor -v -o /tmp/pipelines-as-code ./cmd/pipelines-as-code && strip /tmp/pipelines-as-code
-RUN go build -mod=vendor -v -o /tmp/tkn-pac ./cmd/tkn-pac && strip /tmp/tkn-pac
 
 FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4
 
 LABEL com.redhat.component=pipelines-as-code \ 
     name=openshift-pipelines/pipelines-as-code \ 
     maintainer=pipelines@redhat.com \ 
-    summary="This image is to run Pipeline as Code task"
+    summary="This image is to run Pipelines as Code task"
 
 LABEL version=0.1.0
 
 COPY --from=builder /tmp/pipelines-as-code /usr/bin/pipelines-as-code
-COPY --from=builder /tmp/tkn-pac /usr/bin/tkn-pac
+RUN ln -s /usr/bin/pipelines-as-code /usr/bin/tkn-pac
 CMD ["/usr/bin/pipelines-as-code"]
diff --git a/README.md b/README.md
index cfc81147..6a3c5131 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,7 @@ feature you need to add this annotation :
 pipelinesascode.tekton.dev/target-namespace: "mynamespace"
 ```
 
-and Pipeline as Code will only match the repository in the mynamespace Namespace
+and Pipelines as Code will only match the repository in the mynamespace Namespace
 instead of trying to match it from all available repository on cluster.
 
 ### Writting Tekton pipelines in `.tekton/` directory
@@ -310,7 +310,7 @@ with a short recap of how long each task of your pipeline took and the output of
 
 If there was a failure you can click on the "Re-Run" button on the left to rerun
 the Pipeline or you can issue a issue comment with a line starting and finishing
-with the string `/retest` to ask Pipeline as Code to retest the current PR.
+with the string `/retest` to ask Pipelines as Code to retest the current PR.
 
 Example :
 
@@ -385,7 +385,7 @@ Pipelines as Code reuse this for its push pipeline, see it here :
 
 ## CLI
 
-`Pipeline as Code` provide a CLI which is design to work as tkn plugin.
+`Pipelines as Code` provide a CLI which is design to work as tkn plugin.
 
 Install it like this :
 
@@ -506,7 +506,7 @@ so GitHub can get send the webhook to it.
 Pipelines as Code supports Github Enterprise.
 
 You don't need to do anything special to get Pipelines as code working with GHE.
-Pipeline as code will automatically detects the header as set from GHE and use it  the GHE API auth url instead of the public github.
+Pipelines as code will automatically detects the header as set from GHE and use it  the GHE API auth url instead of the public github.
 
 ### PR cleanups in pipelines-as-code admin namespace
 
diff --git a/cmd/pipelines-as-code/main.go b/cmd/pipelines-as-code/main.go
index 523dd182..469f5158 100644
--- a/cmd/pipelines-as-code/main.go
+++ b/cmd/pipelines-as-code/main.go
@@ -1,17 +1,35 @@
 package main
 
 import (
+	"fmt"
 	"os"
+	"path/filepath"
 
 	"github.com/openshift-pipelines/pipelines-as-code/pkg/cli"
 	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/pipelineascode"
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/tknpac"
+	"github.com/spf13/cobra"
 )
 
-func main() {
+// RouteBinary according to $0
+func RouteBinary(binary string) *cobra.Command {
 	tp := &cli.PacParams{}
-	pac := pipelineascode.Command(tp)
+	if filepath.Base(binary) == "pipelines-as-code" {
+		return pipelineascode.Command(tp)
+	}
+	return tknpac.Root(tp)
+}
+
+func main() {
+	executable, err := os.Executable()
+	if err != nil {
+		fmt.Fprint(os.Stderr, err.Error())
+		os.Exit(1)
+	}
+
+	cmd := RouteBinary(executable)
 
-	if err := pac.Execute(); err != nil {
+	if err := cmd.Execute(); err != nil {
 		os.Exit(1)
 	}
 }
diff --git a/cmd/tkn-pac/main.go b/cmd/tkn-pac/main.go
index 04ede114..fbaa32fc 100644
--- a/cmd/tkn-pac/main.go
+++ b/cmd/tkn-pac/main.go
@@ -4,35 +4,12 @@ import (
 	"os"
 
 	"github.com/openshift-pipelines/pipelines-as-code/pkg/cli"
-	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/completion"
-	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/repository"
-	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/resolve"
-	"github.com/openshift-pipelines/pipelines-as-code/pkg/flags"
-	"github.com/spf13/cobra"
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/tknpac"
 )
 
-func Root(p cli.Params) *cobra.Command {
-	cmd := &cobra.Command{
-		Use:          "tkn-pac",
-		Short:        "Pipeline as Code CLI",
-		Long:         `This is the Pipelines as Code`,
-		SilenceUsage: true,
-		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
-			return flags.InitParams(p, cmd)
-		},
-	}
-	flags.AddPacOptions(cmd)
-
-	cmd.AddCommand(repository.Root(p))
-	cmd.AddCommand(resolve.Command(p))
-	cmd.AddCommand(completion.Command())
-
-	return cmd
-}
-
 func main() {
 	tp := &cli.PacParams{}
-	pac := Root(tp)
+	pac := tknpac.Root(tp)
 
 	if err := pac.Execute(); err != nil {
 		os.Exit(1)
diff --git a/pkg/cmd/pipelineascode/pipelineascode.go b/pkg/cmd/pipelineascode/pipelineascode.go
index 8076e7dd..a2915513 100644
--- a/pkg/cmd/pipelineascode/pipelineascode.go
+++ b/pkg/cmd/pipelineascode/pipelineascode.go
@@ -22,8 +22,8 @@ const (
 func Command(p cli.Params) *cobra.Command {
 	opts := &pacpkg.Options{}
 	cmd := &cobra.Command{
-		Use:   "run",
-		Short: "Run pipelines as code",
+		Use:   "pipelines-as-code",
+		Short: "Pipelines as code Run",
 		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
 			return flags.GetWebCVSOptions(p, cmd)
 		},
diff --git a/pkg/cmd/repository/root.go b/pkg/cmd/repository/root.go
index 4c0b9d4c..0827823b 100644
--- a/pkg/cmd/repository/root.go
+++ b/pkg/cmd/repository/root.go
@@ -10,8 +10,8 @@ func Root(p cli.Params) *cobra.Command {
 	cmd := &cobra.Command{
 		Use:          "repository",
 		Aliases:      []string{"repo", "repsitories"},
-		Short:        "Pipeline as Code repositories",
-		Long:         `Manage Pipeline as Code repositories`,
+		Short:        "Pipelines as Code repositories",
+		Long:         `Manage Pipelines as Code repositories`,
 		SilenceUsage: true,
 	}
 	ioStreams := ui.NewIOStreams()
diff --git a/pkg/cmd/tknpac/root.go b/pkg/cmd/tknpac/root.go
new file mode 100644
index 00000000..5dc92679
--- /dev/null
+++ b/pkg/cmd/tknpac/root.go
@@ -0,0 +1,29 @@
+package tknpac
+
+import (
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/cli"
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/completion"
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/repository"
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/resolve"
+	"github.com/openshift-pipelines/pipelines-as-code/pkg/flags"
+	"github.com/spf13/cobra"
+)
+
+func Root(p cli.Params) *cobra.Command {
+	cmd := &cobra.Command{
+		Use:          "tkn-pac",
+		Short:        "Pipelines as Code CLI",
+		Long:         `This is the Pipelines as Code CLI`,
+		SilenceUsage: true,
+		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
+			return flags.InitParams(p, cmd)
+		},
+	}
+	flags.AddPacOptions(cmd)
+
+	cmd.AddCommand(repository.Root(p))
+	cmd.AddCommand(resolve.Command(p))
+	cmd.AddCommand(completion.Command())
+
+	return cmd
+}
diff --git a/pkg/flags/flags.go b/pkg/flags/flags.go
index be9a4c54..d2f83d39 100644
--- a/pkg/flags/flags.go
+++ b/pkg/flags/flags.go
@@ -14,7 +14,7 @@ const (
 	apiURLFlag = "api-url"
 )
 
-// PacOptions holds struct of Pipeline as code Options
+// PacOptions holds struct of Pipelines as code Options
 type PacOptions struct {
 	KubeConfig, GithubToken, GithubAPIURL string
 }
diff --git a/pkg/webvcs/github.go b/pkg/webvcs/github.go
index bb50b3b9..c42c1ae3 100644
--- a/pkg/webvcs/github.go
+++ b/pkg/webvcs/github.go
@@ -390,7 +390,7 @@ func (v GithubVCS) GetObject(ctx context.Context, sha string, runinfo *RunInfo)
 func (v GithubVCS) CreateCheckRun(ctx context.Context, status string, runinfo *RunInfo) (*github.CheckRun, error) {
 	now := github.Timestamp{Time: time.Now()}
 	checkrunoption := github.CreateCheckRunOptions{
-		Name:       "Tekton Pipeline as Code CI",
+		Name:       "Pipelines as Code CI",
 		HeadSHA:    runinfo.SHA,
 		Status:     &status,
 		DetailsURL: &runinfo.WebConsoleURL,
@@ -428,7 +428,7 @@ func (v GithubVCS) CreateStatus(ctx context.Context, runinfo *RunInfo, status, c
 	}
 
 	opts := github.UpdateCheckRunOptions{
-		Name:   "Tekton Pipeline as Code CI",
+		Name:   "Pipelines as Code CI",
 		Status: &status,
 		Output: checkRunOutput,
 	}


Test patch:
diff --git a/cmd/pipelines-as-code/main_test.go b/cmd/pipelines-as-code/main_test.go
new file mode 100644
index 00000000..fb012e9b
--- /dev/null
+++ b/cmd/pipelines-as-code/main_test.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+	"testing"
+
+	"gotest.tools/v3/assert"
+)
+
+func TestRouteBinary(t *testing.T) {
+	tests := []struct {
+		name  string
+		short string
+	}{
+		{
+			name:  "pipelines-as-code",
+			short: "Pipelines as code Run",
+		},
+		{
+			name:  "tkn-pac",
+			short: "Pipelines as Code CLI",
+		},
+		{
+			name:  "anything-else",
+			short: "Pipelines as Code CLI",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			assert.Equal(t, RouteBinary(tt.name).Short, tt.short)
+		})
+	}
+}