bdy 1.14.1-dev → 1.14.2-dev

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,241 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBranchName = getBranchName;
7
- exports.getCommitHash = getCommitHash;
8
- exports.getCiAndGitInfo = getCiAndGitInfo;
9
- exports.logCiInfo = logCiInfo;
10
- const promises_1 = __importDefault(require("node:fs/promises"));
11
- const exec_1 = require("./exec");
12
- const ciInfo_1 = require("../types/ciInfo");
13
- const output_1 = __importDefault(require("../output"));
14
- const texts_1 = require("../texts");
15
- async function getGithubPullRequestCommit() {
16
- const payloadPath = process.env.GITHUB_EVENT_PATH;
17
- if (!payloadPath) {
18
- output_1.default.warning(texts_1.ERR_GITHUB_EVENT_PATH_NOT_FOUND);
19
- return process.env.GITHUB_SHA;
20
- }
21
- try {
22
- await promises_1.default.access(payloadPath);
23
- }
24
- catch (error) {
25
- output_1.default.warning((0, texts_1.ERR_MISSING_FILE_WITH_HEAD_COMMIT)(payloadPath, JSON.stringify(error)));
26
- return process.env.GITHUB_SHA;
27
- }
28
- let payload;
29
- try {
30
- const payloadFile = await promises_1.default.readFile(payloadPath);
31
- payload = JSON.parse(payloadFile.toString());
32
- }
33
- catch (error) {
34
- output_1.default.warning((0, texts_1.ERR_READING_FILE_WITH_HEAD_COMMIT)(payloadPath, JSON.stringify(error)));
35
- return process.env.GITHUB_SHA;
36
- }
37
- if (!payload?.pull_request) {
38
- output_1.default.warning(texts_1.ERR_MISSING_HEAD_COMMIT_IN_FILE);
39
- return process.env.GITHUB_SHA;
40
- }
41
- return payload.pull_request.head.sha;
42
- }
43
- async function getBranchName(optional) {
44
- let branch = '';
45
- try {
46
- branch = await (0, exec_1.gitExec)(['rev-parse', '--abbrev-ref', 'HEAD']);
47
- }
48
- catch (error) {
49
- if (!optional) {
50
- output_1.default.warning((0, texts_1.ERR_GETTING_BRANCH_NAME)(JSON.stringify(error)));
51
- }
52
- }
53
- branch = branch.trim();
54
- if (!branch) {
55
- if (!optional) {
56
- output_1.default.warning(texts_1.ERR_INVALID_BRANCH_NAME);
57
- }
58
- return;
59
- }
60
- return branch?.trim();
61
- }
62
- async function getCommitHash(optional) {
63
- let commit = '';
64
- try {
65
- commit = await (0, exec_1.gitExec)(['rev-parse', '--verify', 'HEAD']);
66
- }
67
- catch (error) {
68
- if (!optional) {
69
- output_1.default.warning((0, texts_1.ERR_GETTING_COMMIT_HASH)(JSON.stringify(error)));
70
- }
71
- }
72
- commit = commit.trim();
73
- if (!commit || commit.length !== 40) {
74
- if (!optional) {
75
- output_1.default.warning((0, texts_1.ERR_INVALID_COMMIT_HASH)(commit));
76
- }
77
- return;
78
- }
79
- return commit;
80
- }
81
- async function getBaseCommit(baseBranch, headBranch, requiredOriginPrefix) {
82
- if (!baseBranch) {
83
- output_1.default.warning(texts_1.ERR_BASE_BRANCH_NOT_DEFINED);
84
- return;
85
- }
86
- if (!headBranch) {
87
- output_1.default.warning(texts_1.ERR_HEAD_BRANCH_NOT_DEFINED);
88
- return;
89
- }
90
- let commit = '';
91
- try {
92
- const preparedBranch = requiredOriginPrefix && !headBranch.includes('origin/')
93
- ? `origin/${headBranch}`
94
- : headBranch;
95
- const preparedBaseBranch = requiredOriginPrefix && !baseBranch.includes('origin/')
96
- ? `origin/${baseBranch}`
97
- : baseBranch;
98
- commit = await (0, exec_1.gitExec)(['merge-base', preparedBranch, preparedBaseBranch]);
99
- }
100
- catch (error) {
101
- output_1.default.warning((0, texts_1.ERR_GETTING_BASE_COMMIT)(baseBranch, headBranch, JSON.stringify(error)));
102
- }
103
- commit = commit.trim();
104
- if (!commit || commit.length !== 40) {
105
- output_1.default.warning((0, texts_1.ERR_INVALID_COMMIT_HASH)(commit));
106
- return;
107
- }
108
- return commit;
109
- }
110
- async function getCommitDetails(commitHash) {
111
- if (commitHash) {
112
- try {
113
- const commitDetails = await (0, exec_1.gitExec)([
114
- 'show',
115
- '--no-patch',
116
- '--pretty=%an%n%ae%n%ct%n%B',
117
- commitHash,
118
- ]);
119
- const [authorName, authorEmail, authorDate, message] = commitDetails.split('\n');
120
- const authorDateNumber = Number(authorDate);
121
- return {
122
- authorName,
123
- authorEmail,
124
- authorDate: Number.isNaN(authorDateNumber)
125
- ? undefined
126
- : authorDateNumber,
127
- message,
128
- };
129
- }
130
- catch (error) {
131
- output_1.default.warning((0, texts_1.ERR_GETTING_COMMIT_DETAILS)(JSON.stringify(error)));
132
- }
133
- }
134
- }
135
- async function getCiAndGitInfo({ baseBranch, skipBaseCommitDiscovery, }) {
136
- const isBuddy = process.env.BUDDY === 'true';
137
- const isGithubAction = process.env.GITHUB_ACTIONS === 'true';
138
- const isCircleCI = process.env.CIRCLECI === 'true';
139
- const forceTag = process.env.SNAPSHOTS_TAG;
140
- const forceBranch = process.env.SNAPSHOTS_BRANCH;
141
- const forceCommit = process.env.SNAPSHOTS_COMMIT;
142
- const forceBaseCommit = process.env.SNAPSHOTS_BASE_COMMIT;
143
- const withoutBaseCommit = baseBranch === undefined || skipBaseCommitDiscovery;
144
- if (isBuddy) {
145
- const pullRequestNumber = Number(process.env.BUDDY_RUN_PR_NO);
146
- const isPR = !!pullRequestNumber;
147
- const branch = forceBranch ||
148
- (isPR
149
- ? process.env.BUDDY_RUN_PR_HEAD_BRANCH
150
- : process.env.BUDDY_EXECUTION_BRANCH);
151
- const tag = forceTag || process.env.BUDDY_EXECUTION_TAG;
152
- const commit = forceCommit || process.env.BUDDY_EXECUTION_REVISION;
153
- const baseCommit = withoutBaseCommit
154
- ? undefined
155
- : forceBaseCommit ||
156
- (isPR ? await getBaseCommit(baseBranch, branch, true) : undefined);
157
- const invokerId = Number(process.env.BUDDY_INVOKER_ID);
158
- const pipelineId = Number(process.env.BUDDY_PIPELINE_ID);
159
- const actionId = Number(process.env.BUDDY_ACTION_ID);
160
- const executionId = process.env.BUDDY_RUN_HASH;
161
- return {
162
- ci: ciInfo_1.CI.BUDDY,
163
- branch,
164
- tag,
165
- pullRequestNumber: isPR ? pullRequestNumber : undefined,
166
- commit,
167
- baseCommit,
168
- pipelineName: process.env.BUDDY_PIPELINE_NAME,
169
- pipelineId: Number.isNaN(pipelineId) ? undefined : pipelineId,
170
- actionId: Number.isNaN(actionId) ? undefined : actionId,
171
- executionId,
172
- invokerId: Number.isNaN(invokerId) ? undefined : invokerId,
173
- commitDetails: await getCommitDetails(commit),
174
- };
175
- }
176
- if (isGithubAction) {
177
- const isPR = process.env.GITHUB_EVENT_NAME === 'pull_request';
178
- const isTag = process.env.GITHUB_REF_TYPE === 'tag';
179
- const pullRequestNumber = isPR && process.env.GITHUB_REF
180
- ? Number(process.env.GITHUB_REF.split('/')[2])
181
- : undefined;
182
- const branch = forceBranch ||
183
- (isPR ? process.env.GITHUB_HEAD_REF : process.env.GITHUB_REF_NAME);
184
- const tag = forceTag || (isTag ? process.env.GITHUB_REF_NAME : undefined);
185
- const commit = forceCommit ||
186
- (isPR ? await getGithubPullRequestCommit() : process.env.GITHUB_SHA);
187
- const baseCommit = withoutBaseCommit
188
- ? undefined
189
- : forceBaseCommit ||
190
- (isPR ? await getBaseCommit(baseBranch, branch, true) : undefined);
191
- return {
192
- ci: ciInfo_1.CI.GITHUB_ACTION,
193
- branch,
194
- tag,
195
- pullRequestNumber,
196
- commit,
197
- baseCommit,
198
- commitDetails: await getCommitDetails(commit),
199
- executionUrl: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
200
- };
201
- }
202
- if (isCircleCI) {
203
- const isPR = process.env.CIRCLE_PULL_REQUEST;
204
- const pullRequestNumber = isPR
205
- ? Number(process.env.CIRCLE_PR_NUMBER)
206
- : undefined;
207
- const branch = forceBranch || process.env.CIRCLE_BRANCH;
208
- const tag = forceTag || process.env.CIRCLE_TAG;
209
- const commit = forceCommit || process.env.CIRCLE_SHA1;
210
- const baseCommit = withoutBaseCommit
211
- ? undefined
212
- : forceBaseCommit ||
213
- (isPR ? await getBaseCommit(baseBranch, branch) : undefined);
214
- return {
215
- ci: ciInfo_1.CI.CIRCLE_CI,
216
- branch,
217
- tag,
218
- pullRequestNumber,
219
- commit,
220
- baseCommit,
221
- commitDetails: await getCommitDetails(commit),
222
- executionUrl: `${process.env.CIRCLE_BUILD_URL}`,
223
- };
224
- }
225
- const branch = forceBranch || (await getBranchName(withoutBaseCommit));
226
- const commit = forceCommit || (await getCommitHash(withoutBaseCommit));
227
- return {
228
- ci: ciInfo_1.CI.NONE,
229
- branch,
230
- commit,
231
- baseCommit: withoutBaseCommit
232
- ? undefined
233
- : branch && branch !== baseBranch
234
- ? forceBaseCommit || (await getBaseCommit(baseBranch, branch))
235
- : undefined,
236
- commitDetails: await getCommitDetails(commit),
237
- };
238
- }
239
- function logCiInfo(ciInfo) {
240
- output_1.default.normal((0, texts_1.TXT_CI_INFO)(ciInfo));
241
- }