Add status check and login for github cli extension

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-11-25 00:11:48 -05:00
parent b6a12f35a8
commit 6292da3f72
3 changed files with 16 additions and 15 deletions

View File

@@ -94,7 +94,7 @@ export class Act {
'Chocolatey': 'choco install act-cli', 'Chocolatey': 'choco install act-cli',
'Winget': 'winget install nektos.act', 'Winget': 'winget install nektos.act',
'Scoop': 'scoop install act', 'Scoop': 'scoop install act',
'GitHub CLI': 'gh extension install https://github.com/nektos/gh-act' 'GitHub CLI': 'gh auth status || gh auth login && gh extension install https://github.com/nektos/gh-act'
}; };
this.prebuiltExecutables = { this.prebuiltExecutables = {
@@ -109,7 +109,7 @@ export class Act {
'Homebrew': 'brew install act', 'Homebrew': 'brew install act',
'Nix': 'nix run nixpkgs#act', 'Nix': 'nix run nixpkgs#act',
'MacPorts': 'sudo port install act', 'MacPorts': 'sudo port install act',
'GitHub CLI': 'gh extension install https://github.com/nektos/gh-act' 'GitHub CLI': 'gh auth status || gh auth login && gh extension install https://github.com/nektos/gh-act'
}; };
this.prebuiltExecutables = { this.prebuiltExecutables = {
@@ -123,7 +123,7 @@ export class Act {
'Nix': 'nix run nixpkgs#act', 'Nix': 'nix run nixpkgs#act',
'AUR': 'yay -Syu act', 'AUR': 'yay -Syu act',
'COPR': 'dnf copr enable goncalossilva/act && dnf install act-cli', 'COPR': 'dnf copr enable goncalossilva/act && dnf install act-cli',
'GitHub CLI': 'gh extension install https://github.com/nektos/gh-act' 'GitHub CLI': 'gh auth status || gh auth login && gh extension install https://github.com/nektos/gh-act'
}; };
this.prebuiltExecutables = { this.prebuiltExecutables = {
@@ -160,9 +160,15 @@ export class Act {
}); });
// Refresh components view after installation // Refresh components view after installation
tasks.onDidEndTask(e => { tasks.onDidEndTask(async e => {
const taskDefinition = e.execution.task.definition; const taskDefinition = e.execution.task.definition;
if (taskDefinition.type === 'nektos/act installation') { if (taskDefinition.type === 'nektos/act installation') {
if (taskDefinition.ghCliInstall) {
await ConfigurationManager.set(Section.actCommand, Act.githubCliCommand);
} else {
await ConfigurationManager.set(Section.actCommand, Act.command);
}
componentsTreeDataProvider.refresh(); componentsTreeDataProvider.refresh();
} }
}); });
@@ -375,7 +381,7 @@ export class Act {
await tasks.executeTask({ await tasks.executeTask({
name: 'nektos/act', name: 'nektos/act',
detail: 'Install nektos/act', detail: 'Install nektos/act',
definition: { type: 'nektos/act installation' }, definition: { type: 'nektos/act installation', ghCliInstall: command.includes('gh-act') },
source: 'GitHub Local Actions', source: 'GitHub Local Actions',
scope: TaskScope.Workspace, scope: TaskScope.Workspace,
isBackground: true, isBackground: true,
@@ -393,12 +399,6 @@ export class Act {
group: TaskGroup.Build, group: TaskGroup.Build,
execution: new ShellExecution(command) execution: new ShellExecution(command)
}); });
if (command.includes('gh-act')) {
ConfigurationManager.set(Section.actCommand, Act.githubCliCommand);
} else {
ConfigurationManager.set(Section.actCommand, Act.command);
}
} }
} }
} }

View File

@@ -16,7 +16,7 @@ export namespace ConfigurationManager {
export const group: string = 'githubLocalActions'; export const group: string = 'githubLocalActions';
export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions'; export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions';
export function initialize(): void { export async function initialize(): Promise<void> {
let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath); let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
if (!dockerDesktopPath) { if (!dockerDesktopPath) {
switch (process.platform) { switch (process.platform) {
@@ -30,12 +30,12 @@ export namespace ConfigurationManager {
return; return;
} }
ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath); await ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath);
} }
let actCommand = ConfigurationManager.get<string>(Section.actCommand); let actCommand = ConfigurationManager.get<string>(Section.actCommand);
if (!actCommand) { if (!actCommand) {
ConfigurationManager.set(Section.actCommand, Act.command); await ConfigurationManager.set(Section.actCommand, Act.command);
} }
} }

View File

@@ -54,7 +54,8 @@ export function activate(context: vscode.ExtensionContext) {
ConfigurationManager.initialize(); ConfigurationManager.initialize();
workspace.onDidChangeConfiguration(async event => { workspace.onDidChangeConfiguration(async event => {
if (event.affectsConfiguration(ConfigurationManager.group)) { if (event.affectsConfiguration(ConfigurationManager.group)) {
ConfigurationManager.initialize(); await ConfigurationManager.initialize();
componentsTreeDataProvider.refresh();
} }
}); });