Add settings view
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
export interface Environment {
|
import { Workflow } from "./workflowsManager";
|
||||||
|
|
||||||
|
export interface Environment {
|
||||||
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Secret {
|
export interface Secret {
|
||||||
@@ -12,8 +14,67 @@ export interface Variable {
|
|||||||
value?: string
|
value?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Input {
|
||||||
|
key: string,
|
||||||
|
value?: string
|
||||||
|
}
|
||||||
|
|
||||||
export class SettingsManager {
|
export class SettingsManager {
|
||||||
environments: Environment[] = [];
|
getEnvironments(workflow: Workflow): Environment[] {
|
||||||
secrets: Secret[] = [];
|
const environments: Environment[] = [];
|
||||||
variables: Variable[] = [];
|
if (!workflow.yaml) {
|
||||||
|
return environments;
|
||||||
|
}
|
||||||
|
|
||||||
|
const jobs = workflow.yaml?.jobs;
|
||||||
|
if (jobs) {
|
||||||
|
for (const details of Object.values<any>(jobs)) {
|
||||||
|
if (details.environment) {
|
||||||
|
environments.push({
|
||||||
|
name: details.environment
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return environments;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSecrets(workflow: Workflow): Secret[] {
|
||||||
|
const secrets: Secret[] = [];
|
||||||
|
if (!workflow.fileContent) {
|
||||||
|
return secrets;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.findInWorkflow(workflow.fileContent, /\${{\s*secrets\.(.*?)\s*}}/g);
|
||||||
|
}
|
||||||
|
|
||||||
|
getVariables(workflow: Workflow): Variable[] {
|
||||||
|
const variables: Variable[] = [];
|
||||||
|
if (!workflow.fileContent) {
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.findInWorkflow(workflow.fileContent, /\${{\s*vars\.(.*?)(?:\s*==\s*(.*?))?\s*}}/g);
|
||||||
|
}
|
||||||
|
|
||||||
|
getInputs(workflow: Workflow): Input[] {
|
||||||
|
const inputs: Variable[] = [];
|
||||||
|
if (!workflow.fileContent) {
|
||||||
|
return inputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.findInWorkflow(workflow.fileContent, /\${{\s*(?:inputs|github\.event\.inputs)\.(.*?)(?:\s*==\s*(.*?))?\s*}}/g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private findInWorkflow(content: string, regExp: RegExp) {
|
||||||
|
const results: (Secret | Variable | Input)[] = [];
|
||||||
|
|
||||||
|
const matches = content.matchAll(regExp);
|
||||||
|
for (const match of matches) {
|
||||||
|
results.push({ key: match[1] });
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
17
src/views/settings/environment.ts
Normal file
17
src/views/settings/environment.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { Environment } from "../../settingsManager";
|
||||||
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
|
||||||
|
export default class EnvironmentTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
|
static contextValue = 'githubLocalActions.environment';
|
||||||
|
|
||||||
|
constructor(environment: Environment) {
|
||||||
|
super(environment.name, TreeItemCollapsibleState.None);
|
||||||
|
this.contextValue = EnvironmentTreeItem.contextValue;
|
||||||
|
this.iconPath = new ThemeIcon('server');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { act } from "../../extension";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
import EnvironmentTreeItem from "./environment";
|
||||||
|
|
||||||
export default class EnvironmentsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
export default class EnvironmentsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
static contextValue = 'githubLocalActions.environments';
|
static contextValue = 'githubLocalActions.environments';
|
||||||
@@ -11,6 +13,8 @@ export default class EnvironmentsTreeItem extends TreeItem implements GithubLoca
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
return [];
|
const workflows = await act.workflowsManager.getWorkflows();
|
||||||
|
const environments = [...new Set(workflows.map(workflow => act.settingsManager.getEnvironments(workflow)).flat())];
|
||||||
|
return environments.map(environment => new EnvironmentTreeItem(environment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
18
src/views/settings/input.ts
Normal file
18
src/views/settings/input.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { Input } from "../../settingsManager";
|
||||||
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
|
||||||
|
export default class InputTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
|
static contextValue = 'githubLocalActions.input';
|
||||||
|
|
||||||
|
constructor(input: Input) {
|
||||||
|
super(input.key, TreeItemCollapsibleState.None);
|
||||||
|
this.description = input.value;
|
||||||
|
this.contextValue = InputTreeItem.contextValue;
|
||||||
|
this.iconPath = new ThemeIcon('symbol-parameter');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/views/settings/inputs.ts
Normal file
20
src/views/settings/inputs.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { act } from "../../extension";
|
||||||
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
import InputTreeItem from "./input";
|
||||||
|
|
||||||
|
export default class InputsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
|
static contextValue = 'githubLocalActions.inputs';
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super('Inputs', TreeItemCollapsibleState.Collapsed);
|
||||||
|
this.contextValue = InputsTreeItem.contextValue;
|
||||||
|
this.iconPath = new ThemeIcon('record-keys');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
|
const workflows = await act.workflowsManager.getWorkflows();
|
||||||
|
const inputs = [...new Set(workflows.map(workflow => act.settingsManager.getInputs(workflow)).flat())];
|
||||||
|
return inputs.map(input => new InputTreeItem(input));
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/views/settings/secret.ts
Normal file
18
src/views/settings/secret.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { Secret } from "../../settingsManager";
|
||||||
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
|
||||||
|
export default class SecretTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
|
static contextValue = 'githubLocalActions.secret';
|
||||||
|
|
||||||
|
constructor(secret: Secret) {
|
||||||
|
super(secret.key, TreeItemCollapsibleState.None);
|
||||||
|
this.description = secret.value;
|
||||||
|
this.contextValue = SecretTreeItem.contextValue;
|
||||||
|
this.iconPath = new ThemeIcon('key');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { act } from "../../extension";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
import SecretTreeItem from "./secret";
|
||||||
|
|
||||||
export default class SecretsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
export default class SecretsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
static contextValue = 'githubLocalActions.secrets';
|
static contextValue = 'githubLocalActions.secrets';
|
||||||
@@ -11,6 +13,8 @@ export default class SecretsTreeItem extends TreeItem implements GithubLocalActi
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
return [];
|
const workflows = await act.workflowsManager.getWorkflows();
|
||||||
|
const secrets = [...new Set(workflows.map(workflow => act.settingsManager.getSecrets(workflow)).flat())];
|
||||||
|
return secrets.map(secret => new SecretTreeItem(secret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem } from "vscode";
|
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem } from "vscode";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
import EnvironmentsTreeItem from "./environments";
|
import EnvironmentsTreeItem from "./environments";
|
||||||
|
import InputsTreeItem from "./inputs";
|
||||||
import SecretsTreeItem from "./secrets";
|
import SecretsTreeItem from "./secrets";
|
||||||
import VariablesTreeItem from "./variables";
|
import VariablesTreeItem from "./variables";
|
||||||
|
|
||||||
@@ -40,7 +41,8 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
|
|||||||
return [
|
return [
|
||||||
new EnvironmentsTreeItem(),
|
new EnvironmentsTreeItem(),
|
||||||
new SecretsTreeItem(),
|
new SecretsTreeItem(),
|
||||||
new VariablesTreeItem()
|
new VariablesTreeItem(),
|
||||||
|
new InputsTreeItem()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/views/settings/variable.ts
Normal file
18
src/views/settings/variable.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { Variable } from "../../settingsManager";
|
||||||
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
|
||||||
|
export default class VariableTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
|
static contextValue = 'githubLocalActions.variable';
|
||||||
|
|
||||||
|
constructor(variable: Variable) {
|
||||||
|
super(variable.key, TreeItemCollapsibleState.None);
|
||||||
|
this.description = variable.value;
|
||||||
|
this.contextValue = VariableTreeItem.contextValue;
|
||||||
|
this.iconPath = new ThemeIcon('symbol-variable');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
|
import { act } from "../../extension";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
import VariableTreeItem from "./variable";
|
||||||
|
|
||||||
export default class VariablesTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
export default class VariablesTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||||
static contextValue = 'githubLocalActions.variables';
|
static contextValue = 'githubLocalActions.variables';
|
||||||
@@ -11,6 +13,8 @@ export default class VariablesTreeItem extends TreeItem implements GithubLocalAc
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||||
return [];
|
const workflows = await act.workflowsManager.getWorkflows();
|
||||||
|
const variables = [...new Set(workflows.map(workflow => act.settingsManager.getVariables(workflow)).flat())];
|
||||||
|
return variables.map(variable => new VariableTreeItem(variable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,8 @@ import * as yaml from "yaml";
|
|||||||
export interface Workflow {
|
export interface Workflow {
|
||||||
name: string,
|
name: string,
|
||||||
uri: Uri,
|
uri: Uri,
|
||||||
content?: any,
|
fileContent?: string,
|
||||||
|
yaml?: any,
|
||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +66,8 @@ export class WorkflowsManager {
|
|||||||
workflows.push({
|
workflows.push({
|
||||||
name: yamlContent.name || path.parse(workflowFileUri.fsPath).name,
|
name: yamlContent.name || path.parse(workflowFileUri.fsPath).name,
|
||||||
uri: workflowFileUri,
|
uri: workflowFileUri,
|
||||||
content: yaml.parse(fileContent)
|
fileContent: fileContent,
|
||||||
|
yaml: yaml.parse(fileContent)
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
workflows.push({
|
workflows.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user