Skip to content

Commit

Permalink
Rutusamai/list build tasks for each registry (#37)
Browse files Browse the repository at this point in the history
* tslint updates, transfered from old branch

* updated icon

* Addressed PR comments- mostly styling/code efficiency

* Changed url to aka.ms link

* changed Error window to Info message for no build tasks in your registry

* Changed default sku and unified parsing resource group into a new method, getResourceGroup in acrTools.ts

* Changed build task icon
  • Loading branch information
rsamai authored and rosanch committed Sep 21, 2018
1 parent afd4e54 commit f201ce3
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 17 deletions.
2 changes: 1 addition & 1 deletion commands/azureCommands/create-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function createRegistry(): Promise<Registry> {
return registry;
}
async function acquireSKU(): Promise<string> {
let skus: string[] = ["Basic", "Standard", "Premium"];
let skus: string[] = ["Standard", "Basic", "Premium"];
let sku: string;
sku = await vscode.window.showQuickPick(skus, { 'canPickMany': false, 'placeHolder': 'Choose a SKU' });
if (sku === undefined) { throw new Error('User exit'); }
Expand Down
9 changes: 7 additions & 2 deletions explorer/models/azureRegistryNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Repository } from '../../utils/Azure/models/repository';
import { getLoginServer, } from '../../utils/nonNull';
import { formatTag } from './commonRegistryUtils';
import { IconPath, NodeBase } from './nodeBase';
import { TaskRootNode } from './taskNode';

export class AzureRegistryNode extends NodeBase {
constructor(
Expand All @@ -40,8 +41,12 @@ export class AzureRegistryNode extends NodeBase {
}
}

public async getChildren(element: AzureRegistryNode): Promise<AzureRepositoryNode[]> {
const repoNodes: AzureRepositoryNode[] = [];
public async getChildren(element: AzureRegistryNode): Promise<NodeBase[]> {
const repoNodes: NodeBase[] = [];

//Pushing single TaskRootNode under the current registry. All the following nodes added to registryNodes are type AzureRepositoryNode
let taskNode = new TaskRootNode("Tasks", element.azureAccount, element.subscription, element.registry);
repoNodes.push(taskNode);

if (!this.azureAccount) {
return [];
Expand Down
1 change: 1 addition & 0 deletions explorer/models/rootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class RootNode extends NodeBase {
}

public async getChildren(element: NodeBase): Promise<NodeBase[]> {

if (element.contextValue === 'imagesRootNode') {
return this.getImages();
}
Expand Down
85 changes: 85 additions & 0 deletions explorer/models/taskNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { ResourceManagementClient, SubscriptionClient, SubscriptionModels } from 'azure-arm-resource';
import * as opn from 'opn';
import * as path from 'path';
import * as vscode from 'vscode';
import * as ContainerModels from '../../node_modules/azure-arm-containerregistry/lib/models';
import { AzureAccount, AzureSession } from '../../typings/azure-account.api';
import * as acrTools from '../../utils/Azure/acrTools';
import { AzureUtilityManager } from '../../utils/azureUtilityManager';
import { NodeBase } from './nodeBase';

/* Single TaskRootNode under each Repository. Labeled "Build Tasks" */
export class TaskRootNode extends NodeBase {
constructor(
public readonly label: string,
public readonly azureAccount: AzureAccount,
public readonly subscription: SubscriptionModels.Subscription,
public readonly registry: ContainerModels.Registry,
//public readonly iconPath: any = null,
) {
super(label);
}

public readonly contextValue: string = 'taskRootNode';
public name: string;
public readonly iconPath: { light: string | vscode.Uri; dark: string | vscode.Uri } = {
light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'tasks_light.svg'),
dark: path.join(__filename, '..', '..', '..', '..', 'images', 'dark', 'tasks_dark.svg')
};

public getTreeItem(): vscode.TreeItem {
return {
label: this.label,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
contextValue: this.contextValue,
iconPath: this.iconPath
}
}

/* Making a list view of TaskNodes, or the Tasks of the current registry */

public async getChildren(element: TaskRootNode): Promise<TaskNode[]> {
const taskNodes: TaskNode[] = [];
let tasks: ContainerModels.Task[] = [];
const client = AzureUtilityManager.getInstance().getContainerRegistryManagementClient(element.subscription);
const resourceGroup: string = acrTools.getResourceGroupName(element.registry);
tasks = await client.tasks.list(resourceGroup, element.registry.name);
if (tasks.length === 0) {
vscode.window.showInformationMessage(`You do not have any Tasks in the registry, '${element.registry.name}'. You can create one with ACR Task. `, "Learn More").then(val => {
if (val === "Learn More") {
opn('https://aka.ms/acr/task');
}
})
}

for (let task of tasks) {
let node = new TaskNode(task, element.registry, element.subscription, element);
taskNodes.push(node);
}
return taskNodes;
}
}
export class TaskNode extends NodeBase {
constructor(
public task: ContainerModels.Task,
public registry: ContainerModels.Registry,

public subscription: SubscriptionModels.Subscription,
public parent: NodeBase

) {
super(task.name);
}

public label: string;
public readonly contextValue: string = 'taskNode';

public getTreeItem(): vscode.TreeItem {
return {
label: this.label,
collapsibleState: vscode.TreeItemCollapsibleState.None,
contextValue: this.contextValue,
iconPath: null
}
}
}
1 change: 1 addition & 0 deletions images/dark/tasks_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/light/tasks_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions utils/Azure/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import * as acrTools from '../acrTools';

/** Class Azure Repository: Used locally, Organizes data for managing Repositories */
export class Repository {
public registry: Registry;
public name: string;
public subscription: SubscriptionModels.Subscription;
public resourceGroupName: string;
public password?: string;
public username?: string;
public registry: Registry;
public name: string;
public subscription: SubscriptionModels.Subscription;
public resourceGroupName: string;
public password?: string;
public username?: string;

constructor(registry: Registry, repository: string, password?: string, username?: string) {
this.registry = registry;
this.resourceGroupName = acrTools.getResourceGroupName(registry);
this.subscription = acrTools.getSubscriptionFromRegistry(registry);
this.name = repository;
if (password) { this.password = password; }
if (username) { this.username = username; }
}
constructor(registry: Registry, repository: string, password?: string, username?: string) {
this.registry = registry;
this.resourceGroupName = acrTools.getResourceGroupName(registry);
this.subscription = acrTools.getSubscriptionFromRegistry(registry);
this.name = repository;
if (password) { this.password = password; }
if (username) { this.username = username; }
}
}

0 comments on commit f201ce3

Please sign in to comment.