@allurereport/ci 3.16.0 → 3.17.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.
@@ -0,0 +1 @@
1
+ export declare const applyAllureCiEnv: () => void;
package/dist/ciEnv.js ADDED
@@ -0,0 +1,18 @@
1
+ import { env } from "node:process";
2
+ export const applyAllureCiEnv = () => {
3
+ const encodedAllureCiEnv = env.ALLURE_CI_ENV;
4
+ if (!encodedAllureCiEnv) {
5
+ return;
6
+ }
7
+ try {
8
+ const decodedAllureCiEnv = JSON.parse(Buffer.from(encodedAllureCiEnv, "base64").toString("utf8"));
9
+ for (const [variableName, variableValue] of Object.entries(decodedAllureCiEnv)) {
10
+ if (variableName.startsWith("ALLURE_")) {
11
+ env[variableName] = variableValue;
12
+ }
13
+ }
14
+ }
15
+ catch {
16
+ return;
17
+ }
18
+ };
@@ -4,7 +4,7 @@ import { getEnv } from "../utils.js";
4
4
  const REF_PREFIX = "refs/";
5
5
  const BRANCH_REF_PREFIX = "refs/heads/";
6
6
  const TAG_REF_PREFIX = "refs/tags/";
7
- export const getRootURL = () => getEnv("SYSTEM_COLLECTIONURI");
7
+ export const getRootURL = () => getEnv("SYSTEM_COLLECTIONURI").replace(/\/+$/, "");
8
8
  export const getBuildID = () => getEnv("BUILD_BUILDID");
9
9
  export const getDefinitionID = () => getEnv("SYSTEM_DEFINITIONID");
10
10
  export const getProjectID = () => getEnv("SYSTEM_TEAMPROJECTID");
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path/posix";
2
2
  import { CiType, GitProvider } from "@allurereport/core-api";
3
- import { resolveGithubPullRequestNumber } from "../helpers/github.js";
3
+ import { resolveGithubPullRequestContext, resolveGithubPullRequestNumber } from "../helpers/github.js";
4
4
  import { stripRefsHeads } from "../helpers/gitProvider.js";
5
5
  import { getEnv } from "../utils.js";
6
6
  const getBaseURL = () => getEnv("GITHUB_SERVER_URL");
@@ -23,8 +23,19 @@ const getSourceBranch = () => {
23
23
  if (headRef) {
24
24
  return headRef;
25
25
  }
26
+ const pullRequestHeadRef = resolveGithubPullRequestContext()?.headRef;
27
+ if (pullRequestHeadRef) {
28
+ return pullRequestHeadRef;
29
+ }
26
30
  return isTagRef() ? "" : getBranchFromRef();
27
31
  };
32
+ const getTargetBranch = () => {
33
+ const baseRef = getEnv("GITHUB_BASE_REF");
34
+ if (baseRef) {
35
+ return baseRef;
36
+ }
37
+ return resolveGithubPullRequestContext()?.baseRef ?? "";
38
+ };
28
39
  export const github = {
29
40
  type: CiType.Github,
30
41
  get detected() {
@@ -92,7 +103,7 @@ export const github = {
92
103
  return getSourceBranch() || undefined;
93
104
  },
94
105
  get targetBranch() {
95
- return getEnv("GITHUB_BASE_REF") || undefined;
106
+ return getTargetBranch() || undefined;
96
107
  },
97
108
  get pullRequest() {
98
109
  const pullRequestId = resolveGithubPullRequestNumber();
@@ -1,2 +1,9 @@
1
+ export type GithubPullRequestContext = {
2
+ number: string;
3
+ headRef?: string;
4
+ baseRef?: string;
5
+ };
6
+ export declare const parsePullRequestContextFromEventJson: (content: string) => GithubPullRequestContext | undefined;
1
7
  export declare const parsePullRequestNumberFromEventJson: (content: string) => string;
8
+ export declare const resolveGithubPullRequestContext: () => GithubPullRequestContext | undefined;
2
9
  export declare const resolveGithubPullRequestNumber: () => string;
@@ -8,43 +8,75 @@ const normalizePullRequestNumber = (value) => {
8
8
  }
9
9
  return String(value);
10
10
  };
11
- export const parsePullRequestNumberFromEventJson = (content) => {
11
+ const nonBlank = (value) => {
12
+ const trimmed = value?.trim();
13
+ return trimmed ? trimmed : undefined;
14
+ };
15
+ const contextFromPullRequestFields = (pullRequest, fallbackNumber) => {
16
+ const number = normalizePullRequestNumber(pullRequest?.number ?? fallbackNumber);
17
+ if (!number) {
18
+ return undefined;
19
+ }
20
+ return {
21
+ number,
22
+ headRef: nonBlank(pullRequest?.head?.ref),
23
+ baseRef: nonBlank(pullRequest?.base?.ref),
24
+ };
25
+ };
26
+ export const parsePullRequestContextFromEventJson = (content) => {
12
27
  try {
13
28
  const event = JSON.parse(content);
14
- return normalizePullRequestNumber(event?.number ?? event?.pull_request?.number);
29
+ const fromPullRequest = contextFromPullRequestFields(event.pull_request, event.number);
30
+ if (fromPullRequest) {
31
+ return fromPullRequest;
32
+ }
33
+ const workflowPullRequests = event.workflow_run?.pull_requests;
34
+ if (!Array.isArray(workflowPullRequests) || workflowPullRequests.length === 0) {
35
+ return undefined;
36
+ }
37
+ return contextFromPullRequestFields(workflowPullRequests[0]);
15
38
  }
16
39
  catch {
17
- return "";
40
+ return undefined;
18
41
  }
19
42
  };
20
- const readPullRequestNumberFromEventPath = () => {
43
+ export const parsePullRequestNumberFromEventJson = (content) => {
44
+ return parsePullRequestContextFromEventJson(content)?.number ?? "";
45
+ };
46
+ const readPullRequestContextFromEventPath = () => {
21
47
  const eventPath = getEnv("GITHUB_EVENT_PATH");
22
48
  if (!eventPath) {
23
- return "";
49
+ return undefined;
24
50
  }
25
51
  try {
26
52
  const content = readFileSync(eventPath, "utf-8");
27
- return parsePullRequestNumberFromEventJson(content);
53
+ return parsePullRequestContextFromEventJson(content);
28
54
  }
29
55
  catch {
30
- return "";
56
+ return undefined;
31
57
  }
32
58
  };
33
- export const resolveGithubPullRequestNumber = () => {
59
+ export const resolveGithubPullRequestContext = () => {
34
60
  const refName = getEnv("GITHUB_REF_NAME") || "";
35
61
  const refNameMatch = refName.match(PULL_REQUEST_REF_NAME_RE);
36
62
  if (refNameMatch) {
37
- return refNameMatch[1];
63
+ return {
64
+ number: refNameMatch[1],
65
+ headRef: nonBlank(getEnv("GITHUB_HEAD_REF")),
66
+ baseRef: nonBlank(getEnv("GITHUB_BASE_REF")),
67
+ };
38
68
  }
39
69
  const githubRef = getEnv("GITHUB_REF") || "";
40
70
  const mergeRefMatch = githubRef.match(PULL_REQUEST_MERGE_REF_RE);
41
71
  if (mergeRefMatch) {
42
- return mergeRefMatch[1];
72
+ return {
73
+ number: mergeRefMatch[1],
74
+ headRef: nonBlank(getEnv("GITHUB_HEAD_REF")),
75
+ baseRef: nonBlank(getEnv("GITHUB_BASE_REF")),
76
+ };
43
77
  }
44
- const headRef = getEnv("GITHUB_HEAD_REF");
45
- const baseRef = getEnv("GITHUB_BASE_REF");
46
- if (headRef && baseRef) {
47
- return readPullRequestNumberFromEventPath();
48
- }
49
- return "";
78
+ return readPullRequestContextFromEventPath();
79
+ };
80
+ export const resolveGithubPullRequestNumber = () => {
81
+ return resolveGithubPullRequestContext()?.number ?? "";
50
82
  };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export { applyAllureCiEnv } from "./ciEnv.js";
1
2
  export { detect } from "./detect.js";
2
3
  export { isLocalCiDescriptor } from "./detectors/local.js";
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export { applyAllureCiEnv } from "./ciEnv.js";
1
2
  export { detect } from "./detect.js";
2
3
  export { isLocalCiDescriptor } from "./detectors/local.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/ci",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Utilities set to get useful report data from different CI",
5
5
  "keywords": [
6
6
  "allure",
@@ -30,7 +30,7 @@
30
30
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
31
31
  },
32
32
  "dependencies": {
33
- "@allurereport/core-api": "3.16.0"
33
+ "@allurereport/core-api": "3.17.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^20",