@allurereport/git 3.13.0 → 3.13.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.
@@ -1,5 +1,18 @@
1
1
  import { runGit } from "./runGit.js";
2
2
  export const DEFAULT_ANCESTOR_LIMIT = 100;
3
+ const normalizeAncestorLimit = (value) => {
4
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) {
5
+ return Math.floor(value);
6
+ }
7
+ return DEFAULT_ANCESTOR_LIMIT;
8
+ };
9
+ const normalizePositiveInteger = (value) => {
10
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
11
+ return undefined;
12
+ }
13
+ const normalized = Math.floor(value);
14
+ return normalized > 0 ? normalized : undefined;
15
+ };
3
16
  const stripRemotePrefix = (upstreamRef) => {
4
17
  const slashIndex = upstreamRef.indexOf("/");
5
18
  return slashIndex >= 0 ? upstreamRef.slice(slashIndex + 1) : upstreamRef;
@@ -15,6 +28,36 @@ const resolveBranch = (cwd) => {
15
28
  }
16
29
  return branchRaw;
17
30
  };
31
+ const DEEPEN_FETCH_FILTERS = ["--filter=tree:0", "--filter=blob:none"];
32
+ const deepenFetch = (deepenBy, cwd) => {
33
+ const deepen = String(deepenBy);
34
+ const strategies = [
35
+ ["fetch", "--deepen", deepen, DEEPEN_FETCH_FILTERS[0]],
36
+ ["fetch", "--deepen", deepen, DEEPEN_FETCH_FILTERS[1]],
37
+ ["fetch", "--deepen", deepen],
38
+ ];
39
+ for (const args of strategies) {
40
+ if (runGit(args, cwd) !== undefined) {
41
+ return;
42
+ }
43
+ }
44
+ };
45
+ const ensureAncestorHistory = (ancestorLimit, cwd) => {
46
+ if (runGit(["rev-parse", "--is-shallow-repository"], cwd) !== "true") {
47
+ return;
48
+ }
49
+ const needed = ancestorLimit + 1;
50
+ const availableRaw = runGit(["rev-list", "--first-parent", "--count", "HEAD"], cwd);
51
+ const available = normalizePositiveInteger(Number(availableRaw)) ?? 0;
52
+ if (available >= needed) {
53
+ return;
54
+ }
55
+ const deepenBy = normalizePositiveInteger(available > 0 ? needed - available : ancestorLimit);
56
+ if (!deepenBy) {
57
+ return;
58
+ }
59
+ deepenFetch(deepenBy, cwd);
60
+ };
18
61
  const collectLocalState = (cwd) => {
19
62
  const statusPorcelain = runGit(["status", "--porcelain"], cwd) ?? "";
20
63
  const branchRaw = runGit(["rev-parse", "--abbrev-ref", "HEAD"], cwd);
@@ -30,7 +73,8 @@ const collectLocalState = (cwd) => {
30
73
  };
31
74
  };
32
75
  export const collectGitFacts = (options = {}) => {
33
- const { cwd, ancestorLimit = DEFAULT_ANCESTOR_LIMIT } = options;
76
+ const { cwd } = options;
77
+ const ancestorLimit = normalizeAncestorLimit(options.ancestorLimit);
34
78
  if (runGit(["rev-parse", "--is-inside-work-tree"], cwd) !== "true") {
35
79
  return undefined;
36
80
  }
@@ -39,6 +83,7 @@ export const collectGitFacts = (options = {}) => {
39
83
  return undefined;
40
84
  }
41
85
  const branch = resolveBranch(cwd);
86
+ ensureAncestorHistory(ancestorLimit, cwd);
42
87
  const revList = runGit(["rev-list", "--first-parent", commit, `--max-count=${ancestorLimit + 1}`], cwd);
43
88
  if (!revList) {
44
89
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/git",
3
- "version": "3.13.0",
3
+ "version": "3.13.1",
4
4
  "description": "Git metadata collection for Allure Git Flow",
5
5
  "keywords": [
6
6
  "allure",
@@ -29,7 +29,7 @@
29
29
  "lint:fix": "oxlint --import-plugin --fix src test"
30
30
  },
31
31
  "dependencies": {
32
- "@allurereport/core-api": "3.13.0"
32
+ "@allurereport/core-api": "3.13.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^20",