@gitbeaker/cli 38.0.1 → 38.1.0

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <br>
6
6
  <p align="center">
7
7
  <a href="https://gitlab.com/jdalrymple/gitbeaker/-/commits/main"><img alt="pipeline status" src="https://gitlab.com/jdalrymple/gitbeaker/badges/main/pipeline.svg?ignore_skipped=true" /></a>
8
- <a href="https://gitlab.com/jdalrymple/gitbeaker/-/commits/main"><img alt="coverage report" src="https://gitlab.com/jdalrymple/gitbeaker/badges/main/coverage.svg?job=test:integration:cli" /></a>
8
+ <a href="https://gitlab.com/jdalrymple/gitbeaker/-/commits/main"><img alt="coverage report" src="https://gitlab.com/jdalrymple/gitbeaker/badges/main/coverage.svg?job=test:unit:cli" /></a>
9
9
  <a href="https://codeclimate.com/github/jdalrymple/gitbeaker">
10
10
  <img src="https://codeclimate.com/github/jdalrymple/gitbeaker/badges/gpa.svg" alt="Code Climate maintainability">
11
11
  </a>
@@ -187,6 +187,7 @@ This could be set globally or using a [.env](https://github.com/motdotla/dotenv#
187
187
  <td align="center" valign="top" width="3.84%"><a href="https://kyr.github.io/CV/"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/426462?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Kyrylo Fedorov"/></td>
188
188
  <td align="center" valign="top" width="3.84%"><a href="https://github.com/claudio-vellage"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/28930612?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Claudio Vellage"/></td>
189
189
  <td align="center" valign="top" width="3.84%"><a href="https://github.com/seb0uil"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/5122626?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Seb0uil"/></td>
190
+ <td align="center" valign="top" width="3.84%"><a href="http://merorafael.info/"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/3404989?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Rafael Mello"/></td>
190
191
  </tr>
191
192
  </p>
192
193
 
package/dist/index.mjs CHANGED
@@ -1,18 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
  import Chalk from 'chalk';
3
3
  import Sywac from 'sywac';
4
- import { decamelize, depascalize, camelize } from 'xcase';
5
4
  import * as Gitbeaker from '@gitbeaker/rest';
6
5
  import API_MAP from '@gitbeaker/core/map.json' assert { type: 'json' };
6
+ import { decamelize, depascalize, camelize } from 'xcase';
7
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");
8
+ function param(value) {
9
+ let cleaned = value;
10
+ const exceptions = [
11
+ "GitLabCI",
12
+ "YML",
13
+ "GPG",
14
+ "SSH",
15
+ "IId",
16
+ "NPM",
17
+ "NuGet",
18
+ "DORA4",
19
+ "LDAP",
20
+ "CICD",
21
+ "SAML",
22
+ "SCIM",
23
+ "PyPI"
24
+ ];
25
+ exceptions.filter((e) => value.includes(e)).forEach((ex) => {
26
+ cleaned = cleaned.replace(ex, ex.charAt(0).toUpperCase() + ex.slice(1).toLowerCase());
27
+ });
28
+ const decamelized = decamelize(cleaned, "-");
29
+ return decamelized !== cleaned ? decamelized : depascalize(cleaned, "-");
30
+ }
14
31
  function normalizeEnviromentVariables(env) {
15
- const normalized = { ...env };
32
+ const normalized = {};
16
33
  const suffixes = [
17
34
  "TOKEN",
18
35
  "OAUTH_TOKEN",
@@ -25,13 +42,49 @@ function normalizeEnviromentVariables(env) {
25
42
  "PROFILE_MODE"
26
43
  ];
27
44
  suffixes.forEach((s) => {
28
- if (normalized[`GITLAB_${s}`] && !normalized[`GITBEAKER_${s}`]) {
29
- normalized[`GITBEAKER_${s}`] = normalized[`GITLAB_${s}`];
30
- }
45
+ if (env[`GITLAB_${s}`])
46
+ normalized[`GITBEAKER_${s}`] = env[`GITLAB_${s}`];
47
+ if (env[`GITBEAKER_${s}`])
48
+ normalized[`GITBEAKER_${s}`] = env[`GITBEAKER_${s}`];
31
49
  });
32
50
  return normalized;
33
51
  }
34
- function globalConfig(env = process.env) {
52
+ function buildArgumentObjects(globalConfig, method, rawArgs) {
53
+ const ignoreOptions = ["_", "$0", "v", "version", "h", "help", "g", "global-args"];
54
+ const coreArgs = {};
55
+ const optionalArgs = {};
56
+ const initArgs = {};
57
+ Object.entries(rawArgs).forEach(([argName, value]) => {
58
+ if (ignoreOptions.includes(argName) || value == null)
59
+ return;
60
+ const camelCased = camelize(argName.replace("gb-", "").replace("gl-", ""), "-");
61
+ if (globalConfig[argName.replace("gl-", "gb-")]) {
62
+ initArgs[camelCased] = value;
63
+ } else if (method.args.includes(camelCased))
64
+ coreArgs[camelCased] = value;
65
+ else
66
+ optionalArgs[camelCased] = value;
67
+ });
68
+ return {
69
+ initArgs,
70
+ coreArgs,
71
+ optionalArgs
72
+ };
73
+ }
74
+ function getDisplayConfig(globalConfig) {
75
+ const display = {};
76
+ Object.entries(globalConfig).forEach(([k, v]) => {
77
+ if (v.defaultValue == null)
78
+ return;
79
+ display[k] = {
80
+ alias: v.alias,
81
+ description: v.desc,
82
+ value: v.defaultValue
83
+ };
84
+ });
85
+ return display;
86
+ }
87
+ function getGlobalConfig(env = process.env) {
35
88
  const normalEnv = normalizeEnviromentVariables(env);
36
89
  return {
37
90
  "gb-token": {
@@ -90,34 +143,14 @@ function globalConfig(env = process.env) {
90
143
  }
91
144
  };
92
145
  }
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
- "SAML",
108
- "SCIM",
109
- "PyPI"
110
- ];
111
- exceptions.filter((e) => value.includes(e)).forEach((ex) => {
112
- cleaned = cleaned.replace(ex, ex.charAt(0).toUpperCase() + ex.slice(1).toLowerCase());
113
- });
114
- const decamelized = decamelize(cleaned, "-");
115
- return decamelized !== cleaned ? decamelized : depascalize(cleaned, "-");
146
+ function getExposedAPIs(map) {
147
+ const { Gitlab, ...expose } = map;
148
+ return expose;
116
149
  }
150
+
151
+ // src/cli.ts
117
152
  function setupAPIMethods(setupArgs, methodArgs) {
118
153
  methodArgs.forEach((name) => {
119
- if (typeof name !== "string")
120
- return;
121
154
  setupArgs.positional(`[--${param(name)}] <${param(name)}>`, {
122
155
  group: "Required Options",
123
156
  type: "string"
@@ -126,20 +159,8 @@ function setupAPIMethods(setupArgs, methodArgs) {
126
159
  return setupArgs;
127
160
  }
128
161
  function runAPIMethod(ctx, args, apiName, method) {
129
- const coreArgs = {};
130
- const optionalArgs = {};
131
- const initArgs = {};
132
- Object.entries(args).forEach(([argName, value]) => {
133
- if (ignoreOptions.includes(argName) || value == null)
134
- return;
135
- const camelCased = camelize(argName.replace("gb-", "").replace("gl-", ""), "-");
136
- if (globalConfig()[argName.replace("gl-", "gb-")]) {
137
- initArgs[camelCased] = value;
138
- } else if (method.args.includes(camelCased))
139
- coreArgs[camelCased] = value;
140
- else
141
- optionalArgs[camelCased] = value;
142
- });
162
+ const globalConfig = getGlobalConfig();
163
+ const { initArgs, coreArgs, optionalArgs } = buildArgumentObjects(globalConfig, method, args);
143
164
  const s = new Gitbeaker[apiName](initArgs);
144
165
  return s[method.name](...Object.values(coreArgs), optionalArgs).then((r) => {
145
166
  ctx.output = JSON.stringify(r, null, 3);
@@ -148,7 +169,8 @@ function runAPIMethod(ctx, args, apiName, method) {
148
169
  });
149
170
  }
150
171
  function setupAPIs(setupArgs, apiName, methods) {
151
- Object.entries(globalConfig()).forEach(([k, v]) => {
172
+ const globalConfig = getGlobalConfig();
173
+ Object.entries(globalConfig).forEach(([k, v]) => {
152
174
  setupArgs.option(`${k} <value>`, {
153
175
  group: "Base Options",
154
176
  ...v
@@ -163,14 +185,20 @@ function setupAPIs(setupArgs, apiName, methods) {
163
185
  }
164
186
  return setupArgs;
165
187
  }
188
+ var commandStyle = Chalk.hex("#e34329").bold;
189
+ var groupStyle = Chalk.hex("#fca325").bold;
190
+ var usageStyle = Chalk.hex("#fc6e26").bold;
191
+ var optionStyle = Chalk.white.bold;
192
+ var descriptionStyle = Chalk.hex("#848484");
193
+ var hintStyle = Chalk.hex("#6a5f88");
166
194
  var cli = Sywac.version("-v, --version").help("-h, --help").showHelpByDefault().epilogue("Copyright 2023").style({
167
- usagePrefix: (s) => usageStyle(s),
168
- group: (s) => groupStyle(s),
169
- flags: (s) => optionStyle(s),
170
- usageCommandPlaceholder: (s) => commandStyle(s),
171
- usageOptionsPlaceholder: (s) => optionStyle(s),
172
- desc: (s) => descriptionStyle(s),
173
- hints: (s) => hintStyle(s)
195
+ usagePrefix: usageStyle,
196
+ group: groupStyle,
197
+ flags: optionStyle,
198
+ usageCommandPlaceholder: commandStyle,
199
+ usageOptionsPlaceholder: optionStyle,
200
+ desc: descriptionStyle,
201
+ hints: hintStyle
174
202
  });
175
203
  cli.boolean("-g --global-args", {
176
204
  desc: "Show global arguments currently set in the environment variables"
@@ -178,21 +206,12 @@ cli.boolean("-g --global-args", {
178
206
  cli.command("*", (argv, ctx) => {
179
207
  if (!argv.g)
180
208
  return;
181
- const display = {};
182
- Object.entries(globalConfig()).forEach(([k, v]) => {
183
- if (v.defaultValue == null)
184
- return;
185
- display[k] = {
186
- alias: v.alias,
187
- description: v.desc,
188
- value: v.defaultValue
189
- };
190
- });
209
+ const globalConfig = getGlobalConfig();
210
+ const display = getDisplayConfig(globalConfig);
191
211
  ctx.output = Object.keys(display).length === 0 ? "No global variables have been set!" : JSON.stringify(display, null, 3);
192
212
  });
193
- Object.entries(API_MAP).forEach(([apiName, methods]) => {
194
- if (apiName === "Gitlab")
195
- return;
213
+ var exposedAPIs = getExposedAPIs(API_MAP);
214
+ Object.entries(exposedAPIs).forEach(([apiName, methods]) => {
196
215
  cli.command(param(apiName), {
197
216
  desc: `The ${apiName} API`,
198
217
  setup: (setupArgs) => setupAPIs(setupArgs, apiName, methods)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitbeaker/cli",
3
- "version": "38.0.1",
3
+ "version": "38.1.0",
4
4
  "description": "CLI implementation of the GitLab API.",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "build": "tsup src/index.ts --format esm --treeshake --target node18",
35
- "test:integration": "jest --maxWorkers=50% test/integration",
35
+ "test:unit": "jest --maxWorkers=50% test/unit",
36
36
  "test:e2e": "jest --maxWorkers=50% test/e2e",
37
37
  "format:docs": "prettier '**/(*.json|.yml|.js|.md)' --ignore-path ../../.prettierignore",
38
38
  "format:docs:fix": "yarn format:docs --write",
@@ -47,8 +47,8 @@
47
47
  "release": "auto shipit"
48
48
  },
49
49
  "dependencies": {
50
- "@gitbeaker/core": "^38.0.1",
51
- "@gitbeaker/rest": "^38.0.1",
50
+ "@gitbeaker/core": "^38.1.0",
51
+ "@gitbeaker/rest": "^38.1.0",
52
52
  "chalk": "4.1.2",
53
53
  "sywac": "^1.3.0",
54
54
  "xcase": "^2.0.1"
@@ -57,5 +57,5 @@
57
57
  "tsup": "^6.7.0",
58
58
  "typescript": "^5.0.4"
59
59
  },
60
- "gitHead": "8bb3ef8e1cef6bf85e52c32d9390829b5d92e97d"
60
+ "gitHead": "5e87cc739dc4f4b1143eb0e86f7ab3c96ade2e45"
61
61
  }