@codefresh-io/gitops-release 0.1.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/README.md +397 -0
- package/dist/commands/cherry-pick.d.ts +14 -0
- package/dist/commands/cherry-pick.d.ts.map +1 -0
- package/dist/commands/cherry-pick.js +337 -0
- package/dist/commands/cherry-pick.js.map +1 -0
- package/dist/commands/cherry-pick.test.d.ts +2 -0
- package/dist/commands/cherry-pick.test.d.ts.map +1 -0
- package/dist/commands/cherry-pick.test.js +377 -0
- package/dist/commands/cherry-pick.test.js.map +1 -0
- package/dist/commands/completion.d.ts +11 -0
- package/dist/commands/completion.d.ts.map +1 -0
- package/dist/commands/completion.js +195 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/completion.test.d.ts +2 -0
- package/dist/commands/completion.test.d.ts.map +1 -0
- package/dist/commands/completion.test.js +142 -0
- package/dist/commands/completion.test.js.map +1 -0
- package/dist/commands/create.d.ts +15 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +107 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/create.test.d.ts +2 -0
- package/dist/commands/create.test.d.ts.map +1 -0
- package/dist/commands/create.test.js +274 -0
- package/dist/commands/create.test.js.map +1 -0
- package/dist/commands/list.d.ts +14 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +69 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/notes.d.ts +15 -0
- package/dist/commands/notes.d.ts.map +1 -0
- package/dist/commands/notes.js +374 -0
- package/dist/commands/notes.js.map +1 -0
- package/dist/commands/publish.d.ts +14 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +220 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/publish.test.d.ts +2 -0
- package/dist/commands/publish.test.d.ts.map +1 -0
- package/dist/commands/publish.test.js +371 -0
- package/dist/commands/publish.test.js.map +1 -0
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +258 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/context.d.ts +35 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +48 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +152 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +161 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +398 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/formatter.test.d.ts +2 -0
- package/dist/output/formatter.test.d.ts.map +1 -0
- package/dist/output/formatter.test.js +223 -0
- package/dist/output/formatter.test.js.map +1 -0
- package/dist/services/ai.d.ts +69 -0
- package/dist/services/ai.d.ts.map +1 -0
- package/dist/services/ai.js +235 -0
- package/dist/services/ai.js.map +1 -0
- package/dist/services/ai.test.d.ts +2 -0
- package/dist/services/ai.test.d.ts.map +1 -0
- package/dist/services/ai.test.js +101 -0
- package/dist/services/ai.test.js.map +1 -0
- package/dist/services/github.d.ts +200 -0
- package/dist/services/github.d.ts.map +1 -0
- package/dist/services/github.js +465 -0
- package/dist/services/github.js.map +1 -0
- package/dist/services/github.test.d.ts +2 -0
- package/dist/services/github.test.d.ts.map +1 -0
- package/dist/services/github.test.js +64 -0
- package/dist/services/github.test.js.map +1 -0
- package/dist/services/version.d.ts +106 -0
- package/dist/services/version.d.ts.map +1 -0
- package/dist/services/version.js +158 -0
- package/dist/services/version.js.map +1 -0
- package/dist/services/version.test.d.ts +2 -0
- package/dist/services/version.test.d.ts.map +1 -0
- package/dist/services/version.test.js +136 -0
- package/dist/services/version.test.js.map +1 -0
- package/dist/utils/errors.d.ts +66 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +154 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/errors.test.d.ts +2 -0
- package/dist/utils/errors.test.d.ts.map +1 -0
- package/dist/utils/errors.test.js +147 -0
- package/dist/utils/errors.test.js.map +1 -0
- package/dist/utils/prompts.d.ts +54 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +108 -0
- package/dist/utils/prompts.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// ABOUTME: Custom error classes for the CLI with exit code support.
|
|
2
|
+
// ABOUTME: Each error type maps to a specific exit code for scripting use.
|
|
3
|
+
/**
|
|
4
|
+
* Exit codes used by the CLI.
|
|
5
|
+
* These are consistent across all commands for scripting compatibility.
|
|
6
|
+
*/
|
|
7
|
+
export const ExitCode = {
|
|
8
|
+
Success: 0,
|
|
9
|
+
GenericError: 1,
|
|
10
|
+
InvalidUsage: 2,
|
|
11
|
+
GitHubError: 3,
|
|
12
|
+
NotFound: 4,
|
|
13
|
+
UserCancelled: 5,
|
|
14
|
+
AIError: 6,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Base class for all CLI errors.
|
|
18
|
+
* Includes an exit code that will be used when the process exits.
|
|
19
|
+
*/
|
|
20
|
+
export class CLIError extends Error {
|
|
21
|
+
exitCode;
|
|
22
|
+
constructor(message, exitCode = ExitCode.GenericError) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "CLIError";
|
|
25
|
+
this.exitCode = exitCode;
|
|
26
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when user provides invalid arguments or version format.
|
|
31
|
+
* Exit code: 2
|
|
32
|
+
*/
|
|
33
|
+
export class ValidationError extends CLIError {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message, ExitCode.InvalidUsage);
|
|
36
|
+
this.name = "ValidationError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Thrown when a GitHub API operation fails.
|
|
41
|
+
* Exit code: 3
|
|
42
|
+
*/
|
|
43
|
+
export class GitHubError extends CLIError {
|
|
44
|
+
statusCode;
|
|
45
|
+
suggestion;
|
|
46
|
+
constructor(message, statusCode, suggestion) {
|
|
47
|
+
super(message, ExitCode.GitHubError);
|
|
48
|
+
this.name = "GitHubError";
|
|
49
|
+
this.statusCode = statusCode;
|
|
50
|
+
this.suggestion = suggestion;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Thrown when a required resource is not found (branch, PR, release, etc.).
|
|
55
|
+
* Exit code: 4
|
|
56
|
+
*/
|
|
57
|
+
export class NotFoundError extends CLIError {
|
|
58
|
+
resource;
|
|
59
|
+
constructor(resource, message) {
|
|
60
|
+
super(message ?? `${resource} not found`, ExitCode.NotFound);
|
|
61
|
+
this.name = "NotFoundError";
|
|
62
|
+
this.resource = resource;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Thrown when the user cancels an operation.
|
|
67
|
+
* Exit code: 5
|
|
68
|
+
*/
|
|
69
|
+
export class UserCancelledError extends CLIError {
|
|
70
|
+
constructor(message = "Operation cancelled by user") {
|
|
71
|
+
super(message, ExitCode.UserCancelled);
|
|
72
|
+
this.name = "UserCancelledError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Thrown when AI generation fails.
|
|
77
|
+
* Exit code: 6
|
|
78
|
+
*/
|
|
79
|
+
export class AIError extends CLIError {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message, ExitCode.AIError);
|
|
82
|
+
this.name = "AIError";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets a suggestion based on the error type and status code.
|
|
87
|
+
*/
|
|
88
|
+
function getSuggestion(error) {
|
|
89
|
+
if (error instanceof GitHubError) {
|
|
90
|
+
if (error.suggestion) {
|
|
91
|
+
return error.suggestion;
|
|
92
|
+
}
|
|
93
|
+
switch (error.statusCode) {
|
|
94
|
+
case 401:
|
|
95
|
+
return "Check that GITHUB_TOKEN is set and valid.";
|
|
96
|
+
case 403:
|
|
97
|
+
return "Check that GITHUB_TOKEN has the required permissions (repo scope).";
|
|
98
|
+
case 404:
|
|
99
|
+
return "The resource may not exist or you may not have access to it.";
|
|
100
|
+
case 422:
|
|
101
|
+
return "The request was invalid. Check your input and try again.";
|
|
102
|
+
case 429:
|
|
103
|
+
return "Rate limit exceeded. Wait a few minutes and try again.";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (error instanceof NotFoundError) {
|
|
107
|
+
if (error.resource.includes("Branch")) {
|
|
108
|
+
return "Run 'gitops-release status' to see available branches.";
|
|
109
|
+
}
|
|
110
|
+
if (error.resource.includes("PR")) {
|
|
111
|
+
return "Run 'gitops-release status <version>' to check PR status.";
|
|
112
|
+
}
|
|
113
|
+
if (error.resource.includes("release") || error.resource.includes("Release")) {
|
|
114
|
+
return "Run 'gitops-release list --include-drafts' to see all releases.";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (error instanceof AIError) {
|
|
118
|
+
return "Check that ANTHROPIC_API_KEY is set and valid.";
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Handles an error and exits the process with the appropriate code.
|
|
124
|
+
* For CLIError subclasses, uses their exit code. For other errors, uses 1.
|
|
125
|
+
*/
|
|
126
|
+
export function handleError(error) {
|
|
127
|
+
if (error instanceof CLIError) {
|
|
128
|
+
console.error(`Error: ${error.message}`);
|
|
129
|
+
const suggestion = getSuggestion(error);
|
|
130
|
+
if (suggestion) {
|
|
131
|
+
console.error(`\nHint: ${suggestion}`);
|
|
132
|
+
}
|
|
133
|
+
process.exit(error.exitCode);
|
|
134
|
+
}
|
|
135
|
+
if (error instanceof Error) {
|
|
136
|
+
// Check for common error patterns that aren't CLIErrors
|
|
137
|
+
const msg = error.message.toLowerCase();
|
|
138
|
+
console.error(`Error: ${error.message}`);
|
|
139
|
+
if (msg.includes("github_token") || msg.includes("unauthorized") || msg.includes("bad credentials")) {
|
|
140
|
+
console.error("\nHint: Set GITHUB_TOKEN environment variable with a valid token.");
|
|
141
|
+
}
|
|
142
|
+
else if (msg.includes("anthropic") || msg.includes("api_key")) {
|
|
143
|
+
console.error("\nHint: Set ANTHROPIC_API_KEY environment variable for the notes command.");
|
|
144
|
+
}
|
|
145
|
+
else if (msg.includes("enotfound") || msg.includes("network") || msg.includes("fetch failed")) {
|
|
146
|
+
console.error("\nHint: Check your network connection and try again.");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.error("An unexpected error occurred");
|
|
151
|
+
}
|
|
152
|
+
process.exit(ExitCode.GenericError);
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,2EAA2E;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE,CAAC;IACV,YAAY,EAAE,CAAC;IACf,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,QAAQ,EAAE,CAAC;IACX,aAAa,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC;CACF,CAAC;AAIX;;;GAGG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,QAAQ,CAAgB;IAEjC,YAAY,OAAe,EAAE,WAA0B,QAAQ,CAAC,YAAY;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,eAAgB,S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
|
|
1
|
+
// ABOUTME: Unit tests for custom error classes and exit codes.
|
|
2
|
+
// ABOUTME: Verifies each error type has correct exit code and properties.
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { ExitCode, CLIError, ValidationError, GitHubError, NotFoundError, UserCancelledError, AIError, } from "./errors.js";
|
|
5
|
+
describe("ExitCode constants", () => {
|
|
6
|
+
it("has correct values", () => {
|
|
7
|
+
expect(ExitCode.Success).toBe(0);
|
|
8
|
+
expect(ExitCode.GenericError).toBe(1);
|
|
9
|
+
expect(ExitCode.InvalidUsage).toBe(2);
|
|
10
|
+
expect(ExitCode.GitHubError).toBe(3);
|
|
11
|
+
expect(ExitCode.NotFound).toBe(4);
|
|
12
|
+
expect(ExitCode.UserCancelled).toBe(5);
|
|
13
|
+
expect(ExitCode.AIError).toBe(6);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe("CLIError", () => {
|
|
17
|
+
it("creates error with message and default exit code", () => {
|
|
18
|
+
const error = new CLIError("test error");
|
|
19
|
+
expect(error.message).toBe("test error");
|
|
20
|
+
expect(error.exitCode).toBe(ExitCode.GenericError);
|
|
21
|
+
expect(error.name).toBe("CLIError");
|
|
22
|
+
});
|
|
23
|
+
it("creates error with custom exit code", () => {
|
|
24
|
+
const error = new CLIError("test error", ExitCode.NotFound);
|
|
25
|
+
expect(error.exitCode).toBe(ExitCode.NotFound);
|
|
26
|
+
});
|
|
27
|
+
it("is instance of Error", () => {
|
|
28
|
+
const error = new CLIError("test");
|
|
29
|
+
expect(error).toBeInstanceOf(Error);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("ValidationError", () => {
|
|
33
|
+
it("has exit code 2 (InvalidUsage)", () => {
|
|
34
|
+
const error = new ValidationError("invalid input");
|
|
35
|
+
expect(error.exitCode).toBe(ExitCode.InvalidUsage);
|
|
36
|
+
expect(error.exitCode).toBe(2);
|
|
37
|
+
});
|
|
38
|
+
it("has correct name", () => {
|
|
39
|
+
const error = new ValidationError("test");
|
|
40
|
+
expect(error.name).toBe("ValidationError");
|
|
41
|
+
});
|
|
42
|
+
it("is instance of CLIError", () => {
|
|
43
|
+
const error = new ValidationError("test");
|
|
44
|
+
expect(error).toBeInstanceOf(CLIError);
|
|
45
|
+
expect(error).toBeInstanceOf(Error);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("GitHubError", () => {
|
|
49
|
+
it("has exit code 3", () => {
|
|
50
|
+
const error = new GitHubError("api failed");
|
|
51
|
+
expect(error.exitCode).toBe(ExitCode.GitHubError);
|
|
52
|
+
expect(error.exitCode).toBe(3);
|
|
53
|
+
});
|
|
54
|
+
it("stores HTTP status code", () => {
|
|
55
|
+
const error = new GitHubError("not found", 404);
|
|
56
|
+
expect(error.statusCode).toBe(404);
|
|
57
|
+
});
|
|
58
|
+
it("has undefined status code when not provided", () => {
|
|
59
|
+
const error = new GitHubError("api failed");
|
|
60
|
+
expect(error.statusCode).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
it("has correct name", () => {
|
|
63
|
+
const error = new GitHubError("test");
|
|
64
|
+
expect(error.name).toBe("GitHubError");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("NotFoundError", () => {
|
|
68
|
+
it("has exit code 4", () => {
|
|
69
|
+
const error = new NotFoundError("Branch 'main'");
|
|
70
|
+
expect(error.exitCode).toBe(ExitCode.NotFound);
|
|
71
|
+
expect(error.exitCode).toBe(4);
|
|
72
|
+
});
|
|
73
|
+
it("stores resource name", () => {
|
|
74
|
+
const error = new NotFoundError("Branch 'main'");
|
|
75
|
+
expect(error.resource).toBe("Branch 'main'");
|
|
76
|
+
});
|
|
77
|
+
it("generates default message from resource", () => {
|
|
78
|
+
const error = new NotFoundError("Branch 'main'");
|
|
79
|
+
expect(error.message).toBe("Branch 'main' not found");
|
|
80
|
+
});
|
|
81
|
+
it("uses custom message when provided", () => {
|
|
82
|
+
const error = new NotFoundError("PR", "Pull request #123 does not exist");
|
|
83
|
+
expect(error.message).toBe("Pull request #123 does not exist");
|
|
84
|
+
expect(error.resource).toBe("PR");
|
|
85
|
+
});
|
|
86
|
+
it("has correct name", () => {
|
|
87
|
+
const error = new NotFoundError("test");
|
|
88
|
+
expect(error.name).toBe("NotFoundError");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("UserCancelledError", () => {
|
|
92
|
+
it("has exit code 5", () => {
|
|
93
|
+
const error = new UserCancelledError();
|
|
94
|
+
expect(error.exitCode).toBe(ExitCode.UserCancelled);
|
|
95
|
+
expect(error.exitCode).toBe(5);
|
|
96
|
+
});
|
|
97
|
+
it("has default message", () => {
|
|
98
|
+
const error = new UserCancelledError();
|
|
99
|
+
expect(error.message).toBe("Operation cancelled by user");
|
|
100
|
+
});
|
|
101
|
+
it("accepts custom message", () => {
|
|
102
|
+
const error = new UserCancelledError("Publish cancelled");
|
|
103
|
+
expect(error.message).toBe("Publish cancelled");
|
|
104
|
+
});
|
|
105
|
+
it("has correct name", () => {
|
|
106
|
+
const error = new UserCancelledError();
|
|
107
|
+
expect(error.name).toBe("UserCancelledError");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe("AIError", () => {
|
|
111
|
+
it("has exit code 6", () => {
|
|
112
|
+
const error = new AIError("generation failed");
|
|
113
|
+
expect(error.exitCode).toBe(ExitCode.AIError);
|
|
114
|
+
expect(error.exitCode).toBe(6);
|
|
115
|
+
});
|
|
116
|
+
it("has correct name", () => {
|
|
117
|
+
const error = new AIError("test");
|
|
118
|
+
expect(error.name).toBe("AIError");
|
|
119
|
+
});
|
|
120
|
+
it("is instance of CLIError", () => {
|
|
121
|
+
const error = new AIError("test");
|
|
122
|
+
expect(error).toBeInstanceOf(CLIError);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
describe("error inheritance", () => {
|
|
126
|
+
it("all custom errors inherit from CLIError", () => {
|
|
127
|
+
expect(new ValidationError("")).toBeInstanceOf(CLIError);
|
|
128
|
+
expect(new GitHubError("")).toBeInstanceOf(CLIError);
|
|
129
|
+
expect(new NotFoundError("")).toBeInstanceOf(CLIError);
|
|
130
|
+
expect(new UserCancelledError()).toBeInstanceOf(CLIError);
|
|
131
|
+
expect(new AIError("")).toBeInstanceOf(CLIError);
|
|
132
|
+
});
|
|
133
|
+
it("all errors can be caught as Error", () => {
|
|
134
|
+
const errors = [
|
|
135
|
+
new CLIError(""),
|
|
136
|
+
new ValidationError(""),
|
|
137
|
+
new GitHubError(""),
|
|
138
|
+
new NotFoundError(""),
|
|
139
|
+
new UserCancelledError(),
|
|
140
|
+
new AIError(""),
|
|
141
|
+
];
|
|
142
|
+
for (const error of errors) {
|
|
143
|
+
expect(error).toBeInstanceOf(Error);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=errors.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../../src/utils/errors.test.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,0EAA0E;AAE1E,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,OAAO,GACR,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAC5B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC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;IACjC,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACrD,MAAM,CAAC,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACvD,MAAM,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1D,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,MAAM,GAAG;YACb,IAAI,QAAQ,CAAC,EAAE,CAAC;YAChB,IAAI,eAAe,CAAC,EAAE,CAAC;YACvB,IAAI,WAAW,CAAC,EAAE,CAAC;YACnB,IAAI,aAAa,CAAC,EAAE,CAAC;YACrB,IAAI,kBAAkB,EAAE;YACxB,IAAI,OAAO,CAAC,EAAE,CAAC;SAChB,CAAC;QAEF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for prompts that can be skipped.
|
|
3
|
+
*/
|
|
4
|
+
export interface PromptOptions {
|
|
5
|
+
force?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Detects if stdin is a TTY (interactive terminal).
|
|
9
|
+
*/
|
|
10
|
+
export declare function isInteractive(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Prompts the user for confirmation.
|
|
13
|
+
* Returns true if confirmed, throws UserCancelledError if declined.
|
|
14
|
+
*
|
|
15
|
+
* If force is true or stdin is not a TTY, returns true without prompting.
|
|
16
|
+
*/
|
|
17
|
+
export declare function confirm(message: string, options?: PromptOptions): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Prompts the user for confirmation with a default of "no".
|
|
20
|
+
* Useful for destructive operations.
|
|
21
|
+
*/
|
|
22
|
+
export declare function confirmDangerous(message: string, options?: PromptOptions): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Choice option for select prompts.
|
|
25
|
+
*/
|
|
26
|
+
export interface Choice<T> {
|
|
27
|
+
name: string;
|
|
28
|
+
value: T;
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prompts the user to select from a list of choices.
|
|
33
|
+
* Throws UserCancelledError if cancelled.
|
|
34
|
+
*/
|
|
35
|
+
export declare function selectOption<T>(message: string, choices: Choice<T>[]): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Prompts the user for text input.
|
|
38
|
+
* Throws UserCancelledError if empty and required.
|
|
39
|
+
*/
|
|
40
|
+
export declare function promptInput(message: string, options?: {
|
|
41
|
+
default?: string;
|
|
42
|
+
required?: boolean;
|
|
43
|
+
}): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Shows a prompt asking the user if they want to continue.
|
|
46
|
+
* Used after showing a preview in dry-run mode.
|
|
47
|
+
*/
|
|
48
|
+
export declare function confirmContinue(options?: PromptOptions): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Shows a preview message and asks for confirmation.
|
|
51
|
+
* Returns true if the user confirms, false otherwise.
|
|
52
|
+
*/
|
|
53
|
+
export declare function confirmWithPreview(previewMessage: string, confirmMessage: string, options?: PromptOptions): Promise<boolean>;
|
|
54
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +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1
|
+
// ABOUTME: Interactive prompts utility with TTY detection.
|
|
2
|
+
// ABOUTME: Handles confirmation dialogs and respects --force flag for non-interactive use.
|
|
3
|
+
import { confirm as inquirerConfirm, select, input } from "@inquirer/prompts";
|
|
4
|
+
import { UserCancelledError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Detects if stdin is a TTY (interactive terminal).
|
|
7
|
+
*/
|
|
8
|
+
export function isInteractive() {
|
|
9
|
+
return process.stdin.isTTY === true;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Prompts the user for confirmation.
|
|
13
|
+
* Returns true if confirmed, throws UserCancelledError if declined.
|
|
14
|
+
*
|
|
15
|
+
* If force is true or stdin is not a TTY, returns true without prompting.
|
|
16
|
+
*/
|
|
17
|
+
export async function confirm(message, options = {}) {
|
|
18
|
+
if (options.force || !isInteractive()) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const result = await inquirerConfirm({
|
|
22
|
+
message,
|
|
23
|
+
default: true,
|
|
24
|
+
});
|
|
25
|
+
if (!result) {
|
|
26
|
+
throw new UserCancelledError();
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Prompts the user for confirmation with a default of "no".
|
|
32
|
+
* Useful for destructive operations.
|
|
33
|
+
*/
|
|
34
|
+
export async function confirmDangerous(message, options = {}) {
|
|
35
|
+
if (options.force) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (!isInteractive()) {
|
|
39
|
+
throw new UserCancelledError("This operation requires confirmation. Use --force to skip in non-interactive mode.");
|
|
40
|
+
}
|
|
41
|
+
const result = await inquirerConfirm({
|
|
42
|
+
message,
|
|
43
|
+
default: false,
|
|
44
|
+
});
|
|
45
|
+
if (!result) {
|
|
46
|
+
throw new UserCancelledError();
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Prompts the user to select from a list of choices.
|
|
52
|
+
* Throws UserCancelledError if cancelled.
|
|
53
|
+
*/
|
|
54
|
+
export async function selectOption(message, choices) {
|
|
55
|
+
if (!isInteractive()) {
|
|
56
|
+
throw new UserCancelledError("This operation requires interactive input.");
|
|
57
|
+
}
|
|
58
|
+
const result = await select({
|
|
59
|
+
message,
|
|
60
|
+
choices: choices.map((c) => ({
|
|
61
|
+
name: c.name,
|
|
62
|
+
value: c.value,
|
|
63
|
+
description: c.description,
|
|
64
|
+
})),
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Prompts the user for text input.
|
|
70
|
+
* Throws UserCancelledError if empty and required.
|
|
71
|
+
*/
|
|
72
|
+
export async function promptInput(message, options = {}) {
|
|
73
|
+
if (!isInteractive()) {
|
|
74
|
+
if (options.default !== undefined) {
|
|
75
|
+
return options.default;
|
|
76
|
+
}
|
|
77
|
+
throw new UserCancelledError("This operation requires interactive input.");
|
|
78
|
+
}
|
|
79
|
+
const result = await input({
|
|
80
|
+
message,
|
|
81
|
+
default: options.default,
|
|
82
|
+
validate: (value) => {
|
|
83
|
+
if (options.required && !value.trim()) {
|
|
84
|
+
return "This field is required";
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Shows a prompt asking the user if they want to continue.
|
|
93
|
+
* Used after showing a preview in dry-run mode.
|
|
94
|
+
*/
|
|
95
|
+
export async function confirmContinue(options = {}) {
|
|
96
|
+
return confirm("Do you want to continue?", options);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Shows a preview message and asks for confirmation.
|
|
100
|
+
* Returns true if the user confirms, false otherwise.
|
|
101
|
+
*/
|
|
102
|
+
export async function confirmWithPreview(previewMessage, confirmMessage, options = {}) {
|
|
103
|
+
console.log();
|
|
104
|
+
console.log(previewMessage);
|
|
105
|
+
console.log();
|
|
106
|
+
return confirm(confirmMessage, options);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/utils/prompts.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,2FAA2F;AAE3F,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AASjD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,UAAyB,EAAE;IACxE,IAAI,OAAO,CAAC,KAAK,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;QACnC,OAAO;QACP,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,UAAyB,EAAE;IAE3B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,kBAAkB,CAC1B,oFAAoF,CACrF,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;QACnC,OAAO;QACP,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,IAAI,CA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;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAAyB,EAAE;IAC/D,OAAO,OAAO,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,cAAsB,EACtB,cAAsB,EACtB,UAAyB,EAAE;IAE3B,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5B,OAAO,CAAC,GAAG,EAAE,CAAC;IAEd,OAAO,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codefresh-io/gitops-release",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI to automate GitOps runtime release lifecycle operations",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"gitops-release": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/codefresh-io/gitops-release.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/codefresh-io/gitops-release/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/codefresh-io/gitops-release#readme",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"dev": "tsc --watch",
|
|
27
|
+
"start": "node dist/index.js",
|
|
28
|
+
"lint": "eslint src",
|
|
29
|
+
"lint:fix": "eslint src --fix",
|
|
30
|
+
"format": "prettier --write src/**/*.ts",
|
|
31
|
+
"format:check": "prettier --check src/**/*.ts",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"test:coverage": "vitest run --coverage"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"cli",
|
|
39
|
+
"gitops",
|
|
40
|
+
"release",
|
|
41
|
+
"codefresh",
|
|
42
|
+
"helm"
|
|
43
|
+
],
|
|
44
|
+
"author": "Codefresh",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@eslint/js": "^9.39.2",
|
|
51
|
+
"@types/node": "^25.0.3",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
53
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
54
|
+
"eslint": "^9.39.2",
|
|
55
|
+
"prettier": "^3.7.4",
|
|
56
|
+
"typescript": "^5.9.3",
|
|
57
|
+
"vitest": "^4.0.16"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@anthropic-ai/sdk": "^0.71.2",
|
|
61
|
+
"@inquirer/prompts": "^8.1.0",
|
|
62
|
+
"chalk": "^5.6.2",
|
|
63
|
+
"cli-table3": "^0.6.5",
|
|
64
|
+
"commander": "^14.0.2",
|
|
65
|
+
"octokit": "^5.0.5",
|
|
66
|
+
"ora": "^9.0.0",
|
|
67
|
+
"yaml": "^2.8.2",
|
|
68
|
+
"zod": "^4.3.5"
|
|
69
|
+
}
|
|
70
|
+
}
|