@catladder/cli 1.150.3 → 1.152.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/package.json CHANGED
@@ -52,7 +52,7 @@
52
52
  }
53
53
  ],
54
54
  "license": "MIT",
55
- "version": "1.150.3",
55
+ "version": "1.152.0",
56
56
  "scripts": {
57
57
  "lint": "eslint \"src/**/*.ts\"",
58
58
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -0,0 +1,12 @@
1
+ import type Vorpal from "vorpal";
2
+ import { setupAccessTokens } from "./setup/setupAccessTokens";
3
+
4
+ export default async (vorpal: Vorpal) =>
5
+ vorpal
6
+ .command(
7
+ "project-renew-token",
8
+ "Configures the project access token for semantic release.",
9
+ )
10
+ .action(async function () {
11
+ await setupAccessTokens(this);
12
+ });
@@ -9,6 +9,7 @@ import commandGetMyTotalWorktime from "./commandGetMyTotalWorktime";
9
9
  import commandGetShell from "./commandGetShell";
10
10
  import commandGitlabCi from "./commandGitlabCi";
11
11
  import commandSetup from "./commandSetup";
12
+ import commandRenewToken from "./commandRenewToken";
12
13
  import commandListPods from "./commandListPods";
13
14
  import commandMigrateHelm3 from "./commandMigrateHelm3";
14
15
  import commandNamespace from "./commandNamespace";
@@ -29,6 +30,7 @@ import commandSecurityEvaluate from "./commandSecurityEvaluate";
29
30
 
30
31
  export default async (vorpal: Vorpal) => {
31
32
  commandSetup(vorpal);
33
+ commandRenewToken(vorpal);
32
34
 
33
35
  commandEnvVars(vorpal);
34
36
 
@@ -1,57 +1,70 @@
1
- import open from "open";
2
1
  import type { CommandInstance } from "vorpal";
2
+ import dayjs from "dayjs";
3
3
  import { doGitlabRequest, getProjectInfo } from "../../../../../utils/gitlab";
4
4
 
5
+ const TOKEN_NAME = "semantic-release";
6
+
5
7
  export const setupAccessTokens = async (instance: CommandInstance) => {
6
- const { id: projectId, web_url: projectWebUrl } =
7
- await getProjectInfo(instance);
8
+ const { id: projectId } = await getProjectInfo(instance);
9
+
10
+ const projectTokens = await doGitlabRequest(
11
+ instance,
12
+ `projects/${projectId}/access_tokens`,
13
+ );
14
+ const token = projectTokens.find(
15
+ (t) => t.name === TOKEN_NAME && t.active === true,
16
+ );
17
+
18
+ const expires_at = dayjs()
19
+ .add(1, "year")
20
+ .subtract(1, "day")
21
+ .format("YYYY-MM-DD");
22
+
23
+ const newToken = token
24
+ ? await doGitlabRequest(
25
+ instance,
26
+ `projects/${projectId}/access_tokens/${token.id}/rotate`,
27
+ { expires_at },
28
+ "POST",
29
+ )
30
+ : await doGitlabRequest(
31
+ instance,
32
+ `projects/${projectId}/access_tokens`,
33
+ {
34
+ name: TOKEN_NAME,
35
+ scopes: ["api", "read_repository"],
36
+ access_level: 40, // Maintainer
37
+ expires_at,
38
+ },
39
+ "POST",
40
+ );
41
+
8
42
  try {
9
43
  await doGitlabRequest(instance, `projects/${projectId}/variables/GL_TOKEN`);
44
+ await doGitlabRequest(
45
+ instance,
46
+ `projects/${projectId}/variables/GL_TOKEN`,
47
+ { value: newToken.token },
48
+ "PUT",
49
+ );
10
50
  } catch (e) {
11
51
  if (e.message !== "not found") {
12
52
  throw e;
13
53
  }
14
54
  // not found
15
-
16
- instance.log(
17
- "I need add a GL_TOKEN to the project, so that semantic release will work\n",
18
- );
19
- instance.log(
20
- "👉 Please please create a project access token in gitlab and copy its value into clipboard\n\n - name: something like 'semantic-release'\n - expires: leave empty\n - role: maintainer - scopes: api, read_repository",
21
- );
22
- instance.log("\n");
23
-
24
- const { understood } = await instance.prompt({
25
- default: true,
26
- message: "Understood and open gitlab now? 🤔",
27
- name: "understood",
28
- type: "confirm",
29
- });
30
- if (!understood) {
31
- instance.log("continuing anyway...");
32
- }
33
- open(`${projectWebUrl}/-/settings/access_tokens`);
34
-
35
- instance.log("\n");
36
-
37
- instance.log("Enter your copied token now: ");
38
-
39
- instance.log("\n");
40
- const { GL_TOKEN } = await instance.prompt({
41
- type: "password",
42
- name: "GL_TOKEN",
43
- message: "Access Token: ",
44
- });
45
-
46
55
  await doGitlabRequest(
47
56
  instance,
48
57
  `projects/${projectId}/variables`,
49
58
  {
50
59
  key: "GL_TOKEN",
51
- value: GL_TOKEN,
60
+ value: newToken.token,
52
61
  masked: true,
53
62
  },
54
63
  "POST",
55
64
  );
56
65
  }
66
+
67
+ instance.log(
68
+ "Token configured for semantic release. Renew me again in a year!",
69
+ );
57
70
  };
package/src/catenv.ts CHANGED
@@ -2,9 +2,19 @@ import catenv from "./apps/catenv/catenv";
2
2
 
3
3
  import { parseChoice } from "./config/parseChoice";
4
4
 
5
- const choice = process.argv[2] ? parseChoice(process.argv[2]) : null;
5
+ const args = process.argv.slice(2);
6
6
 
7
- catenv(choice).then(() => {
7
+ const helpFlags = ["--help", "-h", "help"];
8
+ if (args.some((arg) => helpFlags.includes(arg))) {
9
+ const docLink =
10
+ "https://git.panter.ch/catladder/catladder/-/blob/main/docs/1_VARS.md";
11
+ console.log(
12
+ `\nUsage: catenv [env|env:component]\n\nEnv variable and catenv documentation:\n${docLink}`,
13
+ );
14
+ process.exit(0);
15
+ }
16
+
17
+ catenv(args[0] ? parseChoice(args[0]) : null).then(() => {
8
18
  // we have to exit manually, because we have some file watches
9
19
  process.exit();
10
20
  });