Skip to content

Commit

Permalink
Add support for ClusterTriggerBinding resource (#283)
Browse files Browse the repository at this point in the history
* Add support for ClusterTriggerBinding resource
  • Loading branch information
sudhirverma authored May 18, 2020
1 parent 13e0916 commit a923769
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,12 @@
},
{
"command": "tekton.edit",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem =~ /^(pipeline|pipelinerun|clustertask|pipelineresource|taskrun|triggertemplates|triggerbinding|eventlistener|conditions|task)$/",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem =~ /^(pipeline|pipelinerun|clustertask|pipelineresource|taskrun|triggertemplates|triggerbinding|eventlistener|conditions|task|clustertriggerbinding)$/",
"group": "inline"
},
{
"command": "tekton.openInEditor",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem =~ /^(pipeline|pipelinerun|clustertask|pipelineresource|taskrun|task|triggertemplates|triggerbinding|eventlistener|conditions)$/",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem =~ /^(pipeline|pipelinerun|clustertask|pipelineresource|taskrun|task|triggertemplates|triggerbinding|eventlistener|conditions|clustertriggerbinding)$/",
"group": "c0@1"
}
],
Expand Down
23 changes: 22 additions & 1 deletion src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export enum ContextType {
TRIGGERTEMPLATES = 'triggertemplates',
TRIGGERBINDINGNODE = 'triggerbindingnode',
TRIGGERBINDING = 'triggerbinding',
CLUSTERTRIGGERBINDINGNODE = 'clustertriggerbindingnode',
CLUSTERTRIGGERBINDING = 'clustertriggerbinding',
EVENTLISTENERNODE = 'eventlistenernode',
EVENTLISTENER = 'eventlistener',
CONDITIONSNODE = 'conditionsnode',
Expand Down Expand Up @@ -209,6 +211,9 @@ export class Command {
static listTriggerBinding(): CliCommand {
return newK8sCommand('get', 'triggerbinding', '-o', 'json');
}
static listClusterTriggerBinding(): CliCommand {
return newK8sCommand('get', 'clustertriggerbinding', '-o', 'json');
}
@verbose
static listEventListener(): CliCommand {
return newK8sCommand('get', 'eventlistener', '-o', 'json');
Expand Down Expand Up @@ -429,6 +434,16 @@ export class TektonNodeImpl implements TektonNode {
tooltip: 'TriggerBinding: {label}',
getChildren: () => []
},
clustertriggerbindingnode: {
icon: 'CTB.svg',
tooltip: 'ClusterTriggerBinding: {label}',
getChildren: () => this.tkn.getClusterTriggerBinding(this)
},
clustertriggerbinding: {
icon: 'CTB.svg',
tooltip: 'ClusterTriggerBinding: {label}',
getChildren: () => []
},
eventlistenernode: {
icon: 'EL.svg',
tooltip: 'EventListener: {label}',
Expand Down Expand Up @@ -655,6 +670,7 @@ export interface Tkn {
getTaskRunsForTasks(task: TektonNode): Promise<TektonNode[]>;
getTriggerTemplates(triggerTemplates: TektonNode): Promise<TektonNode[]>;
getTriggerBinding(triggerBinding: TektonNode): Promise<TektonNode[]>;
getClusterTriggerBinding(clusterTriggerBinding: TektonNode): Promise<TektonNode[]>;
getEventListener(EventListener: TektonNode): Promise<TektonNode[]>;
getConditions(conditions: TektonNode): Promise<TektonNode[]>;
getPipelineRunsList(pipelineRun: TektonNode): Promise<TektonNode[]>;
Expand Down Expand Up @@ -726,8 +742,9 @@ export class TknImpl implements Tkn {
const triggerTemplatesNode = new TektonNodeImpl(TknImpl.ROOT, 'TriggerTemplates', ContextType.TRIGGERTEMPLATESNODE, this, TreeItemCollapsibleState.Collapsed);
const triggerBindingNode = new TektonNodeImpl(TknImpl.ROOT, 'TriggerBinding', ContextType.TRIGGERBINDINGNODE, this, TreeItemCollapsibleState.Collapsed);
const eventListenerNode = new TektonNodeImpl(TknImpl.ROOT, 'EventListener', ContextType.EVENTLISTENERNODE, this, TreeItemCollapsibleState.Collapsed);
const clusterTriggerBindingNode = new TektonNodeImpl(TknImpl.ROOT, 'ClusterTriggerBinding', ContextType.CLUSTERTRIGGERBINDINGNODE, this, TreeItemCollapsibleState.Collapsed);
const conditionsNode = new TektonNodeImpl(TknImpl.ROOT, 'Conditions', ContextType.CONDITIONSNODE, this, TreeItemCollapsibleState.Collapsed);
pipelineTree.push(pipelineNode, pipelineRunNode, taskNode, clustertaskNode, taskRunNode, pipelineResourceNode, triggerTemplatesNode, triggerBindingNode, eventListenerNode, conditionsNode);
pipelineTree.push(pipelineNode, pipelineRunNode, taskNode, clustertaskNode, taskRunNode, pipelineResourceNode, triggerTemplatesNode, triggerBindingNode, eventListenerNode, conditionsNode, clusterTriggerBindingNode);
TknImpl.ROOT.getChildren = () => pipelineTree; // TODO: fix me
return pipelineTree;
}
Expand Down Expand Up @@ -976,6 +993,10 @@ export class TknImpl implements Tkn {
return this._getTriggerResource(eventListenerNode, Command.listEventListener(), ContextType.EVENTLISTENER);
}

async getClusterTriggerBinding(clusterTriggerBindingNode: TektonNode): Promise<TektonNode[]> {
return this._getTriggerResource(clusterTriggerBindingNode, Command.listClusterTriggerBinding(), ContextType.CLUSTERTRIGGERBINDING);
}

private async _getTriggerResource(trigerResource: TektonNode, command: CliCommand, triggerContextType: ContextType): Promise<TektonNode[]> {
let data: TknPipelineResource[] = [];
const result = await this.execute(command, process.cwd(), false);
Expand Down
2 changes: 1 addition & 1 deletion test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ suite('Tekton Pipeline Extension', () => {
test('should load pipeline, task, clustertasks and pipelineresources', async () => {
sandbox.stub(TknImpl.prototype, 'execute').resolves({ error: '', stdout: '' });
const pipelinenodes = await tkn.getPipelineNodes();
expect(pipelinenodes.length).equals(10);
expect(pipelinenodes.length).equals(11);
});

test('should load pipelineruns from pipeline folder', async () => {
Expand Down

0 comments on commit a923769

Please sign in to comment.