Skip to content

Commit

Permalink
Add --last to tkn pac logs
Browse files Browse the repository at this point in the history
And make all the help messages uses it instead of tkn pr directly

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Nov 24, 2022
1 parent 9e010b7 commit 8bebeb6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/content/docs/guide/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ You can follow the execution of your pipeline with the
[tkn](https://github.com/tektoncd/cli) cli :

```console
tkn pr logs -n my-pipeline-ci -Lf
tkn pac logs -n my-pipeline-ci -L
```

If you need to show another pipelinerun than the last one you
Expand Down
23 changes: 17 additions & 6 deletions pkg/cmd/tknpac/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ tkn pac logs will get the logs of a PipelineRun belonging to a Repository.
the PipelineRun needs to exist on the kubernetes cluster to be able to display the logs.`

const (
namespaceFlag = "namespace"
limitFlag = "limit"
tknPathFlag = "tkn-path"
defaultLimit = -1
openWebBrowserFlag = "web"
namespaceFlag = "namespace"
limitFlag = "limit"
tknPathFlag = "tkn-path"
defaultLimit = -1
openWebBrowserFlag = "web"
useLastPipelineRunFlag = "last"
)

type logOption struct {
Expand All @@ -51,6 +52,7 @@ type logOption struct {
tknPath string
limit int
webBrowser bool
useLastPR bool
}

func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
Expand Down Expand Up @@ -92,6 +94,11 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
return err
}

useLastPR, err := cmd.Flags().GetBool(useLastPipelineRunFlag)
if err != nil {
return err
}

tknPath, err := cmd.Flags().GetString(tknPathFlag)
if err != nil {
return err
Expand All @@ -115,6 +122,7 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
limit: limit,
webBrowser: webBrowser,
tknPath: tknPath,
useLastPR: useLastPR,
}
return log(ctx, lopts)
},
Expand All @@ -134,6 +142,9 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
cmd.Flags().BoolP(
openWebBrowserFlag, "w", false, "Open Web browser to detected console instead of using tkn")

cmd.Flags().BoolP(
useLastPipelineRunFlag, "L", false, "show logs of the last PipelineRun")

cmd.Flags().IntP(
limitFlag, "", defaultLimit, "Limit the number of PipelineRun to show (-1 is unlimited)")

Expand Down Expand Up @@ -213,7 +224,7 @@ func log(ctx context.Context, lo *logOption) error {
return fmt.Errorf("cannot detect pipelineruns belonging to repository: %s", repository.GetName())
}
var replyString string
if len(allprs) == 1 {
if lo.useLastPR || len(allprs) == 1 {
replyString = allprs[0]
} else {
if err := prompt.SurveyAskOne(&survey.Select{
Expand Down
17 changes: 17 additions & 0 deletions pkg/cmd/tknpac/logs/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestLogs(t *testing.T) {
currentNamespace string
shift int
pruns []*tektonv1beta1.PipelineRun
useLastPR bool
}{
{
name: "good/show logs",
Expand All @@ -48,6 +49,21 @@ func TestLogs(t *testing.T) {
}, 30),
},
},
{
name: "good/show logs",
wantErr: false,
repoName: "test",
currentNamespace: ns,
useLastPR: true,
pruns: []*tektonv1beta1.PipelineRun{
tektontest.MakePRCompletion(cw, "test-pipeline", ns, completed, map[string]string{
keys.Repository: "test",
}, 30),
tektontest.MakePRCompletion(cw, "test-pipeline2", ns, completed, map[string]string{
keys.Repository: "test",
}, 30),
},
},
{
name: "bad/shift",
wantErr: true,
Expand Down Expand Up @@ -116,6 +132,7 @@ func TestLogs(t *testing.T) {
limit: 1,
tknPath: tknPath,
ioStreams: io,
useLastPR: tt.useLastPR,
}

err = log(ctx, lopts)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipelineascode/pipelineascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
startingPipelineRunText = `Starting Pipelinerun <b>%s</b> in namespace
<b>%s</b><br><br>You can follow the execution on the [OpenShift console](%s) pipelinerun viewer or via
the command line with :
<br><code>tkn pr logs -f -n %s %s</code>`
<br><code>tkn pac logs -L -n %s %s</code>`
queuingPipelineRunText = `PipelineRun <b>%s</b> has been queued Queuing in namespace
<b>%s</b><br><br>`
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
const startingPipelineRunText = `Starting Pipelinerun <b>%s</b> in namespace
<b>%s</b><br><br>You can follow the execution on the [OpenShift console](%s) pipelinerun viewer or via
the command line with :
<br><code>tkn pr logs -f -n %s %s</code>`
<br><code>tkn pac logs -L -n %s %s</code>`

type Reconciler struct {
run *params.Run
Expand Down

0 comments on commit 8bebeb6

Please sign in to comment.