Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plugin for gitlab cli #100

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ Currently available plugins:
- [Rtx](https://github.com/jdx/rtx)
- [Nx](https://nx.dev/)
- [Fluent CI](https://docs.fluentci.io/reference/)
- [Gitlab CLI](https://gitlab.com/gitlab-org/cli/-/tree/main/docs/source)
81 changes: 81 additions & 0 deletions plugins/gitlab-cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { evaluateSystemCommand, spawn } from "../src/helpers.ts";
import Plugin from "../src/plugin.ts";
import Brew from "./brew.ts";

class GitlabCLI implements Plugin {
name = "glab";
commands: Record<string, (params: string[]) => Promise<void>>;

constructor() {
this.commands = {
alias: (args: string[]) => spawn(this.name, ["alias", ...args]),
api: (args: string[]) => spawn(this.name, ["api", ...args]),
auth: (args: string[]) => spawn(this.name, ["auth", ...args]),
changelog: (args: string[]) => spawn(this.name, ["changelog", ...args]),
check_update: (args: string[]) =>
spawn(this.name, ["check-update", ...args]),
ci: (args: string[]) => spawn(this.name, ["ci", ...args]),
completion: (args: string[]) => spawn(this.name, ["completion", ...args]),
config: (args: string[]) => spawn(this.name, ["config", ...args]),
incident: (args: string[]) => spawn(this.name, ["incident", ...args]),
issue: (args: string[]) => spawn(this.name, ["issue", ...args]),
label: (args: string[]) => spawn(this.name, ["label", ...args]),
mr: (args: string[]) => spawn(this.name, ["mr", ...args]),
release: (args: string[]) => spawn(this.name, ["release", ...args]),
repo: (args: string[]) => spawn(this.name, ["repo", ...args]),
schedule: (args: string[]) => spawn(this.name, ["schedule", ...args]),
snippet: (args: string[]) => spawn(this.name, ["snippet", ...args]),
ssh_key: (args: string[]) => spawn(this.name, ["ssh-key", ...args]),
user: (args: string[]) => spawn(this.name, ["user", ...args]),
variable: (args: string[]) => spawn(this.name, ["variable", ...args]),
version: (args: string[]) => spawn(this.name, ["version", ...args]),
help: () => {
console.log(`
CORE COMMANDS
alias: Create, list and delete aliases
api: Make an authenticated request to GitLab API
ask: Generate terminal commands from natural language. (Experimental.)
auth: Manage glab's authentication state
changelog: Interact with the changelog API
check-update: Check for latest glab releases
ci: Work with GitLab CI/CD pipelines and jobs
completion: Generate shell completion scripts
config: Set and get glab settings
help: Help about any command
incident: Work with GitLab incidents
issue: Work with GitLab issues
label: Manage labels on remote
mr: Create, view and manage merge requests
release: Manage GitLab releases
repo: Work with GitLab repositories and projects
schedule: Work with GitLab CI schedules
snippet: Create, view and manage snippets
ssh-key: Manage SSH keys registered with your GitLab account.
user: Interact with user
variable: Manage GitLab Project and Group Variables
version: Show glab version information
`);
return Promise.resolve();
},
};
}

async evaluate(command: string): Promise<void> {
const [cmd, ...params] = command.split(" ");
if (this.commands[cmd]) {
await this.commands[cmd](params);
return;
}
if (cmd === "") {
return;
}
await evaluateSystemCommand(command);
}

async install(): Promise<void> {
await new Brew().install();
await spawn("sh", ["-c", "type glab > /dev/null || brew install glab"]);
}
}

export default GitlabCLI;
2 changes: 2 additions & 0 deletions plugins/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Grunt from "./grunt.ts";
import Rtx from "./rtx.ts";
import Nx from "./nx.ts";
import Fluentci from "./fluentci.ts";
import GitlabCLI from "./gitlab-cli.ts";

export const plugins = [
new Docker(),
Expand Down Expand Up @@ -76,4 +77,5 @@ export const plugins = [
new Rtx(),
new Nx(),
new Fluentci(),
new GitlabCLI(),
];