js-code-detector 0.0.34 → 0.0.35

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,8 +1,8 @@
1
1
  import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
2
2
  export type CloneType = 'ssh' | 'token';
3
3
  export declare function cloneGitRepo(gitUrl: string, branchName: string, tempDirPath: string, folder: string, cloneType?: CloneType): Promise<{
4
- failed: boolean;
5
- stderr: string;
4
+ failed: boolean | undefined;
5
+ stderr: string | undefined;
6
6
  }>;
7
7
  export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string, cloneType?: CloneType): Promise<{
8
8
  [k: string]: string[];
@@ -48,6 +48,7 @@ var import__ = require("../../index");
48
48
  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
+ var import_gitUtil = require("./gitUtil");
51
52
  async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, cloneType) {
52
53
  import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${tempDirPath}/${folder} 文件夹`);
53
54
  let stderr, failed;
@@ -58,7 +59,7 @@ async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder, cloneType)
58
59
  const repoUrl = (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitUrl);
59
60
  ({ stderr, failed } = await import_utils.execa.execa(`git clone ${repoUrl} ${tempDirPath}/${folder}`, { shell: true }));
60
61
  } else {
61
- ({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${tempDirPath}/${folder}`, { shell: true }));
62
+ await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(gitUrl, `${tempDirPath}/${folder}`, branchName);
62
63
  }
63
64
  (0, import_handleExecaError.handleExecaError)({ failed, stderr });
64
65
  import_utils.logger.info("源代码clone完成");
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 克隆 Git 仓库,同时获取目标分支和默认分支的代码
3
+ * @param {string} repoUrl - 仓库地址(带认证信息的 HTTPS/SSH 地址)
4
+ * @param {string} targetBranch - 主要目标分支(如 dev)
5
+ * @param {string} targetDir - 本地目标目录
6
+ * @returns {Promise<string>} 克隆目录路径
7
+ */
8
+ export declare function cloneRepoWithBranchAndDefault(repoUrl: string, targetBranch: string, targetDir: string): Promise<string>;
@@ -0,0 +1,51 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util/shared/gitUtil.ts
20
+ var gitUtil_exports = {};
21
+ __export(gitUtil_exports, {
22
+ cloneRepoWithBranchAndDefault: () => cloneRepoWithBranchAndDefault
23
+ });
24
+ module.exports = __toCommonJS(gitUtil_exports);
25
+ var simpleGit = require("simple-git");
26
+ async function cloneRepoWithBranchAndDefault(repoUrl, targetBranch, targetDir) {
27
+ try {
28
+ const git = simpleGit();
29
+ await git.clone(repoUrl, targetDir, [
30
+ `--branch=${targetBranch}`
31
+ // 初始检出目标分支
32
+ // 不添加 --single-branch,默认会拉取所有分支的引用
33
+ ]);
34
+ const repoGit = simpleGit(targetDir);
35
+ const remoteInfo = await repoGit.remote(["show", "origin"]);
36
+ const defaultBranchMatch = remoteInfo.match(/HEAD branch: (\S+)/);
37
+ const defaultBranch = defaultBranchMatch ? defaultBranchMatch[1] : "main";
38
+ await repoGit.checkout(defaultBranch);
39
+ await repoGit.pull("origin", defaultBranch);
40
+ await repoGit.checkout(targetBranch);
41
+ console.log(`克隆完成:目标分支 ${targetBranch} + 默认分支 ${defaultBranch},路径:${targetDir}`);
42
+ return targetDir;
43
+ } catch (error) {
44
+ console.error(`克隆失败:${error.message}`);
45
+ throw error;
46
+ }
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ cloneRepoWithBranchAndDefault
51
+ });
@@ -1,4 +1,4 @@
1
1
  export declare function handleExecaError({ failed, stderr }: {
2
- failed: boolean;
3
- stderr: string;
2
+ failed: boolean | undefined;
3
+ stderr: string | undefined;
4
4
  }): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -42,6 +42,7 @@
42
42
  "dayjs": "^1.11.13",
43
43
  "lodash": "^4.17.21",
44
44
  "madge": "^8.0.0",
45
+ "simple-git": "^3.28.0",
45
46
  "vue-eslint-parser": "^10.2.0"
46
47
  }
47
48
  }