@argos-ci/gitlab 0.1.10 → 0.2.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.
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import "../dist/cli.mjs";
3
+ import "../dist/cli.js";
package/dist/cli.js ADDED
@@ -0,0 +1,117 @@
1
+ // src/cli.ts
2
+ import { readFile } from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+ import { resolve } from "node:path";
5
+ import { program } from "commander";
6
+
7
+ // src/statuses.ts
8
+ import { createClient } from "@argos-ci/api-client";
9
+ import { Gitlab } from "@gitbeaker/rest";
10
+ async function run(input) {
11
+ const { argosClient, gitlabClient, gitlabProjectId, pullInterval, commit } = input;
12
+ const { data, error } = await argosClient.GET("/project/builds", {
13
+ params: {
14
+ query: {
15
+ distinctName: "true",
16
+ commit
17
+ }
18
+ }
19
+ });
20
+ if (error) {
21
+ console.error(error);
22
+ throw new Error(error.error);
23
+ }
24
+ if (data.results.length === 0) {
25
+ console.log("No builds found for commit", commit);
26
+ return;
27
+ }
28
+ await Promise.all(
29
+ data.results.map(async (build) => {
30
+ if (build.notification) {
31
+ console.log(
32
+ `Setting status for build #${build.number}: "${build.status}" (Argos) \u2192 "${build.notification.gitlab.state}" (GitLab)`
33
+ );
34
+ await gitlabClient.Commits.editStatus(
35
+ gitlabProjectId,
36
+ commit,
37
+ build.notification.gitlab.state,
38
+ {
39
+ context: build.notification.context,
40
+ targetUrl: build.url,
41
+ description: build.notification.description
42
+ }
43
+ );
44
+ }
45
+ })
46
+ );
47
+ if (data.results.some(
48
+ (build) => build.status === "pending" || build.status === "progress"
49
+ )) {
50
+ await new Promise((resolve2) => setTimeout(resolve2, pullInterval));
51
+ run(input);
52
+ }
53
+ }
54
+ async function updateGitLabCommitStatuses(input) {
55
+ const argos = createClient({
56
+ authToken: input.argosToken
57
+ });
58
+ const gitlab = new Gitlab({
59
+ oauthToken: input.gitlab.authToken,
60
+ host: input.gitlab.baseUrl
61
+ });
62
+ await run({
63
+ argosClient: argos,
64
+ gitlabClient: gitlab,
65
+ gitlabProjectId: input.gitlab.projectId,
66
+ commit: input.commit,
67
+ pullInterval: input.pullInterval ?? 3e3
68
+ });
69
+ }
70
+
71
+ // src/config.ts
72
+ function getConfig() {
73
+ if (!process.env.CI_PROJECT_ID) {
74
+ throw new Error("CI_PROJECT_ID is not set");
75
+ }
76
+ if (!process.env.CI_SERVER_URL) {
77
+ throw new Error("CI_SERVER_URL is not set");
78
+ }
79
+ if (!process.env.CI_COMMIT_SHA) {
80
+ throw new Error("CI_COMMIT_SHA is not set");
81
+ }
82
+ if (!process.env.ARGOS_GITLAB_TOKEN) {
83
+ throw new Error("ARGOS_GITLAB_TOKEN is not set");
84
+ }
85
+ if (!process.env.ARGOS_TOKEN) {
86
+ throw new Error("ARGOS_TOKEN is not set");
87
+ }
88
+ return {
89
+ commit: process.env.CI_COMMIT_SHA,
90
+ argosToken: process.env.ARGOS_TOKEN,
91
+ gitlab: {
92
+ projectId: process.env.CI_PROJECT_ID,
93
+ authToken: process.env.ARGOS_GITLAB_TOKEN,
94
+ baseUrl: process.env.CI_SERVER_URL
95
+ }
96
+ };
97
+ }
98
+
99
+ // src/cli.ts
100
+ var __dirname = fileURLToPath(new URL(".", import.meta.url));
101
+ var rawPkg = await readFile(resolve(__dirname, "..", "package.json"), "utf8");
102
+ var pkg = JSON.parse(rawPkg);
103
+ program.name(pkg.name).description("Run Argos GitLab commands from the command line.").version(pkg.version);
104
+ program.command("update-statuses").description("Update GitLab commit statuses based on Argos builds.").action(async () => {
105
+ const config = getConfig();
106
+ try {
107
+ await updateGitLabCommitStatuses(config);
108
+ } catch (error) {
109
+ console.error(error.stack);
110
+ process.exit(1);
111
+ }
112
+ });
113
+ if (!process.argv.slice(2).length) {
114
+ program.outputHelp();
115
+ } else {
116
+ program.parse(process.argv);
117
+ }
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ declare function updateGitLabCommitStatuses(input: {
11
11
  baseUrl: string;
12
12
  };
13
13
  }): Promise<void>;
14
+
14
15
  /**
15
16
  * Get the configuration from the environment variables.
16
17
  */
@@ -23,4 +24,5 @@ declare function getConfig(): {
23
24
  baseUrl: string;
24
25
  };
25
26
  };
26
- export { updateGitLabCommitStatuses, getConfig };
27
+
28
+ export { getConfig, updateGitLabCommitStatuses };
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ // src/statuses.ts
2
+ import { createClient } from "@argos-ci/api-client";
3
+ import { Gitlab } from "@gitbeaker/rest";
4
+ async function run(input) {
5
+ const { argosClient, gitlabClient, gitlabProjectId, pullInterval, commit } = input;
6
+ const { data, error } = await argosClient.GET("/project/builds", {
7
+ params: {
8
+ query: {
9
+ distinctName: "true",
10
+ commit
11
+ }
12
+ }
13
+ });
14
+ if (error) {
15
+ console.error(error);
16
+ throw new Error(error.error);
17
+ }
18
+ if (data.results.length === 0) {
19
+ console.log("No builds found for commit", commit);
20
+ return;
21
+ }
22
+ await Promise.all(
23
+ data.results.map(async (build) => {
24
+ if (build.notification) {
25
+ console.log(
26
+ `Setting status for build #${build.number}: "${build.status}" (Argos) \u2192 "${build.notification.gitlab.state}" (GitLab)`
27
+ );
28
+ await gitlabClient.Commits.editStatus(
29
+ gitlabProjectId,
30
+ commit,
31
+ build.notification.gitlab.state,
32
+ {
33
+ context: build.notification.context,
34
+ targetUrl: build.url,
35
+ description: build.notification.description
36
+ }
37
+ );
38
+ }
39
+ })
40
+ );
41
+ if (data.results.some(
42
+ (build) => build.status === "pending" || build.status === "progress"
43
+ )) {
44
+ await new Promise((resolve) => setTimeout(resolve, pullInterval));
45
+ run(input);
46
+ }
47
+ }
48
+ async function updateGitLabCommitStatuses(input) {
49
+ const argos = createClient({
50
+ authToken: input.argosToken
51
+ });
52
+ const gitlab = new Gitlab({
53
+ oauthToken: input.gitlab.authToken,
54
+ host: input.gitlab.baseUrl
55
+ });
56
+ await run({
57
+ argosClient: argos,
58
+ gitlabClient: gitlab,
59
+ gitlabProjectId: input.gitlab.projectId,
60
+ commit: input.commit,
61
+ pullInterval: input.pullInterval ?? 3e3
62
+ });
63
+ }
64
+
65
+ // src/config.ts
66
+ function getConfig() {
67
+ if (!process.env.CI_PROJECT_ID) {
68
+ throw new Error("CI_PROJECT_ID is not set");
69
+ }
70
+ if (!process.env.CI_SERVER_URL) {
71
+ throw new Error("CI_SERVER_URL is not set");
72
+ }
73
+ if (!process.env.CI_COMMIT_SHA) {
74
+ throw new Error("CI_COMMIT_SHA is not set");
75
+ }
76
+ if (!process.env.ARGOS_GITLAB_TOKEN) {
77
+ throw new Error("ARGOS_GITLAB_TOKEN is not set");
78
+ }
79
+ if (!process.env.ARGOS_TOKEN) {
80
+ throw new Error("ARGOS_TOKEN is not set");
81
+ }
82
+ return {
83
+ commit: process.env.CI_COMMIT_SHA,
84
+ argosToken: process.env.ARGOS_TOKEN,
85
+ gitlab: {
86
+ projectId: process.env.CI_PROJECT_ID,
87
+ authToken: process.env.ARGOS_GITLAB_TOKEN,
88
+ baseUrl: process.env.CI_SERVER_URL
89
+ }
90
+ };
91
+ }
92
+ export {
93
+ getConfig,
94
+ updateGitLabCommitStatuses
95
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/gitlab",
3
3
  "description": "GitLab utilities for visual testing with Argos.",
4
- "version": "0.1.10",
4
+ "version": "0.2.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -31,8 +31,8 @@
31
31
  "exports": {
32
32
  ".": {
33
33
  "types": "./dist/index.d.ts",
34
- "import": "./dist/index.mjs",
35
- "default": "./dist/index.mjs"
34
+ "import": "./dist/index.js",
35
+ "default": "./dist/index.js"
36
36
  },
37
37
  "./package.json": "./package.json"
38
38
  },
@@ -41,16 +41,15 @@
41
41
  "node": ">=18.0.0"
42
42
  },
43
43
  "scripts": {
44
- "prebuild": "rm -rf dist",
45
- "build": "rollup -c"
44
+ "build": "tsup"
46
45
  },
47
46
  "dependencies": {
48
- "@argos-ci/api-client": "0.6.2",
49
- "@gitbeaker/rest": "^40.1.2",
47
+ "@argos-ci/api-client": "0.7.0",
48
+ "@gitbeaker/rest": "^41.1.0",
50
49
  "commander": "^12.1.0"
51
50
  },
52
51
  "devDependencies": {
53
52
  "@types/node": "^18.19.44"
54
53
  },
55
- "gitHead": "d0fa8cd790ffd2343d1cd32706bcb757c4f3b26e"
54
+ "gitHead": "fe6e055a43e955e7df362ddaec59c84dc274bbb2"
56
55
  }
package/dist/cli.mjs DELETED
@@ -1,108 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { fileURLToPath } from 'node:url';
3
- import { resolve } from 'node:path';
4
- import { program } from 'commander';
5
- import { createClient } from '@argos-ci/api-client';
6
- import { Gitlab } from '@gitbeaker/rest';
7
-
8
- /**
9
- * Run the main logic of the action.
10
- */ async function run(input) {
11
- const { argosClient, gitlabClient, gitlabProjectId, pullInterval, commit } = input;
12
- const { data, error } = await argosClient.GET("/project/builds", {
13
- params: {
14
- query: {
15
- distinctName: "true",
16
- commit
17
- }
18
- }
19
- });
20
- if (error) {
21
- console.error(error);
22
- throw new Error(error.error);
23
- }
24
- if (data.results.length === 0) {
25
- console.log("No builds found for commit", commit);
26
- return;
27
- }
28
- await Promise.all(data.results.map(async (build)=>{
29
- if (build.notification) {
30
- console.log(`Setting status for build #${build.number}: "${build.status}" (Argos) → "${build.notification.gitlab.state}" (GitLab)`);
31
- await gitlabClient.Commits.editStatus(gitlabProjectId, commit, build.notification.gitlab.state, {
32
- context: build.notification.context,
33
- targetUrl: build.url,
34
- description: build.notification.description
35
- });
36
- }
37
- }));
38
- if (data.results.some((build)=>build.status === "pending" || build.status === "progress")) {
39
- await new Promise((resolve)=>setTimeout(resolve, pullInterval));
40
- run(input);
41
- }
42
- }
43
- /**
44
- * Upate GitLab commit statuses based on Argos builds.
45
- */ async function updateGitLabCommitStatuses(input) {
46
- const argos = createClient({
47
- authToken: input.argosToken
48
- });
49
- const gitlab = new Gitlab({
50
- oauthToken: input.gitlab.authToken,
51
- host: input.gitlab.baseUrl
52
- });
53
- await run({
54
- argosClient: argos,
55
- gitlabClient: gitlab,
56
- gitlabProjectId: input.gitlab.projectId,
57
- commit: input.commit,
58
- pullInterval: input.pullInterval ?? 3000
59
- });
60
- }
61
-
62
- /**
63
- * Get the configuration from the environment variables.
64
- */ function getConfig() {
65
- if (!process.env.CI_PROJECT_ID) {
66
- throw new Error("CI_PROJECT_ID is not set");
67
- }
68
- if (!process.env.CI_SERVER_URL) {
69
- throw new Error("CI_SERVER_URL is not set");
70
- }
71
- if (!process.env.CI_COMMIT_SHA) {
72
- throw new Error("CI_COMMIT_SHA is not set");
73
- }
74
- if (!process.env.ARGOS_GITLAB_TOKEN) {
75
- throw new Error("ARGOS_GITLAB_TOKEN is not set");
76
- }
77
- if (!process.env.ARGOS_TOKEN) {
78
- throw new Error("ARGOS_TOKEN is not set");
79
- }
80
- return {
81
- commit: process.env.CI_COMMIT_SHA,
82
- argosToken: process.env.ARGOS_TOKEN,
83
- gitlab: {
84
- projectId: process.env.CI_PROJECT_ID,
85
- authToken: process.env.ARGOS_GITLAB_TOKEN,
86
- baseUrl: process.env.CI_SERVER_URL
87
- }
88
- };
89
- }
90
-
91
- const __dirname = fileURLToPath(new URL(".", import.meta.url));
92
- const rawPkg = await readFile(resolve(__dirname, "..", "package.json"), "utf8");
93
- const pkg = JSON.parse(rawPkg);
94
- program.name(pkg.name).description("Run Argos GitLab commands from the command line.").version(pkg.version);
95
- program.command("update-statuses").description("Update GitLab commit statuses based on Argos builds.").action(async ()=>{
96
- const config = getConfig();
97
- try {
98
- await updateGitLabCommitStatuses(config);
99
- } catch (error) {
100
- console.error(error.stack);
101
- process.exit(1);
102
- }
103
- });
104
- if (!process.argv.slice(2).length) {
105
- program.outputHelp();
106
- } else {
107
- program.parse(process.argv);
108
- }
package/dist/index.mjs DELETED
@@ -1,87 +0,0 @@
1
- import { createClient } from '@argos-ci/api-client';
2
- import { Gitlab } from '@gitbeaker/rest';
3
-
4
- /**
5
- * Run the main logic of the action.
6
- */ async function run(input) {
7
- const { argosClient, gitlabClient, gitlabProjectId, pullInterval, commit } = input;
8
- const { data, error } = await argosClient.GET("/project/builds", {
9
- params: {
10
- query: {
11
- distinctName: "true",
12
- commit
13
- }
14
- }
15
- });
16
- if (error) {
17
- console.error(error);
18
- throw new Error(error.error);
19
- }
20
- if (data.results.length === 0) {
21
- console.log("No builds found for commit", commit);
22
- return;
23
- }
24
- await Promise.all(data.results.map(async (build)=>{
25
- if (build.notification) {
26
- console.log(`Setting status for build #${build.number}: "${build.status}" (Argos) → "${build.notification.gitlab.state}" (GitLab)`);
27
- await gitlabClient.Commits.editStatus(gitlabProjectId, commit, build.notification.gitlab.state, {
28
- context: build.notification.context,
29
- targetUrl: build.url,
30
- description: build.notification.description
31
- });
32
- }
33
- }));
34
- if (data.results.some((build)=>build.status === "pending" || build.status === "progress")) {
35
- await new Promise((resolve)=>setTimeout(resolve, pullInterval));
36
- run(input);
37
- }
38
- }
39
- /**
40
- * Upate GitLab commit statuses based on Argos builds.
41
- */ async function updateGitLabCommitStatuses(input) {
42
- const argos = createClient({
43
- authToken: input.argosToken
44
- });
45
- const gitlab = new Gitlab({
46
- oauthToken: input.gitlab.authToken,
47
- host: input.gitlab.baseUrl
48
- });
49
- await run({
50
- argosClient: argos,
51
- gitlabClient: gitlab,
52
- gitlabProjectId: input.gitlab.projectId,
53
- commit: input.commit,
54
- pullInterval: input.pullInterval ?? 3000
55
- });
56
- }
57
-
58
- /**
59
- * Get the configuration from the environment variables.
60
- */ function getConfig() {
61
- if (!process.env.CI_PROJECT_ID) {
62
- throw new Error("CI_PROJECT_ID is not set");
63
- }
64
- if (!process.env.CI_SERVER_URL) {
65
- throw new Error("CI_SERVER_URL is not set");
66
- }
67
- if (!process.env.CI_COMMIT_SHA) {
68
- throw new Error("CI_COMMIT_SHA is not set");
69
- }
70
- if (!process.env.ARGOS_GITLAB_TOKEN) {
71
- throw new Error("ARGOS_GITLAB_TOKEN is not set");
72
- }
73
- if (!process.env.ARGOS_TOKEN) {
74
- throw new Error("ARGOS_TOKEN is not set");
75
- }
76
- return {
77
- commit: process.env.CI_COMMIT_SHA,
78
- argosToken: process.env.ARGOS_TOKEN,
79
- gitlab: {
80
- projectId: process.env.CI_PROJECT_ID,
81
- authToken: process.env.ARGOS_GITLAB_TOKEN,
82
- baseUrl: process.env.CI_SERVER_URL
83
- }
84
- };
85
- }
86
-
87
- export { getConfig, updateGitLabCommitStatuses };