Skip to content

Commit

Permalink
Show task recommendation based on project lang/tooling (#591)
Browse files Browse the repository at this point in the history
* #451 show task recommendation based on project lang/tooling

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>

* use npm package to recognize project

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>

* refactoring

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>

* Use alizer package

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob authored Jul 9, 2021
1 parent 039f6f4 commit 6fbc5ef
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 37 deletions.
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@
},
"dependencies": {
"@kubernetes/client-node": "^0.12.2",
"@redhat-developer/alizer": "^0.0.1",
"@redhat-developer/vscode-redhat-telemetry": "^0.2.0",
"axios": "^0.21.1",
"binary-search": "^1.3.5",
Expand All @@ -956,6 +957,7 @@
"event-stream": "3.3.4",
"fs-extra": "^7.0.1",
"fuzzysearch": "^1.0.3",
"fuzzysort": "^1.1.4",
"git-fetch-pack": "^0.1.1",
"git-transport-protocol": "^0.1.0",
"hasha": "5.0.0",
Expand All @@ -977,4 +979,4 @@
"validator": "^11.0.0",
"vscode-kubernetes-tools-api": "1.3.0"
}
}
}
8 changes: 7 additions & 1 deletion src/hub/hub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getTektonHubStatus(): Promise<TektonHubStatus> {
export async function searchTask(name: string): Promise<hubApi.ResourceData[]> {
try {
const resApi = createResourceApi();
const result = await resApi.resourceQuery(name);
const result = await resApi.resourceQuery(name, undefined, ['task'], undefined, undefined, 'contains');
return result.data.data;
} catch (err) {
if (err instanceof Error ){
Expand All @@ -49,6 +49,12 @@ export async function searchTask(name: string): Promise<hubApi.ResourceData[]> {
}
}

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

export async function getVersions(id: number): Promise<hubApi.Versions> {
const restApi = createResourceApi();
const result = await restApi.resourceVersionsByID(id);
Expand Down
3 changes: 2 additions & 1 deletion src/hub/hub-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface HubTaskInstallation {
minPipelinesVersion?: string;
asClusterTask: boolean;
taskVersion?: ResourceVersionData;
view: string;
}

export interface HubTaskUninstall {
Expand All @@ -24,7 +25,7 @@ export interface InstalledTask extends ResourceData {
clusterTask?: boolean;
}

export type HubTask = InstalledTask | ResourceData
export type HubTask = (InstalledTask | ResourceData) & { view?: string }

export function isInstalledTask(task: HubTask): task is InstalledTask {
return (task as InstalledTask).installedVersion !== undefined;
Expand Down
38 changes: 38 additions & 0 deletions src/hub/hub-recommendation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { getProjectType } from '../project-analizer/language-recongnizer/recognazer'

const MAX_LANG_AND_TOOLS = 10;
export async function startDetectingLanguage(): Promise<string[]> {
const folder = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0];
if (folder) {
try {
const langAndTools = await getProjectType(folder.uri.fsPath);
if (langAndTools && langAndTools.length > 0) {

const result = [];
for (const element of langAndTools) {
result.push(element.name);
result.push(element.builder);
if (element.frameworks){
result.push(...element.frameworks);
}
if (result.length >= MAX_LANG_AND_TOOLS) {
break;
}
}

return result;
}
} catch (err) {
console.error(err);
}
}

return [];
}

Loading

0 comments on commit 6fbc5ef

Please sign in to comment.