Skip to content

Commit

Permalink
Merge pull request #100 from iamando/feature/plugin/gitlab-cli
Browse files Browse the repository at this point in the history
feat: add plugin for gitlab cli
  • Loading branch information
tsirysndr committed Oct 11, 2023
2 parents f646b2c + 2682449 commit 5af32b1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
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(),
];

0 comments on commit 5af32b1

Please sign in to comment.