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.
@@ -21,27 +21,12 @@ const hasBinary = (command) => {
21
21
  }
22
22
  };
23
23
  const detectGlabToken = (host = 'gitlab.com') => {
24
- const candidates = [
25
- path.join(os.homedir(), '.config', 'glab-cli', 'config.yml'),
26
- path.join(os.homedir(), 'Library', 'Application Support', 'glab-cli', 'config.yml'),
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 glabToken = detectGlabToken(host);
264
+ const glabResult = detectGlabToken(host);
280
265
  const envToken = process.env.GITLAB_TOKEN || process.env.GL_TOKEN;
281
266
  let gitlabToken;
282
- if (glabToken || envToken) {
283
- const source = glabToken ? 'glab CLI' : 'environment';
284
- const detected = glabToken || envToken;
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,
@@ -669,5 +669,5 @@
669
669
  ]
670
670
  }
671
671
  },
672
- "version": "0.2.1"
672
+ "version": "0.2.2"
673
673
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duoops",
3
3
  "description": "Toolset for Explainable and Sustainable CI on Gitlab.",
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "author": "Younes Laaroussi",
6
6
  "bin": {
7
7
  "duoops": "./bin/run.js"