@cmflow/cli 3.3.0 → 3.4.0-alpha.1
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/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.18.0.cjs +1000 -0
- package/.yarnrc.yml +8 -1
- package/bin/cm-checkfeatures.ts +10 -0
- package/bin/cm-clean.ts +10 -0
- package/bin/cm-config.ts +10 -0
- package/bin/cm-deploy.ts +10 -0
- package/bin/{cm-expedit.js → cm-expedit.ts} +4 -4
- package/bin/cm-fetch.ts +10 -0
- package/bin/cm-finish.ts +10 -0
- package/bin/cm-jira-releases.ts +10 -0
- package/bin/cm-merge.ts +10 -0
- package/bin/cm-publish.ts +10 -0
- package/bin/cm-pull.ts +8 -0
- package/bin/cm-push.ts +10 -0
- package/bin/cm-rebase.ts +10 -0
- package/bin/{cmrelease.js → cm-release.ts} +0 -0
- package/bin/cm-republish.ts +10 -0
- package/bin/cm-start.ts +10 -0
- package/bin/cm.ts +40 -0
- package/dist/bin/cm.mjs +74985 -0
- package/dist/bin/cmrelease.mjs +72397 -0
- package/dist/cli-truncate-BmHD4ngn.mjs +152 -0
- package/dist/cli-truncate-CXNquMRK.mjs +152 -0
- package/dist/cli-truncate-DbOyuy2e.mjs +2 -0
- package/dist/cli-truncate-DbOyuy2e.mjs.map +1 -0
- package/dist/common-CwPbT3So.mjs +66 -0
- package/dist/common-CwPbT3So.mjs.map +1 -0
- package/dist/docker-clean-tags-Cd-E8IqJ.mjs +2 -0
- package/dist/docker-clean-tags-Cd-E8IqJ.mjs.map +1 -0
- package/dist/docker-publish-B0E0qYYB.mjs +2 -0
- package/dist/docker-publish-B0E0qYYB.mjs.map +1 -0
- package/dist/get-config-DoOyLztI.mjs +41 -0
- package/dist/get-config-DoOyLztI.mjs.map +1 -0
- package/dist/get-east-asian-width-Tfn8qoqd.mjs +2 -0
- package/dist/get-east-asian-width-Tfn8qoqd.mjs.map +1 -0
- package/dist/get-east-asian-width-eFfEkHwo.mjs +682 -0
- package/dist/log-update-B2GqeeDd.mjs +497 -0
- package/dist/log-update-BldA9lkm.mjs +497 -0
- package/dist/log-update-By8Z-mak.mjs +6 -0
- package/dist/log-update-By8Z-mak.mjs.map +1 -0
- package/dist/rolldown-runtime-B4iAMlE-.mjs +35 -0
- package/dist/semver-D8gwMSFO.mjs +2 -0
- package/dist/semver-D8gwMSFO.mjs.map +1 -0
- package/dist/src/index.mjs +18 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/semantic/core/analyze-commits.mjs +2 -0
- package/dist/src/semantic/core/analyze-commits.mjs.map +1 -0
- package/dist/src/semantic/core/conditional.mjs +2 -0
- package/dist/src/semantic/core/conditional.mjs.map +1 -0
- package/dist/src/semantic/core/exit.mjs +2 -0
- package/dist/src/semantic/core/exit.mjs.map +1 -0
- package/dist/src/semantic/core/prepare/bump-version.mjs +48 -0
- package/dist/src/semantic/core/prepare/bump-version.mjs.map +1 -0
- package/dist/src/semantic/core/prepare/commit.mjs +2 -0
- package/dist/src/semantic/core/prepare/commit.mjs.map +1 -0
- package/dist/src/semantic/core/prepare/release-info.mjs +2 -0
- package/dist/src/semantic/core/prepare/release-info.mjs.map +1 -0
- package/dist/src/semantic/core/run.mjs +2 -0
- package/dist/src/semantic/core/run.mjs.map +1 -0
- package/dist/src/semantic/core/sync-repository.mjs +2 -0
- package/dist/src/semantic/core/sync-repository.mjs.map +1 -0
- package/dist/src/semantic/core/verify-conditions.mjs +2 -0
- package/dist/src/semantic/core/verify-conditions.mjs.map +1 -0
- package/dist/src/semantic/core/verify-release.mjs +2 -0
- package/dist/src/semantic/core/verify-release.mjs.map +1 -0
- package/dist/src/semantic/docker/publish.mjs +2 -0
- package/dist/src/semantic/docker/publish.mjs.map +1 -0
- package/dist/src/semantic/docker/success.mjs +2 -0
- package/dist/src/semantic/docker/success.mjs.map +1 -0
- package/dist/strip-ansi-Aeu5cmZe.mjs +174 -0
- package/dist/strip-ansi-Cl0pRo-s.mjs +2 -0
- package/dist/strip-ansi-Cl0pRo-s.mjs.map +1 -0
- package/dist/wrap-ansi-BeIjar2W.mjs +2 -0
- package/dist/wrap-ansi-CWIezXNl.mjs +330 -0
- package/dist/wrap-ansi-DsMb4WnZ.mjs +9 -0
- package/dist/wrap-ansi-DsMb4WnZ.mjs.map +1 -0
- package/dist/wrap-ansi-T0rz0Urp.mjs +330 -0
- package/package.json +47 -38
- package/release.config.mjs +6 -6
- package/src/commands/checkfeatures.ts +39 -0
- package/src/commands/clean.ts +36 -0
- package/src/commands/config.ts +31 -0
- package/src/commands/deploy.ts +39 -0
- package/src/commands/fetch.ts +30 -0
- package/src/commands/finish.ts +50 -0
- package/src/commands/{index.js → index.ts} +1 -0
- package/src/commands/jira-releases.ts +97 -0
- package/src/commands/merge.ts +58 -0
- package/src/commands/prompts/{branches.js → branches.ts} +13 -5
- package/src/commands/pull.ts +44 -0
- package/src/commands/push.ts +48 -0
- package/src/commands/rebase.ts +56 -0
- package/src/commands/republish.ts +34 -0
- package/src/commands/start.ts +123 -0
- package/src/commands/tasks/{merge-branch.js → merge-branch.ts} +18 -3
- package/src/commands/tasks/push-branch.ts +19 -0
- package/src/commands/tasks/{rebase-all-branches.js → rebase-all-branches.ts} +10 -2
- package/src/commands/tasks/{refresh-repository.js → refresh-repository.ts} +8 -4
- package/src/commands/tasks/run-test.ts +28 -0
- package/src/commands/tasks/{update-branch.js → update-branch.ts} +15 -9
- package/src/commands/tasks/{update-dependencies.js → update-dependencies.ts} +4 -3
- package/src/common/back/directus/{directus-flow.test.js → directus-flow.test.ts} +1 -0
- package/src/common/back/directus/{directus-flow.js → directus-flow.ts} +10 -2
- package/src/common/back/http/{http-proxy.js → http-proxy.ts} +7 -1
- package/src/common/back/http/{http-request.spec.js → http-request.spec.ts} +8 -7
- package/src/common/back/http/{http-request.js → http-request.ts} +16 -19
- package/src/common/back/jira/{get-sorted-releases.js → get-sorted-releases.ts} +2 -2
- package/src/common/back/jira/{jira-releases.js → jira-releases.ts} +14 -3
- package/src/common/back/jira/{jira-request.js → jira-request.ts} +9 -1
- package/src/common/back/jira/{jira-search.js → jira-search.ts} +2 -2
- package/src/common/cli/{bun.test.js → bun.test.ts} +17 -10
- package/src/common/cli/{bun.js → bun.ts} +4 -4
- package/src/common/cli/cli.ts +127 -0
- package/src/common/cli/{docker.test.js → docker.test.ts} +22 -14
- package/src/common/cli/{docker.js → docker.ts} +6 -6
- package/src/common/cli/{git.test.js → git.test.ts} +19 -11
- package/src/common/cli/{git.js → git.ts} +24 -24
- package/src/common/cli/{lerna.test.js → lerna.test.ts} +18 -11
- package/src/common/cli/{lerna.js → lerna.ts} +4 -4
- package/src/common/cli/{npm.test.js → npm.test.ts} +17 -10
- package/src/common/cli/{npm.js → npm.ts} +4 -4
- package/src/common/cli/{pnpm.test.js → pnpm.test.ts} +17 -10
- package/src/common/cli/{pnpm.js → pnpm.ts} +4 -4
- package/src/common/cli/{yarn.test.js → yarn.test.ts} +17 -12
- package/src/common/cli/{yarn.js → yarn.ts} +4 -4
- package/src/common/configure-git-workspace.ts +39 -0
- package/src/common/{get-config.js → get-config.ts} +3 -1
- package/src/common/{get-package-json.js → get-package-json.ts} +1 -0
- package/src/common/{get-package-manager.js → get-package-manager.ts} +1 -0
- package/src/common/{get-release-config.js → get-release-config.ts} +1 -0
- package/src/common/{index.js → index.ts} +1 -0
- package/src/common/{run-command.test.js → run-command.test.ts} +1 -0
- package/src/common/run-command.ts +67 -0
- package/src/common/types.ts +26 -0
- package/src/common/vendor.d.ts +4 -0
- package/src/{index.js → index.ts} +5 -1
- package/src/semantic/core/{analyze-commits.js → analyze-commits.ts} +7 -3
- package/src/semantic/core/{conditional.js → conditional.ts} +16 -9
- package/src/semantic/core/{exit.js → exit.ts} +3 -2
- package/src/semantic/core/prepare/{bump-version.js → bump-version.ts} +11 -8
- package/src/semantic/core/prepare/{commit.js → commit.ts} +3 -2
- package/src/semantic/core/prepare/release-info.ts +6 -0
- package/src/semantic/core/{run.js → run.ts} +3 -2
- package/src/semantic/core/sync-repository.ts +55 -0
- package/src/semantic/core/{verify-conditions.js → verify-conditions.ts} +4 -3
- package/src/semantic/core/{verify-release.js → verify-release.ts} +2 -1
- package/src/semantic/docker/publish.ts +6 -0
- package/src/semantic/docker/{success.js → success.ts} +2 -1
- package/src/semantic/utils/{bump-packages-version.test.js → bump-packages-version.test.ts} +1 -0
- package/src/semantic/utils/{bump-packages-version.js → bump-packages-version.ts} +12 -11
- package/src/semantic/utils/{calculate-snapshot-version.test.js → calculate-snapshot-version.test.ts} +10 -8
- package/src/semantic/utils/calculate-snapshot-version.ts +17 -0
- package/src/semantic/utils/display-package-info.ts +12 -0
- package/src/semantic/utils/display-release-info.ts +13 -0
- package/src/semantic/utils/{docker-clean-tags.test.js → docker-clean-tags.test.ts} +1 -0
- package/src/semantic/utils/{docker-clean-tags.js → docker-clean-tags.ts} +11 -4
- package/src/semantic/utils/{docker-publish.test.js → docker-publish.test.ts} +1 -0
- package/src/semantic/utils/{docker-publish.js → docker-publish.ts} +4 -3
- package/src/semantic/utils/{log-section.js → log-section.ts} +5 -1
- package/src/semantic/utils/{transform-writer.js → transform-writer.ts} +37 -13
- package/tsconfig.build.json +29 -0
- package/tsconfig.json +8 -15
- package/tsdown.config.ts +63 -0
- package/vitest.config.mts +2 -3
- package/.yarn/releases/yarn-4.7.0.cjs +0 -935
- package/bin/checkfeatures.js +0 -13
- package/bin/cm-clean.js +0 -8
- package/bin/cm-config.js +0 -15
- package/bin/cm-deploy.js +0 -8
- package/bin/cm-fetch.js +0 -12
- package/bin/cm-finish.js +0 -14
- package/bin/cm-jira-releases.js +0 -16
- package/bin/cm-merge.js +0 -12
- package/bin/cm-publish.js +0 -15
- package/bin/cm-push.js +0 -15
- package/bin/cm-rebase.js +0 -15
- package/bin/cm-republish.js +0 -12
- package/bin/cm-start.js +0 -21
- package/bin/cm.js +0 -27
- package/bin/cmpull.js +0 -22
- package/src/commands/checkfeatures.js +0 -20
- package/src/commands/clean.js +0 -29
- package/src/commands/config.js +0 -23
- package/src/commands/deploy.js +0 -34
- package/src/commands/fetch.js +0 -18
- package/src/commands/finish.js +0 -43
- package/src/commands/jira-releases.js +0 -62
- package/src/commands/merge.js +0 -41
- package/src/commands/pull.js +0 -30
- package/src/commands/push.js +0 -23
- package/src/commands/rebase.js +0 -35
- package/src/commands/republish.js +0 -21
- package/src/commands/start.js +0 -109
- package/src/commands/tasks/push-branch.js +0 -10
- package/src/commands/tasks/run-test.js +0 -21
- package/src/common/cli/cli.js +0 -110
- package/src/common/configure-git-workspace.js +0 -26
- package/src/common/run-command.js +0 -64
- package/src/semantic/core/prepare/release-info.js +0 -5
- package/src/semantic/core/sync-repository.js +0 -52
- package/src/semantic/docker/publish.js +0 -5
- package/src/semantic/utils/calculate-snapshot-version.js +0 -15
- package/src/semantic/utils/display-package-info.js +0 -11
- package/src/semantic/utils/display-release-info.js +0 -12
- /package/src/commands/{release.js → release.ts} +0 -0
- /package/src/commands/utils/{check-install.js → check-install.ts} +0 -0
- /package/src/common/back/jira/{jira-request.spec.js → jira-request.spec.ts} +0 -0
- /package/src/common/back/jira/{jira-search.spec.js → jira-search.spec.ts} +0 -0
- /package/src/semantic/{define-config.js → define-config.ts} +0 -0
- /package/src/semantic/utils/{release-rules.js → release-rules.ts} +0 -0
- /package/src/workflow/{index.js → index.ts} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Listr from "
|
|
2
|
-
import { catchError, EMPTY } from "rxjs";
|
|
1
|
+
import { Listr } from "listr2";
|
|
2
|
+
import { catchError, EMPTY, type Observable } from "rxjs";
|
|
3
3
|
|
|
4
4
|
import { git } from "../../common/index.js";
|
|
5
5
|
|
|
6
|
-
function pipe(observable
|
|
6
|
+
function pipe(observable: Observable<string>, output: unknown[]) {
|
|
7
7
|
observable.pipe(
|
|
8
8
|
catchError((err) => {
|
|
9
9
|
output.push(err);
|
|
@@ -18,7 +18,11 @@ function pipe(observable, output) {
|
|
|
18
18
|
return observable;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
interface RefreshRepositoryContext {
|
|
22
|
+
output?: unknown[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function refreshRepository(context: RefreshRepositoryContext) {
|
|
22
26
|
const { output = [] } = context;
|
|
23
27
|
|
|
24
28
|
return {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getPackageManager, git } from "../../common/index.js";
|
|
2
|
+
import type { CmContext, ListrTask } from "../../common/types";
|
|
3
|
+
|
|
4
|
+
type RunTestContext = CmContext<{
|
|
5
|
+
skipTest?: boolean;
|
|
6
|
+
skipUnit?: boolean;
|
|
7
|
+
skipE2E?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export const runTest = ({ config: { E2E_CMD, PACKAGE_MANAGER }, skipTest, skipUnit, skipE2E }: RunTestContext): ListrTask[] => {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
title: "Unit test",
|
|
14
|
+
skip: () => Boolean(skipTest || skipUnit),
|
|
15
|
+
task: () => getPackageManager(PACKAGE_MANAGER).run("test")
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: "E2E test",
|
|
19
|
+
skip: () => Boolean(skipTest || skipE2E),
|
|
20
|
+
task: () => getPackageManager(PACKAGE_MANAGER).run(E2E_CMD || "test_e2e")
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: "Reset changes",
|
|
24
|
+
skip: () => !!skipTest,
|
|
25
|
+
task: () => git.reset("--hard") as unknown as void // reset files updated unit test
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
};
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import Listr from "
|
|
2
|
+
import { Listr } from "listr2";
|
|
3
3
|
|
|
4
4
|
import { git } from "../../common/cli/git.js";
|
|
5
|
+
import type { CmContext, ListrTask } from "../../common/types";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
type UpdateBranchContext = CmContext<{
|
|
8
|
+
origin: string;
|
|
9
|
+
featureBranch: string;
|
|
10
|
+
fromBranch: string;
|
|
11
|
+
force: boolean;
|
|
12
|
+
checkStatus?: boolean;
|
|
13
|
+
rebase?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
async function checkBranchRemoteStatus({ featureBranch, origin, force }: UpdateBranchContext) {
|
|
7
17
|
const isBranchExists = git.branchExists(featureBranch, origin);
|
|
8
18
|
|
|
9
19
|
if (isBranchExists && !force) {
|
|
@@ -15,7 +25,8 @@ async function checkBranchRemoteStatus({ featureBranch, origin, force }) {
|
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
27
|
|
|
18
|
-
export const updateBranch = (
|
|
28
|
+
export const updateBranch = (context: UpdateBranchContext): ListrTask => {
|
|
29
|
+
const { origin, fromBranch, checkStatus = true, rebase = true } = context;
|
|
19
30
|
return {
|
|
20
31
|
title: "Rebase branch",
|
|
21
32
|
task: () =>
|
|
@@ -24,12 +35,7 @@ export const updateBranch = ({ origin, featureBranch, fromBranch, force, checkSt
|
|
|
24
35
|
{
|
|
25
36
|
title: "Check status",
|
|
26
37
|
enabled: () => checkStatus,
|
|
27
|
-
task: () =>
|
|
28
|
-
checkBranchRemoteStatus({
|
|
29
|
-
force,
|
|
30
|
-
featureBranch,
|
|
31
|
-
origin
|
|
32
|
-
})
|
|
38
|
+
task: () => checkBranchRemoteStatus(context)
|
|
33
39
|
},
|
|
34
40
|
{
|
|
35
41
|
title: `Rebase from ${origin}/${chalk.green(fromBranch)}`,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import Listr from "
|
|
1
|
+
import { Listr } from "listr2";
|
|
2
2
|
import { catchError } from "rxjs";
|
|
3
3
|
|
|
4
4
|
import { getPackageManager } from "../../common/index.js";
|
|
5
|
+
import type { CmContext, ListrTask } from "../../common/types";
|
|
5
6
|
import { refreshMetadata, shouldReinstall } from "../utils/check-install.js";
|
|
6
7
|
|
|
7
|
-
export const updateDependencies = ({ PACKAGE_MANAGER }) => {
|
|
8
|
+
export const updateDependencies = ({ config: { PACKAGE_MANAGER } }: CmContext): ListrTask => {
|
|
8
9
|
const reinstall = shouldReinstall();
|
|
9
10
|
|
|
10
11
|
return {
|
|
@@ -36,7 +37,7 @@ export const updateDependencies = ({ PACKAGE_MANAGER }) => {
|
|
|
36
37
|
task: () => refreshMetadata()
|
|
37
38
|
}
|
|
38
39
|
],
|
|
39
|
-
{
|
|
40
|
+
{ concurrent: false }
|
|
40
41
|
)
|
|
41
42
|
};
|
|
42
43
|
};
|
|
@@ -11,12 +11,20 @@ import { httpRequest } from "../http/http-request.js";
|
|
|
11
11
|
* @param {object} [opts] - Additional request options (e.g., rejectUnauthorized)
|
|
12
12
|
* @returns {Promise<unknown>} The parsed JSON response
|
|
13
13
|
*/
|
|
14
|
-
export async function triggerDirectusFlow(projectId, versions, opts = {}) {
|
|
14
|
+
export async function triggerDirectusFlow(projectId: string, versions: string[], opts: Record<string, unknown> = {}) {
|
|
15
15
|
const { DIRECTUS_URL, DIRECTUS_FLOW_ID, DIRECTUS_ACCESS_TOKEN } = getConfig();
|
|
16
16
|
|
|
17
17
|
const endpoint = `${DIRECTUS_URL}/flows/trigger/${DIRECTUS_FLOW_ID}`;
|
|
18
18
|
|
|
19
|
-
const options
|
|
19
|
+
const options: {
|
|
20
|
+
method: string;
|
|
21
|
+
callee: string;
|
|
22
|
+
headers: Record<string, string>;
|
|
23
|
+
data: Record<string, unknown> | string;
|
|
24
|
+
retries: number;
|
|
25
|
+
retryDelay: unknown;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
} = {
|
|
20
28
|
method: "post",
|
|
21
29
|
callee: "DIRECTUS",
|
|
22
30
|
headers: {
|
|
@@ -4,7 +4,13 @@ import { getConfig } from "../../get-config.js";
|
|
|
4
4
|
|
|
5
5
|
const { HTTPS_PROXY } = getConfig();
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface HttpProxyOptions {
|
|
8
|
+
callee?: string;
|
|
9
|
+
rejectUnauthorized?: boolean;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getHttpProxy = (opts: HttpProxyOptions) => {
|
|
8
14
|
if (HTTPS_PROXY) {
|
|
9
15
|
console.debug({
|
|
10
16
|
message: `Using proxy agent for ${opts.callee} requests`,
|
|
@@ -9,12 +9,12 @@ vi.mock("axios-retry");
|
|
|
9
9
|
vi.mock("./http-proxy.js");
|
|
10
10
|
|
|
11
11
|
describe("httpRequest", () => {
|
|
12
|
-
let mockInstance
|
|
12
|
+
let mockInstance: ReturnType<typeof vi.fn>;
|
|
13
13
|
|
|
14
14
|
beforeEach(() => {
|
|
15
15
|
vi.clearAllMocks();
|
|
16
16
|
mockInstance = vi.fn();
|
|
17
|
-
vi.mocked(axios.create).mockReturnValue(mockInstance);
|
|
17
|
+
vi.mocked(axios.create).mockReturnValue(mockInstance as unknown as ReturnType<typeof axios.create>);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it("should create an agent in production with proxy", async () => {
|
|
@@ -37,11 +37,12 @@ describe("httpRequest", () => {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it("should throw an error if the response is not ok", async () => {
|
|
40
|
-
const axiosError = new Error("Request failed")
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const axiosError = Object.assign(new Error("Request failed"), {
|
|
41
|
+
response: {
|
|
42
|
+
status: 500,
|
|
43
|
+
data: { error: "Internal server error" }
|
|
44
|
+
}
|
|
45
|
+
});
|
|
45
46
|
mockInstance.mockRejectedValue(axiosError);
|
|
46
47
|
|
|
47
48
|
await expect(httpRequest("http://example.com/test-endpoint", { callee: "test" })).rejects.toThrow("HTTP error! status: 500");
|
|
@@ -11,23 +11,19 @@ import { getHttpProxy } from "./http-proxy.js";
|
|
|
11
11
|
* @property {boolean} [retryOnIdempotentRequests=true] - Retry on 5xx for idempotent requests
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
interface HttpRequestOptions {
|
|
15
|
+
rejectUnauthorized?: boolean;
|
|
16
|
+
callee?: string;
|
|
17
|
+
params?: Record<string, string>;
|
|
18
|
+
method?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
retries?: number;
|
|
21
|
+
retryDelay?: unknown;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
* @param endpoint {string}
|
|
27
|
-
* @param options {HttpRequestOptions}
|
|
28
|
-
* @return {Promise<*>}
|
|
29
|
-
*/
|
|
30
|
-
export async function httpRequest(endpoint, options = {}) {
|
|
26
|
+
export async function httpRequest(endpoint: string, options: HttpRequestOptions = {}) {
|
|
31
27
|
const { callee, headers, method = "get", params = {}, rejectUnauthorized, ...rest } = options;
|
|
32
28
|
const httpsAgent = getHttpProxy({
|
|
33
29
|
rejectUnauthorized,
|
|
@@ -36,7 +32,7 @@ export async function httpRequest(endpoint, options = {}) {
|
|
|
36
32
|
|
|
37
33
|
const instance = axios.create();
|
|
38
34
|
|
|
39
|
-
axiosRetry(instance, options);
|
|
35
|
+
axiosRetry(instance, options as Parameters<typeof axiosRetry>[1]);
|
|
40
36
|
|
|
41
37
|
try {
|
|
42
38
|
const response = await instance({
|
|
@@ -60,8 +56,9 @@ export async function httpRequest(endpoint, options = {}) {
|
|
|
60
56
|
|
|
61
57
|
return response.data;
|
|
62
58
|
} catch (error) {
|
|
63
|
-
const
|
|
64
|
-
const
|
|
59
|
+
const axiosError = error as { response?: { status: number; data: unknown } };
|
|
60
|
+
const status = axiosError.response?.status;
|
|
61
|
+
const responseData = axiosError.response?.data;
|
|
65
62
|
|
|
66
63
|
console.error({
|
|
67
64
|
...options,
|
|
@@ -8,7 +8,7 @@ import { getJiraReleases } from "./jira-releases.js";
|
|
|
8
8
|
* @param component {string}
|
|
9
9
|
* @param tagVersion {string}
|
|
10
10
|
*/
|
|
11
|
-
export async function getSortedReleases(projectId, component, tagVersion) {
|
|
11
|
+
export async function getSortedReleases(projectId: string, component: string, tagVersion: string) {
|
|
12
12
|
const releases = await getJiraReleases(projectId);
|
|
13
13
|
|
|
14
14
|
const promises = releases
|
|
@@ -24,7 +24,7 @@ export async function getSortedReleases(projectId, component, tagVersion) {
|
|
|
24
24
|
}
|
|
25
25
|
})
|
|
26
26
|
.sort((ra, rb) => {
|
|
27
|
-
return semver.rcompare(ra.version
|
|
27
|
+
return semver.rcompare(ra.version!, rb.version!);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
const [current, ...others] = await Promise.all(promises);
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { jiraRequest } from "./jira-request.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface JiraRelease {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
archived?: boolean;
|
|
8
|
+
released?: boolean;
|
|
9
|
+
projectId?: string;
|
|
10
|
+
releaseDate?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function getJiraReleases(projectId: string): Promise<JiraRelease[]> {
|
|
4
15
|
const endpoint = `/rest/api/3/project/${projectId}/versions?expand`;
|
|
5
16
|
const response = await jiraRequest(endpoint);
|
|
6
17
|
|
|
@@ -8,10 +19,10 @@ export async function getJiraReleases(projectId) {
|
|
|
8
19
|
return [];
|
|
9
20
|
}
|
|
10
21
|
|
|
11
|
-
return response;
|
|
22
|
+
return response as JiraRelease[];
|
|
12
23
|
}
|
|
13
24
|
|
|
14
|
-
export async function updateJiraRelease(release) {
|
|
25
|
+
export async function updateJiraRelease(release: JiraRelease) {
|
|
15
26
|
const endpoint = `/rest/api/3/version/${release.id}`;
|
|
16
27
|
try {
|
|
17
28
|
await jiraRequest(endpoint, {
|
|
@@ -3,7 +3,15 @@ import axiosRetry from "axios-retry";
|
|
|
3
3
|
import { getConfig } from "../../get-config.js";
|
|
4
4
|
import { httpRequest } from "../http/http-request.js";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface JiraRequestOptions {
|
|
7
|
+
method?: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
data?: unknown;
|
|
10
|
+
params?: Record<string, string>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function jiraRequest(endpoint: string, opts: JiraRequestOptions = {}) {
|
|
7
15
|
const { JIRA_API, JIRA_TOKEN, JIRA_EMAIL } = getConfig();
|
|
8
16
|
const jiraUrl = `${JIRA_API}${endpoint}`;
|
|
9
17
|
const auth = Buffer.from(`${JIRA_EMAIL}:${JIRA_TOKEN}`).toString("base64");
|
|
@@ -7,10 +7,10 @@ import { jiraRequest } from "./jira-request.js";
|
|
|
7
7
|
* @param opts {object} Options
|
|
8
8
|
* @returns {Promise<{issues: (import("./interfaces/JiraIIssue.d.ts").JiraIssue & Expand)[], total: number, maxResults: number}>}
|
|
9
9
|
*/
|
|
10
|
-
export function jiraSearch(jql, opts) {
|
|
10
|
+
export function jiraSearch(jql: string, opts?: Record<string, unknown>) {
|
|
11
11
|
return jiraRequest("/rest/api/3/search/jql", {
|
|
12
12
|
params: {
|
|
13
|
-
...opts,
|
|
13
|
+
...(opts as Record<string, string>),
|
|
14
14
|
jql
|
|
15
15
|
}
|
|
16
16
|
});
|
|
@@ -1,24 +1,31 @@
|
|
|
1
|
+
import execa from "execa";
|
|
2
|
+
import { bun } from "./bun.js";
|
|
3
|
+
import { Cli } from "./cli.js";
|
|
4
|
+
|
|
1
5
|
vi.mock("execa", () => {
|
|
2
|
-
const
|
|
3
|
-
execaMock
|
|
6
|
+
const sync = vi.fn();
|
|
7
|
+
const execaMock = Object.assign(vi.fn(), { sync });
|
|
4
8
|
return { default: execaMock };
|
|
5
9
|
});
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
type ExecaMock = {
|
|
12
|
+
sync: { mockImplementation(fn: (...args: unknown[]) => unknown): void };
|
|
13
|
+
mockReturnValue(v: unknown): void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const execaMock = execa as unknown as ExecaMock;
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
execaMock.sync.mockImplementation((...args) => {
|
|
12
19
|
return {
|
|
13
|
-
stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
|
|
20
|
+
stdout: `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
|
|
14
21
|
};
|
|
15
22
|
});
|
|
16
|
-
|
|
23
|
+
execaMock.mockReturnValue({});
|
|
17
24
|
|
|
18
25
|
describe("BunCli", () => {
|
|
19
26
|
beforeEach(() => {
|
|
20
|
-
vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
|
|
21
|
-
return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
|
|
27
|
+
vi.spyOn(Cli, "getRaw").mockImplementation((...args: unknown[]) => {
|
|
28
|
+
return `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
|
|
22
29
|
});
|
|
23
30
|
});
|
|
24
31
|
describe("newVersion", () => {
|
|
@@ -5,19 +5,19 @@ class BunCli extends Cli {
|
|
|
5
5
|
super("bun");
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
newVersion(version) {
|
|
8
|
+
newVersion(version: string) {
|
|
9
9
|
return this.pm("version", "--no-git-tag-version", version);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
pm(...args) {
|
|
12
|
+
pm(...args: string[]) {
|
|
13
13
|
return this.sync("pm", ...args);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
run(...args) {
|
|
16
|
+
run(...args: string[]) {
|
|
17
17
|
return super.run("run", ...args);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
install(...args) {
|
|
20
|
+
install(...args: string[]) {
|
|
21
21
|
return super.run("install", ...args);
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import "any-observable/register/rxjs-all.js";
|
|
2
|
+
|
|
3
|
+
import { spawnSync, type SpawnSyncOptions } from "child_process";
|
|
4
|
+
import execa from "execa";
|
|
5
|
+
import { filter, fromEvent, map, merge, takeUntil } from "rxjs";
|
|
6
|
+
import type { Observable } from "rxjs";
|
|
7
|
+
|
|
8
|
+
type RunOptions = Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export interface CliResult extends Promise<unknown> {
|
|
11
|
+
toObservable(opt?: RunOptions): Observable<string>;
|
|
12
|
+
toStream(opt?: RunOptions): execa.ExecaChildProcess<string>;
|
|
13
|
+
cwd(cwd: string): CliResult;
|
|
14
|
+
sync(opt?: RunOptions): execa.ExecaSyncReturnValue<string>;
|
|
15
|
+
getRaw(opt?: RunOptions): string;
|
|
16
|
+
get(opt?: RunOptions): string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class Cli {
|
|
20
|
+
cmd: string;
|
|
21
|
+
|
|
22
|
+
constructor(cmd: string) {
|
|
23
|
+
this.cmd = cmd;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
sync(...args: string[]): execa.ExecaSyncReturnValue<string> {
|
|
27
|
+
return (Cli.run(this.cmd, args) as CliResult).sync();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
run(...args: string[]): CliResult {
|
|
31
|
+
return Cli.run(this.cmd, args);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get(...args: string[]): string {
|
|
35
|
+
return (Cli.run(this.cmd, args) as CliResult).get();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static run(cmd: string, args: string[] = [], options: RunOptions = {}): CliResult {
|
|
39
|
+
const run = (opt: RunOptions = {}) => {
|
|
40
|
+
return execa(cmd, args, {
|
|
41
|
+
cwd: process.cwd(),
|
|
42
|
+
...opt,
|
|
43
|
+
...options
|
|
44
|
+
} as execa.Options);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let isPromise = true;
|
|
48
|
+
|
|
49
|
+
const promise = new Promise<void>((resolve, reject) => {
|
|
50
|
+
setTimeout(async () => {
|
|
51
|
+
if (isPromise) {
|
|
52
|
+
try {
|
|
53
|
+
const result = await run({
|
|
54
|
+
stdio: "inherit"
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
resolve(result as unknown as void);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
reject(err);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
resolve();
|
|
63
|
+
}
|
|
64
|
+
}, 10);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const cliResult = promise as unknown as CliResult;
|
|
68
|
+
|
|
69
|
+
cliResult.toObservable = (opt?: RunOptions): Observable<string> => {
|
|
70
|
+
isPromise = false;
|
|
71
|
+
const cp = run(opt);
|
|
72
|
+
const end$ = fromEvent(cp, "close");
|
|
73
|
+
const stdout$ = fromEvent(cp.stdout!, "data").pipe(
|
|
74
|
+
takeUntil(end$),
|
|
75
|
+
map((data) => (data as Buffer).toString())
|
|
76
|
+
);
|
|
77
|
+
const stderr$ = fromEvent(cp.stderr!, "data").pipe(
|
|
78
|
+
takeUntil(end$),
|
|
79
|
+
map((data) => (data as Buffer).toString())
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return merge(stdout$, stderr$).pipe(filter(Boolean));
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
cliResult.toStream = (opt?: RunOptions) => {
|
|
86
|
+
isPromise = false;
|
|
87
|
+
|
|
88
|
+
return run(opt);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
cliResult.cwd = (cwd: string) => {
|
|
92
|
+
options.cwd = cwd;
|
|
93
|
+
return cliResult;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
cliResult.sync = (opt?: RunOptions) => {
|
|
97
|
+
isPromise = false;
|
|
98
|
+
return execa.sync(cmd, args, {
|
|
99
|
+
cwd: process.cwd(),
|
|
100
|
+
stdio: "inherit",
|
|
101
|
+
...options,
|
|
102
|
+
...opt
|
|
103
|
+
} as execa.SyncOptions);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
cliResult.getRaw = (opt?: RunOptions): string => {
|
|
107
|
+
isPromise = false;
|
|
108
|
+
return Cli.getRaw(cmd, args, {
|
|
109
|
+
cwd: process.cwd(),
|
|
110
|
+
...options,
|
|
111
|
+
...opt
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
cliResult.get = cliResult.getRaw;
|
|
116
|
+
|
|
117
|
+
return cliResult;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static getRaw(cmd: string, args: string[], options?: RunOptions): string {
|
|
121
|
+
return (spawnSync(cmd, args, options as SpawnSyncOptions).output as (Buffer | null)[])
|
|
122
|
+
.filter((o): o is Buffer => o !== null)
|
|
123
|
+
.map((o) => o.toString())
|
|
124
|
+
.join("\n")
|
|
125
|
+
.trim();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -1,28 +1,36 @@
|
|
|
1
|
+
import execa from "execa";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { docker } from "./docker.js";
|
|
4
|
+
import { Cli } from "./cli.js";
|
|
5
|
+
|
|
1
6
|
vi.mock("axios", () => {
|
|
2
7
|
return { default: vi.fn() };
|
|
3
8
|
});
|
|
4
9
|
vi.mock("execa", () => {
|
|
5
|
-
const
|
|
6
|
-
execaMock
|
|
10
|
+
const sync = vi.fn();
|
|
11
|
+
const execaMock = Object.assign(vi.fn(), { sync });
|
|
7
12
|
return { default: execaMock };
|
|
8
13
|
});
|
|
9
|
-
const { default: execa } = await import("execa");
|
|
10
|
-
const { default: axios } = await import("axios");
|
|
11
|
-
const { docker } = await import("./docker.js");
|
|
12
|
-
const { Cli } = await import("./cli.js");
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
type ExecaMock = {
|
|
16
|
+
sync: { mockImplementation(fn: (...args: unknown[]) => unknown): void };
|
|
17
|
+
mockReturnValue(v: unknown): void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const execaMock = execa as unknown as ExecaMock;
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
execaMock.mockReturnValue({});
|
|
23
|
+
|
|
24
|
+
execaMock.sync.mockImplementation((...args) => {
|
|
17
25
|
return {
|
|
18
|
-
stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
|
|
26
|
+
stdout: `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
|
|
19
27
|
};
|
|
20
28
|
});
|
|
21
29
|
|
|
22
30
|
describe("DockerCli", () => {
|
|
23
31
|
beforeEach(() => {
|
|
24
|
-
vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
|
|
25
|
-
return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
|
|
32
|
+
vi.spyOn(Cli, "getRaw").mockImplementation((...args: unknown[]) => {
|
|
33
|
+
return `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
|
|
26
34
|
});
|
|
27
35
|
});
|
|
28
36
|
describe("tag", () => {
|
|
@@ -58,7 +66,7 @@ describe("DockerCli", () => {
|
|
|
58
66
|
});
|
|
59
67
|
describe("getToken", () => {
|
|
60
68
|
beforeEach(() => {
|
|
61
|
-
axios.mockReturnValue({ data: { token: "token" } });
|
|
69
|
+
vi.mocked(axios).mockReturnValue({ data: { token: "token" } } as unknown as ReturnType<typeof axios>);
|
|
62
70
|
});
|
|
63
71
|
it("should get token", async () => {
|
|
64
72
|
const token = await docker.getToken("username", "password");
|
|
@@ -80,7 +88,7 @@ describe("DockerCli", () => {
|
|
|
80
88
|
});
|
|
81
89
|
describe("getTags", () => {
|
|
82
90
|
beforeEach(() => {
|
|
83
|
-
axios.mockReturnValue({
|
|
91
|
+
vi.mocked(axios).mockReturnValue({
|
|
84
92
|
data: {
|
|
85
93
|
results: [
|
|
86
94
|
{
|
|
@@ -89,7 +97,7 @@ describe("DockerCli", () => {
|
|
|
89
97
|
}
|
|
90
98
|
]
|
|
91
99
|
}
|
|
92
|
-
});
|
|
100
|
+
} as unknown as ReturnType<typeof axios>);
|
|
93
101
|
});
|
|
94
102
|
it("should get token", async () => {
|
|
95
103
|
const tags = await docker.getTags({
|
|
@@ -7,19 +7,19 @@ class DockerCli extends Cli {
|
|
|
7
7
|
super("docker");
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
tag(...args) {
|
|
10
|
+
tag(...args: string[]) {
|
|
11
11
|
return this.get("tag", ...args);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
login(...args) {
|
|
14
|
+
login(...args: string[]) {
|
|
15
15
|
return this.sync("login", ...args);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
push(...args) {
|
|
18
|
+
push(...args: string[]) {
|
|
19
19
|
return this.run("push", ...args);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
async getToken(username, password) {
|
|
22
|
+
async getToken(username: string, password: string) {
|
|
23
23
|
const {
|
|
24
24
|
data: { token }
|
|
25
25
|
} = await axios({
|
|
@@ -38,7 +38,7 @@ class DockerCli extends Cli {
|
|
|
38
38
|
return token;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async getTags({ token, repository }) {
|
|
41
|
+
async getTags({ token, repository }: { token: string; repository: string }) {
|
|
42
42
|
const { data } = await axios({
|
|
43
43
|
method: "GET",
|
|
44
44
|
url: `https://hub.docker.com/v2/repositories/${repository}/tags/?page=1&page_size=500`,
|
|
@@ -51,7 +51,7 @@ class DockerCli extends Cli {
|
|
|
51
51
|
return data.results;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async deleteTag(tag, { token, repository }) {
|
|
54
|
+
async deleteTag(tag: string, { token, repository }: { token: string; repository: string }) {
|
|
55
55
|
await axios({
|
|
56
56
|
method: "DELETE",
|
|
57
57
|
url: `https://hub.docker.com/v2/repositories/${repository}/tags/${tag}/`,
|