js-code-detector 0.0.32 → 0.0.34
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/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/util/parseGitLabDiffUril.d.ts +2 -0
- package/dist/cjs/util/parseGitLabDiffUril.js +20 -0
- package/dist/cjs/util/shared/gitDiffTool.d.ts +3 -2
- package/dist/cjs/util/shared/gitDiffTool.js +13 -4
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CloneType } from "./util/shared/gitDiffTool";
|
|
1
2
|
export declare const gitDiffFileName = "git_diff.txt";
|
|
2
3
|
export declare function getGitRepositoryAndBranch(): Promise<{
|
|
3
4
|
gitUrl: string;
|
|
@@ -48,6 +49,6 @@ export declare function gitDiffDetectByUrl(inputUrl: string): Promise<{
|
|
|
48
49
|
filePath: string;
|
|
49
50
|
}[];
|
|
50
51
|
} | undefined>;
|
|
51
|
-
export declare function getUpstreamDependenceJson(inputUrl: string): Promise<{
|
|
52
|
+
export declare function getUpstreamDependenceJson(inputUrl: string, cloneType?: CloneType): Promise<{
|
|
52
53
|
[k: string]: string[];
|
|
53
54
|
} | undefined>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -75,9 +75,9 @@ async function gitDiffDetectByUrl(inputUrl) {
|
|
|
75
75
|
const gitInfo = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
|
|
76
76
|
return (0, import_gitDiffTool.gitDiffTool)({ ...gitInfo, tempDirPath: today, generateFile: [] });
|
|
77
77
|
}
|
|
78
|
-
async function getUpstreamDependenceJson(inputUrl) {
|
|
78
|
+
async function getUpstreamDependenceJson(inputUrl, cloneType) {
|
|
79
79
|
const gitInfo = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
|
|
80
|
-
return (0, import_gitDiffTool.cloneGitRepoAndGetDiff)(gitInfo.gitRepoUrl, gitInfo.targetBranch);
|
|
80
|
+
return (0, import_gitDiffTool.cloneGitRepoAndGetDiff)(gitInfo.gitRepoUrl, gitInfo.targetBranch, cloneType);
|
|
81
81
|
}
|
|
82
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
83
|
0 && (module.exports = {
|
|
@@ -10,3 +10,5 @@ export declare function parseGitLabCompareUrl(compareUrl: string): {
|
|
|
10
10
|
baseBranch: string;
|
|
11
11
|
targetBranch: string;
|
|
12
12
|
};
|
|
13
|
+
export declare function getSshGitRepoUrl(gitRepoUrl: string): string;
|
|
14
|
+
export declare function getGitRepoUrlByToken(gitRepoUrl: string): string;
|
|
@@ -19,6 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/parseGitLabDiffUril.ts
|
|
20
20
|
var parseGitLabDiffUril_exports = {};
|
|
21
21
|
__export(parseGitLabDiffUril_exports, {
|
|
22
|
+
getGitRepoUrlByToken: () => getGitRepoUrlByToken,
|
|
23
|
+
getSshGitRepoUrl: () => getSshGitRepoUrl,
|
|
22
24
|
parseGitLabCompareUrl: () => parseGitLabCompareUrl
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(parseGitLabDiffUril_exports);
|
|
@@ -57,7 +59,25 @@ function parseGitLabCompareUrl(compareUrl) {
|
|
|
57
59
|
targetBranch
|
|
58
60
|
};
|
|
59
61
|
}
|
|
62
|
+
function getSshGitRepoUrl(gitRepoUrl) {
|
|
63
|
+
return gitRepoUrl.replace(/https?:\/\/[^/]+/, "git@");
|
|
64
|
+
}
|
|
65
|
+
function getGitRepoUrlByToken(gitRepoUrl) {
|
|
66
|
+
const urlObj = new URL(gitRepoUrl);
|
|
67
|
+
const gitlabToken = process.env.GITLAB_ACCESS_TOKEN;
|
|
68
|
+
const gitlabDomain = process.env.GITLAB_DOMAIN || urlObj.hostname;
|
|
69
|
+
const projectPath = urlObj.pathname.replace(/\.git/, "");
|
|
70
|
+
if (!gitlabToken) {
|
|
71
|
+
throw new Error("未配置 GitLab accessToken,请通过 GITLAB_ACCESS_TOKEN 环境变量传入");
|
|
72
|
+
}
|
|
73
|
+
if (!projectPath) {
|
|
74
|
+
throw new Error("请传入 GitLab 项目路径(如 dev-team/my-project)");
|
|
75
|
+
}
|
|
76
|
+
return `http://${gitlabToken}@${gitlabDomain}/${projectPath}.git`;
|
|
77
|
+
}
|
|
60
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
79
|
0 && (module.exports = {
|
|
80
|
+
getGitRepoUrlByToken,
|
|
81
|
+
getSshGitRepoUrl,
|
|
62
82
|
parseGitLabCompareUrl
|
|
63
83
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
|
|
2
|
-
export
|
|
2
|
+
export type CloneType = 'ssh' | 'token';
|
|
3
|
+
export declare function cloneGitRepo(gitUrl: string, branchName: string, tempDirPath: string, folder: string, cloneType?: CloneType): Promise<{
|
|
3
4
|
failed: boolean;
|
|
4
5
|
stderr: string;
|
|
5
6
|
}>;
|
|
6
|
-
export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string): Promise<{
|
|
7
|
+
export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string, cloneType?: CloneType): Promise<{
|
|
7
8
|
[k: string]: string[];
|
|
8
9
|
} | undefined>;
|
|
9
10
|
export declare function gitDiffTool(arg: {
|
|
@@ -34,6 +34,7 @@ __export(gitDiffTool_exports, {
|
|
|
34
34
|
gitDiffTool: () => gitDiffTool
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(gitDiffTool_exports);
|
|
37
|
+
var import_parseGitLabDiffUril = require("../parseGitLabDiffUril");
|
|
37
38
|
var import_utils = require("@umijs/utils");
|
|
38
39
|
var import_await_to_js = __toESM(require("await-to-js"));
|
|
39
40
|
var import_constants = require("../constants");
|
|
@@ -47,10 +48,18 @@ var import__ = require("../../index");
|
|
|
47
48
|
var import_dayjs = __toESM(require("dayjs"));
|
|
48
49
|
var import_fs = require("fs");
|
|
49
50
|
var import_format_git_diff_content = require("../format_git_diff_content");
|
|
50
|
-
async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder) {
|
|
51
|
+
async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, cloneType) {
|
|
51
52
|
import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${tempDirPath}/${folder} 文件夹`);
|
|
52
53
|
let stderr, failed;
|
|
53
|
-
|
|
54
|
+
if (cloneType === "ssh") {
|
|
55
|
+
const sshGitRepoUrl = (0, import_parseGitLabDiffUril.getSshGitRepoUrl)(gitUrl);
|
|
56
|
+
({ stderr, failed } = await import_utils.execa.execa(`git clone ${sshGitRepoUrl} ${tempDirPath}/${folder}`, { shell: true }));
|
|
57
|
+
} else if (cloneType === "token") {
|
|
58
|
+
const repoUrl = (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitUrl);
|
|
59
|
+
({ stderr, failed } = await import_utils.execa.execa(`git clone ${repoUrl} ${tempDirPath}/${folder}`, { shell: true }));
|
|
60
|
+
} else {
|
|
61
|
+
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${tempDirPath}/${folder}`, { shell: true }));
|
|
62
|
+
}
|
|
54
63
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
55
64
|
import_utils.logger.info("源代码clone完成");
|
|
56
65
|
if (branchName !== "master") {
|
|
@@ -61,7 +70,7 @@ async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder) {
|
|
|
61
70
|
}
|
|
62
71
|
return { failed, stderr };
|
|
63
72
|
}
|
|
64
|
-
async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName) {
|
|
73
|
+
async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, cloneType) {
|
|
65
74
|
const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
|
|
66
75
|
import_utils.logger.ready("准备生成临时工作目录...");
|
|
67
76
|
const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: true }));
|
|
@@ -72,7 +81,7 @@ async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName) {
|
|
|
72
81
|
import_utils.logger.info("临时目录建立完成");
|
|
73
82
|
try {
|
|
74
83
|
let stderr, failed;
|
|
75
|
-
({ stderr, failed } = await cloneGitRepo(gitRepoUrl, branchName, today, import_constants.TARGET));
|
|
84
|
+
({ stderr, failed } = await cloneGitRepo(gitRepoUrl, branchName, today, import_constants.TARGET, cloneType));
|
|
76
85
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
77
86
|
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
78
87
|
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff master..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: true }));
|