@gitbeaker/cli 38.0.1 → 38.1.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/README.md +46 -3
- package/dist/index.mjs +91 -72
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<br>
|
|
3
|
-
<
|
|
3
|
+
<br>
|
|
4
|
+
<img alt="gitbeaker" src="../../.github/ASSETS/header.svg">
|
|
5
|
+
<br>
|
|
6
|
+
<br>
|
|
7
|
+
<br>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div align="center">
|
|
11
|
+
<p>
|
|
12
|
+
<sup>
|
|
13
|
+
<a href="https://github.com/jdalrymple">My open source work is supported by the community</a>
|
|
14
|
+
</sup>
|
|
15
|
+
</p>
|
|
16
|
+
<br>
|
|
17
|
+
<sup>Special thanks to:</sup>
|
|
18
|
+
<br>
|
|
19
|
+
<br>
|
|
20
|
+
|
|
21
|
+
<a href="https://wearecws.com/">
|
|
22
|
+
<img src="https://wearecws.com/images/brand/cws-logo.svg" width="210">
|
|
23
|
+
</a>
|
|
24
|
+
|
|
25
|
+
<br>
|
|
26
|
+
<br>
|
|
27
|
+
<br>
|
|
28
|
+
|
|
29
|
+
<a href="https://axolo.co/gitlab-slack-integration/?ref=gitbeaker">
|
|
30
|
+
<div>
|
|
31
|
+
<img src="https://apichaos.s3.eu-west-3.amazonaws.com/logo_axolo.png" width="210" alt="Axolo Logo"/>
|
|
32
|
+
<br>
|
|
33
|
+
<br>
|
|
34
|
+
</div>
|
|
35
|
+
<b>Review merge requests in Slack to merge code faster</b>
|
|
36
|
+
<div>
|
|
37
|
+
<sub>Improve your code review process by creating an ephemeral channel per merge request.</sub>
|
|
38
|
+
<br>
|
|
39
|
+
</div>
|
|
40
|
+
</a>
|
|
41
|
+
|
|
42
|
+
<br>
|
|
43
|
+
<hr>
|
|
4
44
|
</div>
|
|
5
|
-
|
|
45
|
+
|
|
6
46
|
<p align="center">
|
|
7
47
|
<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:
|
|
48
|
+
<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
49
|
<a href="https://codeclimate.com/github/jdalrymple/gitbeaker">
|
|
10
50
|
<img src="https://codeclimate.com/github/jdalrymple/gitbeaker/badges/gpa.svg" alt="Code Climate maintainability">
|
|
11
51
|
</a>
|
|
@@ -32,6 +72,8 @@
|
|
|
32
72
|
## Table of Contents
|
|
33
73
|
|
|
34
74
|
- [Usage](#usage)
|
|
75
|
+
- [Testing](../../docs/TESTING.md)
|
|
76
|
+
- [FAQ](../../FAQ.md)
|
|
35
77
|
- [Contributors](#contributors)
|
|
36
78
|
- [Changelog](./CHANGELOG.md)
|
|
37
79
|
|
|
@@ -187,6 +229,7 @@ This could be set globally or using a [.env](https://github.com/motdotla/dotenv#
|
|
|
187
229
|
<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
230
|
<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
231
|
<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>
|
|
232
|
+
<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
233
|
</tr>
|
|
191
234
|
</p>
|
|
192
235
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 = {
|
|
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 (
|
|
29
|
-
normalized[`GITBEAKER_${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
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
168
|
-
group:
|
|
169
|
-
flags:
|
|
170
|
-
usageCommandPlaceholder:
|
|
171
|
-
usageOptionsPlaceholder:
|
|
172
|
-
desc:
|
|
173
|
-
hints:
|
|
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
|
|
182
|
-
|
|
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
|
-
|
|
194
|
-
|
|
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.
|
|
3
|
+
"version": "38.1.1",
|
|
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:
|
|
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.
|
|
51
|
-
"@gitbeaker/rest": "^38.
|
|
50
|
+
"@gitbeaker/core": "^38.1.1",
|
|
51
|
+
"@gitbeaker/rest": "^38.1.1",
|
|
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": "
|
|
60
|
+
"gitHead": "747a6a0e960524895b3fb852e5f51ca2d9f8d682"
|
|
61
61
|
}
|