duoops 0.2.1 → 0.2.2
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/commands/init.js +9 -24
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -21,27 +21,12 @@ const hasBinary = (command) => {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
const detectGlabToken = (host = 'gitlab.com') => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const configPath of candidates) {
|
|
29
|
-
try {
|
|
30
|
-
if (!fs.existsSync(configPath))
|
|
31
|
-
continue;
|
|
32
|
-
const content = fs.readFileSync(configPath, 'utf8');
|
|
33
|
-
const hostSection = content.split(`${host}:`)[1];
|
|
34
|
-
if (!hostSection)
|
|
35
|
-
continue;
|
|
36
|
-
const isOauth = hostSection.match(/is_oauth2:\s*"?true"?/);
|
|
37
|
-
if (isOauth)
|
|
38
|
-
continue;
|
|
39
|
-
const tokenMatch = hostSection.match(/token:\s*(?:!!null\s+)?(\S+)/);
|
|
40
|
-
if (tokenMatch?.[1] && tokenMatch[1].startsWith('glpat-'))
|
|
41
|
-
return tokenMatch[1];
|
|
42
|
-
}
|
|
43
|
-
catch { /* ignore */ }
|
|
24
|
+
try {
|
|
25
|
+
const token = execSync(`glab config get token --host ${host}`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim();
|
|
26
|
+
if (token)
|
|
27
|
+
return { source: 'glab CLI', token };
|
|
44
28
|
}
|
|
29
|
+
catch { /* glab not installed or not authenticated */ }
|
|
45
30
|
};
|
|
46
31
|
const detectGitRemotePath = () => {
|
|
47
32
|
try {
|
|
@@ -276,12 +261,12 @@ export default class Init extends Command {
|
|
|
276
261
|
message: 'GitLab URL',
|
|
277
262
|
});
|
|
278
263
|
const { host } = new URL(gitlabUrl);
|
|
279
|
-
const
|
|
264
|
+
const glabResult = detectGlabToken(host);
|
|
280
265
|
const envToken = process.env.GITLAB_TOKEN || process.env.GL_TOKEN;
|
|
281
266
|
let gitlabToken;
|
|
282
|
-
if (
|
|
283
|
-
const source =
|
|
284
|
-
const detected =
|
|
267
|
+
if (glabResult || envToken) {
|
|
268
|
+
const source = glabResult ? glabResult.source : 'environment';
|
|
269
|
+
const detected = glabResult ? glabResult.token : envToken;
|
|
285
270
|
const masked = detected.slice(0, 6) + '...' + detected.slice(-4);
|
|
286
271
|
const useDetected = await confirm({
|
|
287
272
|
default: true,
|
package/oclif.manifest.json
CHANGED