@allurereport/git 3.13.0
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/collectGitFacts.d.ts +7 -0
- package/dist/collectGitFacts.js +57 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/isGitAvailable.d.ts +1 -0
- package/dist/isGitAvailable.js +5 -0
- package/dist/runGit.d.ts +1 -0
- package/dist/runGit.js +29 -0
- package/package.json +43 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GitFacts } from "@allurereport/core-api";
|
|
2
|
+
export declare const DEFAULT_ANCESTOR_LIMIT = 100;
|
|
3
|
+
export type CollectGitFactsOptions = {
|
|
4
|
+
cwd?: string;
|
|
5
|
+
ancestorLimit?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const collectGitFacts: (options?: CollectGitFactsOptions) => GitFacts | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { runGit } from "./runGit.js";
|
|
2
|
+
export const DEFAULT_ANCESTOR_LIMIT = 100;
|
|
3
|
+
const stripRemotePrefix = (upstreamRef) => {
|
|
4
|
+
const slashIndex = upstreamRef.indexOf("/");
|
|
5
|
+
return slashIndex >= 0 ? upstreamRef.slice(slashIndex + 1) : upstreamRef;
|
|
6
|
+
};
|
|
7
|
+
const resolveBranch = (cwd) => {
|
|
8
|
+
const branchRaw = runGit(["rev-parse", "--abbrev-ref", "HEAD"], cwd);
|
|
9
|
+
if (!branchRaw || branchRaw === "HEAD") {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const upstreamBranch = runGit(["rev-parse", "--abbrev-ref", "@{u}"], cwd);
|
|
13
|
+
if (upstreamBranch) {
|
|
14
|
+
return stripRemotePrefix(upstreamBranch);
|
|
15
|
+
}
|
|
16
|
+
return branchRaw;
|
|
17
|
+
};
|
|
18
|
+
const collectLocalState = (cwd) => {
|
|
19
|
+
const statusPorcelain = runGit(["status", "--porcelain"], cwd) ?? "";
|
|
20
|
+
const branchRaw = runGit(["rev-parse", "--abbrev-ref", "HEAD"], cwd);
|
|
21
|
+
const detachedHead = branchRaw === "HEAD";
|
|
22
|
+
const headCommit = runGit(["rev-parse", "--verify", "HEAD"], cwd);
|
|
23
|
+
const upstreamCommit = runGit(["rev-parse", "--verify", "@{u}"], cwd);
|
|
24
|
+
const upstreamBranch = runGit(["rev-parse", "--abbrev-ref", "@{u}"], cwd);
|
|
25
|
+
return {
|
|
26
|
+
uncommittedChanges: statusPorcelain.length > 0,
|
|
27
|
+
unpublishedCommit: !upstreamCommit || headCommit !== upstreamCommit,
|
|
28
|
+
unpublishedBranch: !upstreamBranch,
|
|
29
|
+
detachedHead,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const collectGitFacts = (options = {}) => {
|
|
33
|
+
const { cwd, ancestorLimit = DEFAULT_ANCESTOR_LIMIT } = options;
|
|
34
|
+
if (runGit(["rev-parse", "--is-inside-work-tree"], cwd) !== "true") {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const commit = runGit(["rev-parse", "HEAD"], cwd);
|
|
38
|
+
if (!commit) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const branch = resolveBranch(cwd);
|
|
42
|
+
const revList = runGit(["rev-list", "--first-parent", commit, `--max-count=${ancestorLimit + 1}`], cwd);
|
|
43
|
+
if (!revList) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const firstParentAncestors = revList
|
|
47
|
+
.split("\n")
|
|
48
|
+
.map((line) => line.trim())
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.slice(1);
|
|
51
|
+
return {
|
|
52
|
+
commit,
|
|
53
|
+
branch,
|
|
54
|
+
firstParentAncestors,
|
|
55
|
+
localState: collectLocalState(cwd),
|
|
56
|
+
};
|
|
57
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isGitAvailable: () => boolean;
|
package/dist/runGit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runGit: (args: string[], cwd?: string) => string | undefined;
|
package/dist/runGit.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
const isGitDebugEnabled = () => {
|
|
3
|
+
const value = process.env.ALLURE_DEBUG?.trim().toLowerCase();
|
|
4
|
+
return value === "1" || value === "true";
|
|
5
|
+
};
|
|
6
|
+
const hasUnsafeGitArgs = (args) => {
|
|
7
|
+
return args.some((arg) => arg === "--upload-pack" || arg.startsWith("--upload-pack="));
|
|
8
|
+
};
|
|
9
|
+
export const runGit = (args, cwd) => {
|
|
10
|
+
if (hasUnsafeGitArgs(args)) {
|
|
11
|
+
if (isGitDebugEnabled()) {
|
|
12
|
+
process.stderr.write(`[allurereport/git] blocked unsafe git arguments: ${args.join(" ")}\n`);
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const result = spawnSync("git", args, {
|
|
17
|
+
cwd,
|
|
18
|
+
encoding: "utf-8",
|
|
19
|
+
});
|
|
20
|
+
if (result.error || result.status !== 0) {
|
|
21
|
+
if (isGitDebugEnabled()) {
|
|
22
|
+
const stderr = result.stderr?.trim();
|
|
23
|
+
const status = result.status ?? "n/a";
|
|
24
|
+
process.stderr.write(`[allurereport/git] git ${args.join(" ")} failed (status=${status})${stderr ? `: ${stderr}` : ""}\n`);
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return result.stdout.trim();
|
|
29
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@allurereport/git",
|
|
3
|
+
"version": "3.13.0",
|
|
4
|
+
"description": "Git metadata collection for Allure Git Flow",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"allure",
|
|
7
|
+
"git",
|
|
8
|
+
"report",
|
|
9
|
+
"testing"
|
|
10
|
+
],
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"author": "Qameta Software",
|
|
13
|
+
"repository": "https://github.com/allure-framework/allure3",
|
|
14
|
+
"files": [
|
|
15
|
+
"./dist"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "run clean && tsc --project ./tsconfig.json",
|
|
26
|
+
"clean": "rimraf ./dist",
|
|
27
|
+
"test": "rimraf ./out && vitest run",
|
|
28
|
+
"lint": "oxlint --import-plugin src test",
|
|
29
|
+
"lint:fix": "oxlint --import-plugin --fix src test"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@allurereport/core-api": "3.13.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^20",
|
|
36
|
+
"@vitest/runner": "^2",
|
|
37
|
+
"@vitest/snapshot": "^2",
|
|
38
|
+
"allure-vitest": "^3",
|
|
39
|
+
"rimraf": "^6",
|
|
40
|
+
"typescript": "^5",
|
|
41
|
+
"vitest": "^4"
|
|
42
|
+
}
|
|
43
|
+
}
|