Skip to content

Commit

Permalink
#510 add tekton hub url in to preferences
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed Apr 20, 2021
1 parent 195b41b commit 148e2a1
Show file tree
Hide file tree
Showing 7 changed files with 700 additions and 72 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
"type": "boolean",
"default": true,
"description": "Enable/disable to check Task and ClusterTask Reference Resource"
},
"vs-tekton.tekton-hub-url": {
"title": "TektonHub URL",
"type": "string",
"default": "https://api.hub.tekton.dev",
"description": "The URL for TektonHub"
}
}
},
Expand Down
21 changes: 14 additions & 7 deletions src/hub/hub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*-----------------------------------------------------------------------------------------------*/

import * as hubApi from '../tekton-hub-client';
import * as vscode from 'vscode';

export enum TektonHubStatusEnum {
Ok = 'ok',
Expand All @@ -17,7 +18,8 @@ export interface TektonHubStatus {

export async function getTektonHubStatus(): Promise<TektonHubStatus> {
try {
const result = await new hubApi.StatusApi().statusStatus();
const hubUrl = vscode.workspace.getConfiguration('vs-tekton').get<string>('tekton-hub-url');
const result = await new hubApi.StatusApi({basePath: hubUrl}).statusStatus();
for (const service of result.data.services) {
if (service.status !== hubApi.HubServiceStatusEnum.Ok){
return {status: TektonHubStatusEnum.Error, error: service.error};
Expand All @@ -33,7 +35,7 @@ export async function getTektonHubStatus(): Promise<TektonHubStatus> {

export async function searchTask(name: string): Promise<hubApi.ResourceData[]> {
try {
const resApi = new hubApi.ResourceApi();
const resApi = createResourceApi();
const result = await resApi.resourceQuery(name);
return result.data.data;
} catch (err) {
Expand All @@ -48,31 +50,36 @@ export async function searchTask(name: string): Promise<hubApi.ResourceData[]> {
}

export async function getVersions(id: number): Promise<hubApi.Versions> {
const restApi = new hubApi.ResourceApi();
const restApi = createResourceApi();
const result = await restApi.resourceVersionsByID(id);
return result.data.data;
}

export async function getTaskByVersion(taskId: number): Promise<hubApi.ResourceVersionData> {
const restApi = new hubApi.ResourceApi();
const restApi = createResourceApi();
const result = await restApi.resourceByVersionId(taskId);
return result.data.data;
}

export async function getTaskByNameAndVersion(catalog: string, name: string, version: string): Promise<hubApi.ResourceVersionData> {
const restApi = new hubApi.ResourceApi();
const restApi = createResourceApi();
const result = await restApi.resourceByCatalogKindNameVersion(catalog, 'task', name, version);
return result.data.data;
}

export async function getTaskById(taskId: number): Promise<hubApi.ResourceData> {
const restApi = new hubApi.ResourceApi();
const restApi = createResourceApi();
const result = await restApi.resourceById(taskId);
return result.data.data;
}

export async function getTopRatedTasks(limit: number): Promise<hubApi.ResourceData[]> {
const restApi = new hubApi.ResourceApi();
const restApi = createResourceApi();
const result = await restApi.resourceList(limit);
return result.data.data;
}

function createResourceApi(): hubApi.ResourceApi {
const hubUrl = vscode.workspace.getConfiguration('vs-tekton').get<string>('tekton-hub-url');
return new hubApi.ResourceApi({basePath: hubUrl});
}
Loading

0 comments on commit 148e2a1

Please sign in to comment.