@gitbeaker/cli 35.8.0 → 35.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
File without changes
package/dist/index.mjs ADDED
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env node
2
+ import Chalk from 'chalk';
3
+ import Sywac from 'sywac';
4
+ import { decamelize, depascalize, camelize } from 'xcase';
5
+ import * as Gitbeaker from '@gitbeaker/rest';
6
+ import API_MAP from '@gitbeaker/core/map.json' assert { type: 'json' };
7
+
8
+ var commandStyle = Chalk.hex("#e34329").bold;
9
+ var groupStyle = Chalk.hex("#fca325").bold;
10
+ var usageStyle = Chalk.hex("#fc6e26").bold;
11
+ var optionStyle = Chalk.white.bold;
12
+ var descriptionStyle = Chalk.hex("#848484");
13
+ var hintStyle = Chalk.hex("#6a5f88");
14
+ function normalizeEnviromentVariables(env) {
15
+ const normalized = { ...env };
16
+ const suffixes = [
17
+ "TOKEN",
18
+ "OAUTH_TOKEN",
19
+ "JOB_TOKEN",
20
+ "HOST",
21
+ "SUDO",
22
+ "CAMELIZE",
23
+ "REQUEST_TIMEOUT",
24
+ "PROFILE_TOKEN",
25
+ "PROFILE_MODE"
26
+ ];
27
+ suffixes.forEach((s) => {
28
+ if (normalized[`GITLAB_${s}`] && !normalized[`GITBEAKER_${s}`]) {
29
+ normalized[`GITBEAKER_${s}`] = normalized[`GITLAB_${s}`];
30
+ }
31
+ });
32
+ return normalized;
33
+ }
34
+ function globalConfig(env = process.env) {
35
+ const normalEnv = normalizeEnviromentVariables(env);
36
+ return {
37
+ "gb-token": {
38
+ alias: "gl-token",
39
+ desc: "Your Gitlab Personal Token",
40
+ type: "string",
41
+ defaultValue: normalEnv.GITBEAKER_TOKEN
42
+ },
43
+ "gb-oauth-token": {
44
+ alias: "gl-oauth-token",
45
+ desc: "Your Gitlab OAuth Token",
46
+ type: "string",
47
+ defaultValue: normalEnv.GITBEAKER_OAUTH_TOKEN
48
+ },
49
+ "gb-job-token": {
50
+ alias: "gl-job-token",
51
+ desc: "Your Gitlab Job Token",
52
+ type: "string",
53
+ defaultValue: normalEnv.GITBEAKER_JOB_TOKEN
54
+ },
55
+ "gb-host": {
56
+ alias: "gl-host",
57
+ desc: "Your Gitlab API host (Defaults to https://www.gitlab.com)",
58
+ type: "string",
59
+ defaultValue: normalEnv.GITBEAKER_HOST
60
+ },
61
+ "gb-sudo": {
62
+ alias: "gl-sudo",
63
+ desc: "[Sudo](https://docs.gitlab.com/ee/api/#sudo) query parameter",
64
+ type: "string",
65
+ defaultValue: normalEnv.GITBEAKER_SUDO
66
+ },
67
+ "gb-camelize": {
68
+ alias: "gl-camelize",
69
+ desc: "Camelizes all response body keys",
70
+ type: "boolean",
71
+ defaultValue: normalEnv.GITBEAKER_CAMELIZE
72
+ },
73
+ "gb-request-timeout": {
74
+ alias: "gl-request-timeout",
75
+ desc: "Timeout for API requests. Measured in ms",
76
+ type: "number",
77
+ defaultValue: normalEnv.GITBEAKER_REQUEST_TIMEOUT && parseInt(normalEnv.GITBEAKER_REQUEST_TIMEOUT, 10)
78
+ },
79
+ "gb-profile-token": {
80
+ alias: "gl-profile-token",
81
+ desc: "[Requests Profiles Token](https://docs.gitlab.com/ee/administration/monitoring/performance/request_profiling.html)",
82
+ type: "string",
83
+ defaultValue: normalEnv.GITBEAKER_PROFILE_TOKEN
84
+ },
85
+ "gb-profile-mode": {
86
+ alias: "gl-profile-mode",
87
+ desc: "[Requests Profiles Token](https://docs.gitlab.com/ee/administration/monitoring/performance/request_profiling.html)",
88
+ type: "string",
89
+ defaultValue: normalEnv.GITBEAKER_PROFILE_MODE
90
+ }
91
+ };
92
+ }
93
+ var ignoreOptions = ["_", "$0", "v", "version", "h", "help", "g", "global-args"];
94
+ function param(value) {
95
+ let cleaned = value;
96
+ const exceptions = [
97
+ "GitLabCI",
98
+ "YML",
99
+ "GPG",
100
+ "SSH",
101
+ "IId",
102
+ "NPM",
103
+ "NuGet",
104
+ "DORA4",
105
+ "LDAP",
106
+ "CICD"
107
+ ];
108
+ const ex = exceptions.find((e) => value.includes(e));
109
+ if (ex)
110
+ cleaned = cleaned.replace(ex, ex.charAt(0).toUpperCase() + ex.slice(1).toLowerCase());
111
+ const decamelized = decamelize(cleaned, "-");
112
+ return decamelized !== cleaned ? decamelized : depascalize(cleaned, "-");
113
+ }
114
+ function setupAPIMethods(setupArgs, methodArgs) {
115
+ methodArgs.forEach((name) => {
116
+ if (typeof name !== "string")
117
+ return;
118
+ setupArgs.positional(`[--${param(name)}] <${param(name)}>`, {
119
+ group: "Required Options",
120
+ type: "string"
121
+ });
122
+ });
123
+ return setupArgs;
124
+ }
125
+ function runAPIMethod(ctx, args, apiName, method) {
126
+ const coreArgs = {};
127
+ const optionalArgs = {};
128
+ const initArgs = {};
129
+ Object.entries(args).forEach(([argName, value]) => {
130
+ if (ignoreOptions.includes(argName) || value == null)
131
+ return;
132
+ const camelCased = camelize(argName.replace("gb-", "").replace("gl-", ""), "-");
133
+ if (globalConfig()[argName.replace("gl-", "gb-")]) {
134
+ initArgs[camelCased] = value;
135
+ } else if (method.args.includes(camelCased))
136
+ coreArgs[camelCased] = value;
137
+ else
138
+ optionalArgs[camelCased] = value;
139
+ });
140
+ const s = new Gitbeaker[apiName](initArgs);
141
+ return s[method.name](...Object.values(coreArgs), optionalArgs).then((r) => {
142
+ ctx.output = JSON.stringify(r, null, 3);
143
+ }).catch((e) => {
144
+ ctx.output = e;
145
+ });
146
+ }
147
+ function setupAPIs(setupArgs, apiName, methods) {
148
+ Object.entries(globalConfig()).forEach(([k, v]) => {
149
+ setupArgs.option(`${k} <value>`, {
150
+ group: "Base Options",
151
+ ...v
152
+ });
153
+ });
154
+ for (let i = 1; i < methods.length; i += 1) {
155
+ const method = methods[i];
156
+ setupArgs.command(param(method.name), {
157
+ setup: (setupMethodArgs) => setupAPIMethods(setupMethodArgs, method.args),
158
+ run: (args, ctx) => runAPIMethod(ctx, args, apiName, method)
159
+ });
160
+ }
161
+ return setupArgs;
162
+ }
163
+ var cli = Sywac.version("-v, --version").help("-h, --help").showHelpByDefault().epilogue("Copyright 2023").style({
164
+ usagePrefix: (s) => usageStyle(s),
165
+ group: (s) => groupStyle(s),
166
+ flags: (s) => optionStyle(s),
167
+ usageCommandPlaceholder: (s) => commandStyle(s),
168
+ usageOptionsPlaceholder: (s) => optionStyle(s),
169
+ desc: (s) => descriptionStyle(s),
170
+ hints: (s) => hintStyle(s)
171
+ });
172
+ cli.boolean("-g --global-args", {
173
+ desc: "Show global arguments currently set in the environment variables"
174
+ });
175
+ cli.command("*", (argv, ctx) => {
176
+ if (!argv.g)
177
+ return;
178
+ const display = {};
179
+ Object.entries(globalConfig()).forEach(([k, v]) => {
180
+ if (v.defaultValue == null)
181
+ return;
182
+ display[k] = {
183
+ alias: v.alias,
184
+ description: v.desc,
185
+ value: v.defaultValue
186
+ };
187
+ });
188
+ ctx.output = Object.keys(display).length === 0 ? "No global variables have been set!" : JSON.stringify(display, null, 3);
189
+ });
190
+ Object.entries(API_MAP).forEach(([apiName, methods]) => {
191
+ if (apiName === "Gitlab")
192
+ return;
193
+ cli.command(param(apiName), {
194
+ desc: `The ${apiName} API`,
195
+ setup: (setupArgs) => setupAPIs(setupArgs, apiName, methods)
196
+ });
197
+ });
198
+
199
+ // src/index.ts
200
+ cli.parseAndExit();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gitbeaker/cli",
3
3
  "description": "Full NodeJS CLI implementation of the GitLab API.",
4
- "version": "35.8.0",
4
+ "version": "35.8.1",
5
5
  "author": {
6
6
  "name": "Justin Dalrymple"
7
7
  },
@@ -12,8 +12,8 @@
12
12
  "url": "https://github.com/jdalrymple/gitbeaker/issues"
13
13
  },
14
14
  "dependencies": {
15
- "@gitbeaker/core": "^35.8.0",
16
- "@gitbeaker/node": "^35.8.0",
15
+ "@gitbeaker/core": "^35.8.1",
16
+ "@gitbeaker/node": "^35.8.1",
17
17
  "chalk": "4.1.2",
18
18
  "ora": "^6.0.0",
19
19
  "sywac": "^1.3.0",
@@ -53,6 +53,5 @@
53
53
  "build": "rollup -c",
54
54
  "test:integration": "TEST_ID=$(uuid) node --expose-gc ../../node_modules/.bin/jest --runInBand --logHeapUsage test/integration",
55
55
  "test:unit": "node --expose-gc ../../node_modules/.bin/jest --runInBand --logHeapUsage test/unit"
56
- },
57
- "gitHead": "f42202715f3b6d327bf63b20bffdea41d0d72009"
56
+ }
58
57
  }
package/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- # The MIT License
2
-
3
- Copyright (c)
4
- **2020 Justin Dalrymple**
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.