Skip to content

Commit

Permalink
'Tekton: Follow Log' command for PipelineRuns and TaskRuns
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhirverma committed Dec 6, 2019
1 parent dc0317a commit 922c693
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"onCommand:tekton.pipelinerun.list",
"onCommand:tekton.pipelinerun.describe",
"onCommand:tekton.pipelinerun.logs",
"onCommand:tekton.pipelinerun.followLogs",
"onCommand:tekton.pipelinerun.cancel",
"onCommand:tekton.pipelinerun.delete",
"onCommand:tekton.pipelineresource.list",
Expand All @@ -44,6 +45,7 @@
"onCommand:tekton.taskrun.list",
"onCommand:tekton.taskrun.listFromTask",
"onCommand:tekton.taskrun.logs",
"onCommand:tekton.taskrun.followLogs",
"onCommand:tekton.taskrun.delete",
"onCommand:tekton.explorer.refresh",
"onCommand:tekton.about",
Expand Down Expand Up @@ -132,6 +134,11 @@
"title": "Show Logs",
"category": "Tekton"
},
{
"command": "tekton.pipelinerun.followLogs",
"title": "Follow Logs",
"category": "Tekton"
},
{
"command": "tekton.pipelinerun.cancel",
"title": "Cancel",
Expand Down Expand Up @@ -187,6 +194,11 @@
"title": "Show Logs",
"category": "Tekton"
},
{
"command": "tekton.taskrun.followLogs",
"title": "Follow Logs",
"category": "Tekton"
},
{
"command": "tekton.taskrun.delete",
"title": "Delete",
Expand Down Expand Up @@ -274,6 +286,10 @@
"command": "tekton.pipelinerun.logs",
"when": "view == tektonPipelineExplorer"
},
{
"command": "tekton.pipelinerun.followLogs",
"when": "view == tektonPipelineExplorer"
},
{
"command": "tekton.pipelinerun.cancel",
"when": "view == tektonPipelineExplorer"
Expand Down Expand Up @@ -318,6 +334,10 @@
"command": "tekton.taskrun.logs",
"when": "view == tektonPipelineExplorer"
},
{
"command": "tekton.taskrun.followLogs",
"when": "view == tektonPipelineExplorer"
},
{
"command": "tekton.taskrun.delete",
"when": "view == tektonPipelineExplorer"
Expand Down Expand Up @@ -401,6 +421,11 @@
"when": "view == tektonPipelineExplorer && viewItem == pipelinerun",
"group": "c1@3"
},
{
"command": "tekton.pipelinerun.followLogs",
"when": "view == tektonPipelineExplorer && viewItem == pipelinerun",
"group": "c1@4"
},
{
"command": "tekton.pipelinerun.cancel",
"when": "view == tektonPipelineExplorer && viewItem == pipelinerun",
Expand Down Expand Up @@ -461,6 +486,11 @@
"when": "view == tektonPipelineExplorer && viewItem == taskrun",
"group": "c1"
},
{
"command": "tekton.taskrun.followLogs",
"when": "view == tektonPipelineExplorer && viewItem == taskrun",
"group": "c1@1"
},
{
"command": "tekton.taskrun.delete",
"when": "view == tektonPipelineExplorer && viewItem == taskrun",
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('tekton.pipelinerun.list', (context) => execute(PipelineRun.list, context)),
vscode.commands.registerCommand('tekton.pipelinerun.describe', (context) => execute(PipelineRun.describe, context)),
vscode.commands.registerCommand('tekton.pipelinerun.logs', (context) => execute(PipelineRun.logs, context)),
vscode.commands.registerCommand('tekton.pipelinerun.followLogs', (context) => execute(PipelineRun.followLog, context)),
vscode.commands.registerCommand('tekton.pipelinerun.cancel', (context) => execute(PipelineRun.cancel, context)),
vscode.commands.registerCommand('tekton.pipelinerun.delete', (context) => execute(PipelineRun.delete, context)),
vscode.commands.registerCommand('tekton.task.start', (context) => execute(Task.start, context)),
Expand All @@ -49,6 +50,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('tekton.taskrun.list', (context) => execute(TaskRun.list, context)),
vscode.commands.registerCommand('tekton.taskrun.listFromTask', (context) => execute(TaskRun.listFromTask, context)),
vscode.commands.registerCommand('tekton.taskrun.logs', (context) => execute(TaskRun.logs, context)),
vscode.commands.registerCommand('tekton.taskrun.followLogs', (context) => execute(TaskRun.followLog, context)),
// vscode.commands.registerCommand('tekton.taskrun.cancel', (context) => execute(TaskRun.cancel, context)),
vscode.commands.registerCommand('tekton.taskrun.delete', (context) => execute(TaskRun.delete, context)),
vscode.commands.registerCommand('tekton.explorer.reportIssue', () => PipelineExplorer.reportIssue()),
Expand Down
4 changes: 4 additions & 0 deletions src/tekton/pipelinerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class PipelineRun extends TektonItem {
if (pipelinerun) { PipelineRun.tkn.executeInTerminal(Command.showPipelineRunLogs(pipelinerun.getName())); }
}

static async followLog(pipelinerun: TektonNode): Promise<void> {
PipelineRun.tkn.executeInTerminal(Command.showPipelineRunFollowLogs(pipelinerun.getName()));
}

static async cancel(pipelinerun: TektonNode): Promise<void> {
if (pipelinerun) { PipelineRun.tkn.executeInTerminal(Command.cancelPipelineRun(pipelinerun.getName())); }
}
Expand Down
4 changes: 4 additions & 0 deletions src/tekton/taskrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class TaskRun extends TektonItem {
if (taskrun) { TaskRun.tkn.executeInTerminal(Command.showTaskRunLogs(taskrun.getName())); }
}

static async followLog(taskrun: TektonNode): Promise<void> {
TaskRun.tkn.executeInTerminal(Command.showTaskRunFollowLogs(taskrun.getName()));
}

static async delete(taskrun: TektonNode): Promise<void> {
if (taskrun) { TaskRun.tkn.executeInTerminal(Command.deleteTaskRun(taskrun.getName())); }
}
Expand Down
8 changes: 8 additions & 0 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ export class Command {
return `tkn version`;
}

static showPipelineRunFollowLogs(name: string) {
return `tkn pipelinerun logs ${name} -f`;
}

static showTaskRunFollowLogs(name: string) {
return `tkn taskrun logs ${name} -f`;
}

}

export class TektonNodeImpl implements TektonNode {
Expand Down
10 changes: 10 additions & 0 deletions test/tekton/pipelinerun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ suite('Tekton/PipelineRun', () => {

});

suite('followLog', () => {

test('followLog calls the correct tkn command in terminal', async () => {
await PipelineRun.followLog(pipelinerunItem);

expect(termStub).calledOnceWith(Command.showPipelineRunFollowLogs(pipelinerunItem.getName()));
});

});

suite('cancel', () => {

setup(() => {
Expand Down
11 changes: 11 additions & 0 deletions test/tekton/taskrun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ suite('Tekton/TaskRun', () => {
});

});

suite('followLog', () => {

test('followLog calls the correct tkn command in terminal', async () => {
await TaskRun.followLog(taskrunItem);

expect(termStub).calledOnceWith(Command.showTaskRunFollowLogs(taskrunItem.getName()));
});

});

suite('delete', () => {

test('delete calls the correct tkn command in terminal', async () => {
Expand Down

0 comments on commit 922c693

Please sign in to comment.