js-code-detector 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import { CloneType } from "./util/shared/gitDiffTool";
2
1
  export declare const gitDiffFileName = "git_diff.txt";
3
2
  export declare function getGitRepositoryAndBranch(): Promise<{
4
3
  gitUrl: string;
@@ -49,6 +48,6 @@ export declare function gitDiffDetectByUrl(inputUrl: string): Promise<{
49
48
  filePath: string;
50
49
  }[];
51
50
  } | undefined>;
52
- export declare function getUpstreamDependenceJson(inputUrl: string, cloneType?: CloneType): Promise<{
51
+ export declare function getUpstreamDependenceJson(inputUrl: string, token: string): Promise<{
53
52
  [k: string]: string[];
54
53
  } | 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, cloneType) {
78
+ async function getUpstreamDependenceJson(inputUrl, token) {
79
79
  const gitInfo = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
80
- return (0, import_gitDiffTool.cloneGitRepoAndGetDiff)(gitInfo.gitRepoUrl, gitInfo.targetBranch, cloneType);
80
+ return (0, import_gitDiffTool.cloneGitRepoAndGetDiff)(gitInfo.gitRepoUrl, gitInfo.targetBranch, { cloneType: token ? "token" : void 0, token });
81
81
  }
82
82
  // Annotate the CommonJS export names for ESM import in node:
83
83
  0 && (module.exports = {
@@ -11,4 +11,4 @@ export declare function parseGitLabCompareUrl(compareUrl: string): {
11
11
  targetBranch: string;
12
12
  };
13
13
  export declare function getSshGitRepoUrl(gitRepoUrl: string): string;
14
- export declare function getGitRepoUrlByToken(gitRepoUrl: string): string;
14
+ export declare function getGitRepoUrlByToken(gitRepoUrl: string, gitlabToken: string): string;
@@ -62,10 +62,9 @@ function parseGitLabCompareUrl(compareUrl) {
62
62
  function getSshGitRepoUrl(gitRepoUrl) {
63
63
  return gitRepoUrl.replace(/https?:\/\/[^/]+/, "git@");
64
64
  }
65
- function getGitRepoUrlByToken(gitRepoUrl) {
65
+ function getGitRepoUrlByToken(gitRepoUrl, gitlabToken) {
66
66
  const urlObj = new URL(gitRepoUrl);
67
- const gitlabToken = process.env.GITLAB_ACCESS_TOKEN;
68
- const gitlabDomain = process.env.GITLAB_DOMAIN || urlObj.hostname;
67
+ const gitlabDomain = urlObj.hostname;
69
68
  const projectPath = urlObj.pathname.replace(/\.git/, "");
70
69
  if (!gitlabToken) {
71
70
  throw new Error("未配置 GitLab accessToken,请通过 GITLAB_ACCESS_TOKEN 环境变量传入");
@@ -1,10 +1,16 @@
1
1
  import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
2
2
  export type CloneType = 'ssh' | 'token';
3
- export declare function cloneGitRepo(gitUrl: string, branchName: string, tempDirPath: string, folder: string, cloneType?: CloneType): Promise<{
3
+ export declare function cloneGitRepo(gitUrl: string, branchName: string, tempDirPath: string, folder: string, extra?: {
4
+ cloneType?: CloneType;
5
+ token?: string;
6
+ }): Promise<{
4
7
  failed: boolean | undefined;
5
8
  stderr: string | undefined;
6
9
  }>;
7
- export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string, cloneType?: CloneType): Promise<{
10
+ export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string, extra?: {
11
+ cloneType?: CloneType;
12
+ token?: string;
13
+ }): Promise<{
8
14
  [k: string]: string[];
9
15
  } | undefined>;
10
16
  export declare function gitDiffTool(arg: {
@@ -49,14 +49,15 @@ var import_dayjs = __toESM(require("dayjs"));
49
49
  var import_fs = require("fs");
50
50
  var import_format_git_diff_content = require("../format_git_diff_content");
51
51
  var import_gitUtil = require("./gitUtil");
52
- async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, cloneType) {
52
+ async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, extra = {}) {
53
+ const { cloneType, token = "" } = extra;
53
54
  import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${tempDirPath}/${folder} 文件夹`);
54
55
  let stderr, failed;
55
56
  if (cloneType === "ssh") {
56
57
  const sshGitRepoUrl = (0, import_parseGitLabDiffUril.getSshGitRepoUrl)(gitUrl);
57
58
  ({ stderr, failed } = await import_utils.execa.execa(`git clone ${sshGitRepoUrl} ${tempDirPath}/${folder}`, { shell: true }));
58
59
  } else if (cloneType === "token") {
59
- const repoUrl = (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitUrl);
60
+ const repoUrl = (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitUrl, token);
60
61
  ({ stderr, failed } = await import_utils.execa.execa(`git clone ${repoUrl} ${tempDirPath}/${folder}`, { shell: true }));
61
62
  } else {
62
63
  await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(gitUrl, `${tempDirPath}/${folder}`, branchName);
@@ -71,7 +72,8 @@ async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, cloneType)
71
72
  }
72
73
  return { failed, stderr };
73
74
  }
74
- async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, cloneType) {
75
+ async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, extra = {}) {
76
+ const { cloneType, token } = extra;
75
77
  const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
76
78
  import_utils.logger.ready("准备生成临时工作目录...");
77
79
  const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: true }));
@@ -82,7 +84,7 @@ async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, cloneType) {
82
84
  import_utils.logger.info("临时目录建立完成");
83
85
  try {
84
86
  let stderr, failed;
85
- ({ stderr, failed } = await cloneGitRepo(gitRepoUrl, branchName, today, import_constants.TARGET, cloneType));
87
+ ({ stderr, failed } = await cloneGitRepo(gitRepoUrl, branchName, today, import_constants.TARGET, { cloneType, token }));
86
88
  (0, import_handleExecaError.handleExecaError)({ failed, stderr });
87
89
  import_utils.logger.ready("准备生成git_diff.txt文件");
88
90
  ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff master..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: true }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",