js-code-detector 0.0.33 → 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.
@@ -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, cloneType?: 'ssh'): Promise<{
52
+ export declare function getUpstreamDependenceJson(inputUrl: string, cloneType?: CloneType): Promise<{
52
53
  [k: string]: string[];
53
54
  } | undefined>;
@@ -11,3 +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;
@@ -19,6 +19,7 @@ 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,
22
23
  getSshGitRepoUrl: () => getSshGitRepoUrl,
23
24
  parseGitLabCompareUrl: () => parseGitLabCompareUrl
24
25
  });
@@ -61,8 +62,22 @@ function parseGitLabCompareUrl(compareUrl) {
61
62
  function getSshGitRepoUrl(gitRepoUrl) {
62
63
  return gitRepoUrl.replace(/https?:\/\/[^/]+/, "git@");
63
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
+ }
64
78
  // Annotate the CommonJS export names for ESM import in node:
65
79
  0 && (module.exports = {
80
+ getGitRepoUrlByToken,
66
81
  getSshGitRepoUrl,
67
82
  parseGitLabCompareUrl
68
83
  });
@@ -1,9 +1,10 @@
1
1
  import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
2
- export declare function cloneGitRepo(gitUrl: string, branchName: string, tempDirPath: string, folder: string, cloneType?: 'ssh'): Promise<{
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, cloneType?: 'ssh'): 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: {
@@ -54,6 +54,9 @@ async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, cloneType)
54
54
  if (cloneType === "ssh") {
55
55
  const sshGitRepoUrl = (0, import_parseGitLabDiffUril.getSshGitRepoUrl)(gitUrl);
56
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 }));
57
60
  } else {
58
61
  ({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${tempDirPath}/${folder}`, { shell: true }));
59
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",