@ycadence/cli 0.0.0-stage → 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/LICENSE +202 -0
- package/README.md +63 -2
- package/dist/bin.js +469 -0
- package/package.json +49 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Yarlis, Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ycadence/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Work with YCadence from the command line: list, create, show and close work items,
|
|
4
|
+
read states and cycles, and run imports from CSV, Jira, Linear or GitHub exports.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install -g @ycadence/cli
|
|
10
|
+
# or run it once, without installing
|
|
11
|
+
npx @ycadence/cli help
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### If npm is unavailable
|
|
15
|
+
|
|
16
|
+
Each release is mirrored to GitHub Packages when the npm publish fails, as
|
|
17
|
+
`@yarlisaisolutions/ycadence-cli`. It needs a GitHub token with `read:packages`:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
# ~/.npmrc
|
|
21
|
+
@yarlisaisolutions:registry=https://npm.pkg.github.com
|
|
22
|
+
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install -g @yarlisaisolutions/ycadence-cli
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The package installs two commands that behave the same: `ycadence`, and `devpulse`,
|
|
30
|
+
the name from before the rename.
|
|
31
|
+
|
|
32
|
+
## Configure
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
export YCADENCE_URL=https://ycadence.example.com
|
|
36
|
+
export YCADENCE_API_KEY=yc_live_p_... # a project, organization or personal key
|
|
37
|
+
export YCADENCE_IDENTITY_TOKEN=... # only behind Google IAP; lasts about an hour
|
|
38
|
+
ycadence doctor # checks configuration and connectivity
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
When a `YCADENCE_*` variable is unset, the CLI reads the older `DEVPULSE_*` name
|
|
42
|
+
instead, and `doctor` tells you which one it used.
|
|
43
|
+
|
|
44
|
+
## Commands
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
ycadence doctor
|
|
48
|
+
ycadence work-item list <projectId>
|
|
49
|
+
ycadence work-item create <projectId> --title "..." [--priority high]
|
|
50
|
+
ycadence work-item show <workItemId>
|
|
51
|
+
ycadence work-item close <workItemId>
|
|
52
|
+
ycadence states <projectId>
|
|
53
|
+
ycadence cycles <projectId>
|
|
54
|
+
ycadence import preview <projectId> --source csv --file issues.csv
|
|
55
|
+
ycadence import run <projectId> --source csv --file issues.csv [--map "Done=<stateId>"]
|
|
56
|
+
ycadence import status <runId>
|
|
57
|
+
ycadence import list <projectId>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires Node 18 or later. The package is self-contained and installs no other packages.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
Apache-2.0
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
// ../core/src/env.ts
|
|
7
|
+
var ENV_PREFIX = "YCADENCE_";
|
|
8
|
+
var LEGACY_ENV_PREFIX = "DEVPULSE_";
|
|
9
|
+
function processEnv() {
|
|
10
|
+
const candidate = globalThis.process;
|
|
11
|
+
return candidate?.env ?? {};
|
|
12
|
+
}
|
|
13
|
+
function readEnv(name, env = processEnv()) {
|
|
14
|
+
const current = env[`${ENV_PREFIX}${name}`];
|
|
15
|
+
if (current !== undefined && current !== "")
|
|
16
|
+
return current;
|
|
17
|
+
const legacy = env[`${LEGACY_ENV_PREFIX}${name}`];
|
|
18
|
+
if (legacy !== undefined && legacy !== "")
|
|
19
|
+
return legacy;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ../sdk/src/client.ts
|
|
24
|
+
class YCadenceError extends Error {
|
|
25
|
+
status;
|
|
26
|
+
code;
|
|
27
|
+
issues;
|
|
28
|
+
constructor(status, code, message, issues) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.issues = issues;
|
|
33
|
+
this.name = "YCadenceError";
|
|
34
|
+
}
|
|
35
|
+
get retryable() {
|
|
36
|
+
return this.status === 429 || this.status >= 500;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class YCadenceClient {
|
|
41
|
+
baseUrl;
|
|
42
|
+
apiKey;
|
|
43
|
+
identityToken;
|
|
44
|
+
timeoutMs;
|
|
45
|
+
doFetch;
|
|
46
|
+
constructor(options) {
|
|
47
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
48
|
+
this.apiKey = options.apiKey;
|
|
49
|
+
this.identityToken = options.identityToken;
|
|
50
|
+
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
51
|
+
this.doFetch = options.fetch ?? globalThis.fetch;
|
|
52
|
+
}
|
|
53
|
+
async health() {
|
|
54
|
+
return this.request("GET", "/api/health");
|
|
55
|
+
}
|
|
56
|
+
async listWorkItems(projectId, options = {}) {
|
|
57
|
+
const query = new URLSearchParams;
|
|
58
|
+
if (options.filter !== undefined)
|
|
59
|
+
query.set("filter", JSON.stringify(options.filter));
|
|
60
|
+
if (options.limit !== undefined)
|
|
61
|
+
query.set("limit", String(options.limit));
|
|
62
|
+
if (options.cursor !== undefined)
|
|
63
|
+
query.set("cursor", options.cursor);
|
|
64
|
+
return this.request("GET", `/api/v1/projects/${projectId}/work-items?${query}`);
|
|
65
|
+
}
|
|
66
|
+
async* iterateWorkItems(projectId, options = {}) {
|
|
67
|
+
let cursor;
|
|
68
|
+
do {
|
|
69
|
+
const page = await this.listWorkItems(projectId, {
|
|
70
|
+
filter: options.filter,
|
|
71
|
+
limit: options.pageSize ?? 100,
|
|
72
|
+
cursor
|
|
73
|
+
});
|
|
74
|
+
for (const item of page.items)
|
|
75
|
+
yield item;
|
|
76
|
+
cursor = page.nextCursor ?? undefined;
|
|
77
|
+
} while (cursor !== undefined);
|
|
78
|
+
}
|
|
79
|
+
async createWorkItem(projectId, body) {
|
|
80
|
+
return this.request("POST", `/api/v1/projects/${projectId}/work-items`, body);
|
|
81
|
+
}
|
|
82
|
+
async getWorkItem(workItemId) {
|
|
83
|
+
return this.request("GET", `/api/v1/work-items/${workItemId}`);
|
|
84
|
+
}
|
|
85
|
+
async updateWorkItem(workItemId, body) {
|
|
86
|
+
return this.request("PATCH", `/api/v1/work-items/${workItemId}`, body);
|
|
87
|
+
}
|
|
88
|
+
async deleteWorkItem(workItemId) {
|
|
89
|
+
await this.request("DELETE", `/api/v1/work-items/${workItemId}`);
|
|
90
|
+
}
|
|
91
|
+
async listStates(projectId) {
|
|
92
|
+
return this.request("GET", `/api/v1/projects/${projectId}/states`);
|
|
93
|
+
}
|
|
94
|
+
async listLabels(projectId) {
|
|
95
|
+
return this.request("GET", `/api/v1/projects/${projectId}/labels`);
|
|
96
|
+
}
|
|
97
|
+
async listCycles(projectId) {
|
|
98
|
+
return this.request("GET", `/api/v1/projects/${projectId}/cycles`);
|
|
99
|
+
}
|
|
100
|
+
async previewImport(projectId, body) {
|
|
101
|
+
return this.request("POST", `/api/v1/projects/${projectId}/imports/preview`, body);
|
|
102
|
+
}
|
|
103
|
+
async startImport(projectId, body) {
|
|
104
|
+
return this.request("POST", `/api/v1/projects/${projectId}/imports`, body);
|
|
105
|
+
}
|
|
106
|
+
async getImport(runId) {
|
|
107
|
+
return this.request("GET", `/api/v1/imports/${runId}`);
|
|
108
|
+
}
|
|
109
|
+
async listImports(projectId) {
|
|
110
|
+
return this.request("GET", `/api/v1/projects/${projectId}/imports`);
|
|
111
|
+
}
|
|
112
|
+
async listViews(projectId) {
|
|
113
|
+
return this.request("GET", `/api/v1/projects/${projectId}/views`);
|
|
114
|
+
}
|
|
115
|
+
async request(method, path, body) {
|
|
116
|
+
const controller = new AbortController;
|
|
117
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
118
|
+
let response;
|
|
119
|
+
try {
|
|
120
|
+
const identityToken = typeof this.identityToken === "function" ? await this.identityToken() : this.identityToken;
|
|
121
|
+
response = await this.doFetch(`${this.baseUrl}${path}`, {
|
|
122
|
+
method,
|
|
123
|
+
headers: {
|
|
124
|
+
"x-api-key": this.apiKey,
|
|
125
|
+
...identityToken === undefined || identityToken.length === 0 ? {} : { Authorization: `Bearer ${identityToken}` },
|
|
126
|
+
...body === undefined ? {} : { "Content-Type": "application/json" }
|
|
127
|
+
},
|
|
128
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
129
|
+
signal: controller.signal
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
133
|
+
throw new YCadenceError(408, "timeout", `${method} ${path} timed out after ${this.timeoutMs}ms.`);
|
|
134
|
+
}
|
|
135
|
+
throw new YCadenceError(0, "network_error", `Could not reach ${this.baseUrl}: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
136
|
+
} finally {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
}
|
|
139
|
+
if (response.status === 204)
|
|
140
|
+
return;
|
|
141
|
+
const text = await response.text();
|
|
142
|
+
const parsed = text.length === 0 ? undefined : safeJson(text);
|
|
143
|
+
if (!response.ok) {
|
|
144
|
+
const failure = parsed ?? {};
|
|
145
|
+
throw new YCadenceError(response.status, failure.code ?? "unknown", failure.error ?? `${method} ${path} failed with ${response.status}.`, failure.issues);
|
|
146
|
+
}
|
|
147
|
+
return parsed;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function safeJson(text) {
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(text);
|
|
153
|
+
} catch {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// src/commands.ts
|
|
158
|
+
var ok = (output) => ({ output, exitCode: 0 });
|
|
159
|
+
var fail = (output, exitCode = 1) => ({ output, exitCode });
|
|
160
|
+
var USAGE = `ycadence — project and work management from the command line
|
|
161
|
+
|
|
162
|
+
ycadence doctor check configuration and connectivity
|
|
163
|
+
ycadence work-item list <projectId> list work items
|
|
164
|
+
ycadence work-item create <projectId> --title "..." [--priority high]
|
|
165
|
+
ycadence work-item show <workItemId>
|
|
166
|
+
ycadence work-item close <workItemId>
|
|
167
|
+
ycadence states <projectId>
|
|
168
|
+
ycadence cycles <projectId>
|
|
169
|
+
ycadence import preview <projectId> --source csv --file issues.csv
|
|
170
|
+
ycadence import run <projectId> --source csv --file issues.csv [--map "Done=<stateId>"]
|
|
171
|
+
ycadence import status <runId>
|
|
172
|
+
ycadence import list <projectId>
|
|
173
|
+
|
|
174
|
+
Configuration:
|
|
175
|
+
YCADENCE_URL the instance, e.g. https://devpulse.yarlis.com
|
|
176
|
+
YCADENCE_API_KEY a project, organization or personal key
|
|
177
|
+
YCADENCE_IDENTITY_TOKEN
|
|
178
|
+
optional: a Google identity token, for an instance behind
|
|
179
|
+
IAP. Its audience must be the IAP OAuth client id, and it
|
|
180
|
+
lasts about an hour
|
|
181
|
+
|
|
182
|
+
The DEVPULSE_* names are still read when the YCADENCE_* one is unset.
|
|
183
|
+
\`devpulse\` is kept as an alias of this command.`;
|
|
184
|
+
async function run(argv, context) {
|
|
185
|
+
const [command, ...rest] = argv;
|
|
186
|
+
try {
|
|
187
|
+
switch (command) {
|
|
188
|
+
case undefined:
|
|
189
|
+
case "help":
|
|
190
|
+
case "--help":
|
|
191
|
+
case "-h":
|
|
192
|
+
return ok(USAGE);
|
|
193
|
+
case "doctor":
|
|
194
|
+
return await doctor(context);
|
|
195
|
+
case "states": {
|
|
196
|
+
const projectId = rest[0];
|
|
197
|
+
if (projectId === undefined)
|
|
198
|
+
return fail("Usage: ycadence states <projectId>");
|
|
199
|
+
const { states } = await context.client.listStates(projectId);
|
|
200
|
+
return ok(states.map((state) => `${state.id} ${state.name} (${state.group})`).join(`
|
|
201
|
+
`));
|
|
202
|
+
}
|
|
203
|
+
case "cycles": {
|
|
204
|
+
const projectId = rest[0];
|
|
205
|
+
if (projectId === undefined)
|
|
206
|
+
return fail("Usage: ycadence cycles <projectId>");
|
|
207
|
+
const { cycles } = await context.client.listCycles(projectId);
|
|
208
|
+
return ok(cycles.length === 0 ? "No cycles." : cycles.map((cycle) => `${cycle.id} ${cycle.name} [${cycle.status}]`).join(`
|
|
209
|
+
`));
|
|
210
|
+
}
|
|
211
|
+
case "import":
|
|
212
|
+
return await importCommand(rest, context);
|
|
213
|
+
case "work-item":
|
|
214
|
+
return await workItem(rest, context);
|
|
215
|
+
default:
|
|
216
|
+
return fail(`Unknown command: ${command}
|
|
217
|
+
|
|
218
|
+
${USAGE}`);
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (error instanceof YCadenceError) {
|
|
222
|
+
const detail = error.issues === undefined ? error.message : `${error.message}
|
|
223
|
+
${error.issues.map((issue) => ` ${issue.path}: ${issue.message}`).join(`
|
|
224
|
+
`)}`;
|
|
225
|
+
return fail(detail, error.retryable ? 75 : 1);
|
|
226
|
+
}
|
|
227
|
+
return fail(error instanceof Error ? error.message : "Unknown error.");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async function workItem(argv, context) {
|
|
231
|
+
const [action, ...rest] = argv;
|
|
232
|
+
switch (action) {
|
|
233
|
+
case "list": {
|
|
234
|
+
const projectId = rest[0];
|
|
235
|
+
if (projectId === undefined)
|
|
236
|
+
return fail("Usage: ycadence work-item list <projectId>");
|
|
237
|
+
const page = await context.client.listWorkItems(projectId, { limit: 50 });
|
|
238
|
+
if (page.items.length === 0)
|
|
239
|
+
return ok("No work items.");
|
|
240
|
+
const lines = page.items.map((item) => `${item.key.padEnd(10)} ${item.priority.padEnd(7)} ${item.name}`);
|
|
241
|
+
if (page.nextCursor !== null)
|
|
242
|
+
lines.push(`… more (use --cursor ${page.nextCursor})`);
|
|
243
|
+
return ok(lines.join(`
|
|
244
|
+
`));
|
|
245
|
+
}
|
|
246
|
+
case "create": {
|
|
247
|
+
const projectId = rest[0];
|
|
248
|
+
const flags = parseFlags(rest.slice(1));
|
|
249
|
+
const title = flags.title;
|
|
250
|
+
if (projectId === undefined || title === undefined) {
|
|
251
|
+
return fail('Usage: ycadence work-item create <projectId> --title "..."');
|
|
252
|
+
}
|
|
253
|
+
const created = await context.client.createWorkItem(projectId, {
|
|
254
|
+
name: title,
|
|
255
|
+
priority: flags.priority,
|
|
256
|
+
description: flags.description
|
|
257
|
+
});
|
|
258
|
+
return ok(`${created.key} ${created.name}`);
|
|
259
|
+
}
|
|
260
|
+
case "show": {
|
|
261
|
+
const workItemId = rest[0];
|
|
262
|
+
if (workItemId === undefined)
|
|
263
|
+
return fail("Usage: ycadence work-item show <workItemId>");
|
|
264
|
+
const item = await context.client.getWorkItem(workItemId);
|
|
265
|
+
return ok([
|
|
266
|
+
`${item.key} ${item.name}`,
|
|
267
|
+
`priority ${item.priority}`,
|
|
268
|
+
`state ${item.stateId ?? "—"}`,
|
|
269
|
+
"",
|
|
270
|
+
item.description ?? "(no description)"
|
|
271
|
+
].join(`
|
|
272
|
+
`));
|
|
273
|
+
}
|
|
274
|
+
case "close": {
|
|
275
|
+
const workItemId = rest[0];
|
|
276
|
+
if (workItemId === undefined)
|
|
277
|
+
return fail("Usage: ycadence work-item close <workItemId>");
|
|
278
|
+
const item = await context.client.getWorkItem(workItemId);
|
|
279
|
+
const { states } = await context.client.listStates(item.projectId ?? "");
|
|
280
|
+
const done = states.find((state) => state.group === "completed");
|
|
281
|
+
if (done === undefined) {
|
|
282
|
+
return fail("This project has no completed state, so nothing can be closed.");
|
|
283
|
+
}
|
|
284
|
+
await context.client.updateWorkItem(workItemId, { stateId: done.id });
|
|
285
|
+
return ok(`Closed ${item.key}.`);
|
|
286
|
+
}
|
|
287
|
+
default:
|
|
288
|
+
return fail(`Unknown work-item action: ${action ?? "(none)"}
|
|
289
|
+
|
|
290
|
+
${USAGE}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function legacyNote(name, env) {
|
|
294
|
+
const current = env[`YCADENCE_${name}`];
|
|
295
|
+
if (current !== undefined && current !== "")
|
|
296
|
+
return "";
|
|
297
|
+
return ` (read from ${LEGACY_ENV_PREFIX}${name}; rename it to YCADENCE_${name})`;
|
|
298
|
+
}
|
|
299
|
+
async function doctor(context) {
|
|
300
|
+
const lines = [];
|
|
301
|
+
let healthy = true;
|
|
302
|
+
const url = readEnv("URL", context.env);
|
|
303
|
+
const key = readEnv("API_KEY", context.env);
|
|
304
|
+
lines.push(url === undefined ? "✗ YCADENCE_URL is not set" : `✓ YCADENCE_URL ${url}${legacyNote("URL", context.env)}`);
|
|
305
|
+
lines.push(key === undefined ? "✗ YCADENCE_API_KEY is not set" : `✓ YCADENCE_API_KEY ${key.slice(0, 12)}… (${key.length} chars)${legacyNote("API_KEY", context.env)}`);
|
|
306
|
+
if (url === undefined || key === undefined)
|
|
307
|
+
healthy = false;
|
|
308
|
+
const identityToken = readEnv("IDENTITY_TOKEN", context.env);
|
|
309
|
+
lines.push(identityToken === undefined || identityToken.length === 0 ? "· YCADENCE_IDENTITY_TOKEN not set (only needed behind IAP)" : `✓ YCADENCE_IDENTITY_TOKEN set (${identityToken.length} chars)${legacyNote("IDENTITY_TOKEN", context.env)}`);
|
|
310
|
+
if (healthy) {
|
|
311
|
+
try {
|
|
312
|
+
const health = await context.client.health();
|
|
313
|
+
lines.push(`✓ reachable — status ${health.status}`);
|
|
314
|
+
for (const [name, state] of Object.entries(health.checks)) {
|
|
315
|
+
lines.push(` ${state === "ok" ? "✓" : "✗"} ${name}: ${state}`);
|
|
316
|
+
if (state !== "ok")
|
|
317
|
+
healthy = false;
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
healthy = false;
|
|
321
|
+
lines.push(`✗ unreachable — ${error instanceof Error ? error.message : "unknown error"}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return healthy ? ok(lines.join(`
|
|
325
|
+
`)) : fail(lines.join(`
|
|
326
|
+
`));
|
|
327
|
+
}
|
|
328
|
+
function parseFlags(argv) {
|
|
329
|
+
const flags = {};
|
|
330
|
+
for (let index = 0;index < argv.length; index += 1) {
|
|
331
|
+
const token = argv[index];
|
|
332
|
+
if (!token.startsWith("--"))
|
|
333
|
+
continue;
|
|
334
|
+
const equals = token.indexOf("=");
|
|
335
|
+
if (equals > -1) {
|
|
336
|
+
flags[token.slice(2, equals)] = token.slice(equals + 1);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const next = argv[index + 1];
|
|
340
|
+
if (next === undefined || next.startsWith("--")) {
|
|
341
|
+
flags[token.slice(2)] = "";
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
flags[token.slice(2)] = next;
|
|
345
|
+
index += 1;
|
|
346
|
+
}
|
|
347
|
+
return flags;
|
|
348
|
+
}
|
|
349
|
+
var IMPORT_SOURCES = ["csv", "github", "jira", "linear"];
|
|
350
|
+
async function importCommand(argv, context) {
|
|
351
|
+
const [action, target] = argv;
|
|
352
|
+
const flags = parseFlags(argv.slice(2));
|
|
353
|
+
if (action === "status") {
|
|
354
|
+
if (target === undefined)
|
|
355
|
+
return fail("Usage: ycadence import status <runId>");
|
|
356
|
+
const run2 = await context.client.getImport(target);
|
|
357
|
+
return ok(formatRun(run2));
|
|
358
|
+
}
|
|
359
|
+
if (action === "list") {
|
|
360
|
+
if (target === undefined)
|
|
361
|
+
return fail("Usage: ycadence import list <projectId>");
|
|
362
|
+
const { runs } = await context.client.listImports(target);
|
|
363
|
+
return ok(runs.length === 0 ? "No imports." : runs.map((run2) => formatRun(run2)).join(`
|
|
364
|
+
|
|
365
|
+
`));
|
|
366
|
+
}
|
|
367
|
+
if (action !== "preview" && action !== "run") {
|
|
368
|
+
return fail(`Usage: ycadence import preview|run|status|list …`);
|
|
369
|
+
}
|
|
370
|
+
if (target === undefined)
|
|
371
|
+
return fail(`Usage: ycadence import ${action} <projectId> --file …`);
|
|
372
|
+
const source = flags.source ?? "csv";
|
|
373
|
+
if (!IMPORT_SOURCES.includes(source)) {
|
|
374
|
+
return fail(`Unknown source "${source}". One of: ${IMPORT_SOURCES.join(", ")}.`);
|
|
375
|
+
}
|
|
376
|
+
if (flags.file === undefined)
|
|
377
|
+
return fail("Pass --file with the export to import.");
|
|
378
|
+
const text = await context.readFile(flags.file);
|
|
379
|
+
const data = source === "csv" ? text : JSON.parse(text);
|
|
380
|
+
const body = { source, data };
|
|
381
|
+
if (flags.repository !== undefined)
|
|
382
|
+
body.repository = flags.repository;
|
|
383
|
+
if (flags["base-url"] !== undefined)
|
|
384
|
+
body.baseUrl = flags["base-url"];
|
|
385
|
+
if (action === "preview") {
|
|
386
|
+
const preview = await context.client.previewImport(target, body);
|
|
387
|
+
const lines = [
|
|
388
|
+
`${preview.total} items from ${preview.source}.`,
|
|
389
|
+
preview.idempotent ? "" : "This source has no stable ids, so re-importing an edited row creates a second item.",
|
|
390
|
+
"",
|
|
391
|
+
"States:",
|
|
392
|
+
...preview.states.map((state) => ` ${state.name} → ${state.suggestedStateId ?? "no match; will use the default state"}`),
|
|
393
|
+
"",
|
|
394
|
+
"Labels:",
|
|
395
|
+
...preview.labels.map((label) => ` ${label.name}${label.exists ? "" : " (will create)"}`),
|
|
396
|
+
"",
|
|
397
|
+
"Assignees:",
|
|
398
|
+
...preview.assignees.map((assignee) => ` ${assignee.value}${assignee.matched ? "" : " (no matching member)"}`)
|
|
399
|
+
];
|
|
400
|
+
if (preview.unmappedPriorities.length > 0) {
|
|
401
|
+
lines.push("", `Unrecognised priorities: ${preview.unmappedPriorities.join(", ")}`);
|
|
402
|
+
}
|
|
403
|
+
if (preview.skipped.length > 0) {
|
|
404
|
+
lines.push("", "Skipped:");
|
|
405
|
+
for (const skip of preview.skipped)
|
|
406
|
+
lines.push(` row ${skip.row}: ${skip.reason}`);
|
|
407
|
+
}
|
|
408
|
+
return ok(lines.filter((line, index) => line !== "" || index > 0).join(`
|
|
409
|
+
`));
|
|
410
|
+
}
|
|
411
|
+
const stateMap = {};
|
|
412
|
+
for (const pair of toList(flags.map)) {
|
|
413
|
+
const at = pair.indexOf("=");
|
|
414
|
+
if (at < 0)
|
|
415
|
+
return fail(`--map takes "SourceState=<stateId>", got "${pair}".`);
|
|
416
|
+
stateMap[pair.slice(0, at)] = pair.slice(at + 1);
|
|
417
|
+
}
|
|
418
|
+
if (Object.keys(stateMap).length > 0)
|
|
419
|
+
body.stateMap = stateMap;
|
|
420
|
+
const { runId } = await context.client.startImport(target, body);
|
|
421
|
+
return ok(`Queued as ${runId}. Follow it with: ycadence import status ${runId}`);
|
|
422
|
+
}
|
|
423
|
+
function formatRun(run2) {
|
|
424
|
+
const lines = [
|
|
425
|
+
`${run2.id} [${run2.status}] ${run2.source}`,
|
|
426
|
+
` ${run2.cursor}/${run2.totalItems} committed — ${run2.createdCount} created, ${run2.updatedCount} updated`
|
|
427
|
+
];
|
|
428
|
+
if (run2.error !== null)
|
|
429
|
+
lines.push(` error: ${run2.error}`);
|
|
430
|
+
for (const miss of run2.unmatched.slice(0, 20)) {
|
|
431
|
+
lines.push(` unmatched ${miss.kind} "${miss.value}" on ${miss.item}`);
|
|
432
|
+
}
|
|
433
|
+
if (run2.unmatched.length > 20) {
|
|
434
|
+
lines.push(` …and ${run2.unmatched.length - 20} more`);
|
|
435
|
+
}
|
|
436
|
+
return lines.join(`
|
|
437
|
+
`);
|
|
438
|
+
}
|
|
439
|
+
function toList(value) {
|
|
440
|
+
if (value === undefined)
|
|
441
|
+
return [];
|
|
442
|
+
return value.split(",").map((part) => part.trim()).filter((part) => part !== "");
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/bin.ts
|
|
446
|
+
var url = readEnv("URL");
|
|
447
|
+
var key = readEnv("API_KEY");
|
|
448
|
+
var argv = process.argv.slice(2);
|
|
449
|
+
var needsConfig = argv[0] !== undefined && argv[0] !== "help" && argv[0] !== "doctor";
|
|
450
|
+
if (needsConfig && (url === undefined || key === undefined)) {
|
|
451
|
+
process.stderr.write(`Set YCADENCE_URL and YCADENCE_API_KEY first.
|
|
452
|
+
|
|
453
|
+
${USAGE}
|
|
454
|
+
`);
|
|
455
|
+
process.exit(1);
|
|
456
|
+
}
|
|
457
|
+
var result = await run(argv, {
|
|
458
|
+
client: new YCadenceClient({
|
|
459
|
+
baseUrl: url ?? "http://localhost:3000",
|
|
460
|
+
apiKey: key ?? "",
|
|
461
|
+
identityToken: readEnv("IDENTITY_TOKEN")
|
|
462
|
+
}),
|
|
463
|
+
env: process.env,
|
|
464
|
+
readFile: (path) => readFile(path, "utf8")
|
|
465
|
+
});
|
|
466
|
+
var stream = result.exitCode === 0 ? process.stdout : process.stderr;
|
|
467
|
+
stream.write(`${result.output}
|
|
468
|
+
`);
|
|
469
|
+
process.exit(result.exitCode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycadence/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "YCadence from the command line: work items, states, cycles and imports.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ycadence",
|
|
7
|
+
"cli",
|
|
8
|
+
"project-management",
|
|
9
|
+
"issue-tracker"
|
|
10
|
+
],
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/YarlisAISolutions/dev-pulse.git",
|
|
15
|
+
"directory": "packages/cli"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/YarlisAISolutions/dev-pulse/tree/main/packages/cli#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/YarlisAISolutions/dev-pulse/issues"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"bin": {
|
|
23
|
+
"ycadence": "dist/bin.js",
|
|
24
|
+
"devpulse": "dist/bin.js"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": false
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "rm -rf dist && bun build src/bin.ts --outdir dist --target node --format esm --conditions ycadence-source",
|
|
43
|
+
"prepack": "cp ../../LICENSE LICENSE && bun run build",
|
|
44
|
+
"type-check": "tsc --noEmit",
|
|
45
|
+
"test": "vitest run"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@devpulse/core": "workspace:*",
|
|
49
|
+
"@ycadence/sdk": "workspace:*"
|
|
50
|
+
}
|
|
51
|
+
}
|