@argos-ci/core 1.5.0 → 1.5.2
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/index.mjs +24 -10
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -118,14 +118,18 @@ const debugTimeEnd = (arg)=>{
|
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
121
|
+
* Get a pull request from a head sha.
|
|
122
|
+
* Fetch the last 30 pull requests sorted by updated date
|
|
123
|
+
* then try to find the one that matches the head sha.
|
|
124
|
+
* If no pull request is found, return null.
|
|
123
125
|
*/ async function getPullRequestFromHeadSha({ env }, sha) {
|
|
124
126
|
debug("Fetching pull request number from head sha", sha);
|
|
125
127
|
if (!env.GITHUB_REPOSITORY) {
|
|
126
128
|
throw new Error("GITHUB_REPOSITORY is missing");
|
|
127
129
|
}
|
|
128
130
|
if (!env.GITHUB_TOKEN) {
|
|
131
|
+
// For security reasons, people doesn't want to expose their GITHUB_TOKEN
|
|
132
|
+
// That's why we allow to disable this warning.
|
|
129
133
|
if (!env.DISABLE_GITHUB_TOKEN_WARNING) {
|
|
130
134
|
console.log(`
|
|
131
135
|
Running argos from a "deployment_status" event requires a GITHUB_TOKEN.
|
|
@@ -141,7 +145,10 @@ To disable this warning, add \`DISABLE_GITHUB_TOKEN_WARNING: true\` as environme
|
|
|
141
145
|
try {
|
|
142
146
|
const result = await axios.get(`https://api.github.com/repos/${env.GITHUB_REPOSITORY}/pulls`, {
|
|
143
147
|
params: {
|
|
144
|
-
|
|
148
|
+
state: "open",
|
|
149
|
+
sort: "updated",
|
|
150
|
+
per_page: 30,
|
|
151
|
+
page: 1
|
|
145
152
|
},
|
|
146
153
|
headers: {
|
|
147
154
|
Accept: "application/vnd.github+json",
|
|
@@ -153,9 +160,13 @@ To disable this warning, add \`DISABLE_GITHUB_TOKEN_WARNING: true\` as environme
|
|
|
153
160
|
debug("Aborting because no pull request found");
|
|
154
161
|
return null;
|
|
155
162
|
}
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const matchingPr = result.data.find((pr)=>pr.head.sha === sha);
|
|
164
|
+
if (matchingPr) {
|
|
165
|
+
debug("Pull request found", matchingPr);
|
|
166
|
+
return matchingPr;
|
|
167
|
+
}
|
|
168
|
+
debug("Aborting because no pull request found");
|
|
169
|
+
return null;
|
|
159
170
|
} catch (error) {
|
|
160
171
|
debug("Error while fetching pull request from head sha", error);
|
|
161
172
|
return null;
|
|
@@ -166,11 +177,11 @@ const getBranch = ({ env })=>{
|
|
|
166
177
|
return env.GITHUB_HEAD_REF;
|
|
167
178
|
}
|
|
168
179
|
const branchRegex = /refs\/heads\/(.*)/;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return matches[1];
|
|
180
|
+
if (!env.GITHUB_REF) {
|
|
181
|
+
return null;
|
|
172
182
|
}
|
|
173
|
-
|
|
183
|
+
const matches = branchRegex.exec(env.GITHUB_REF);
|
|
184
|
+
return (matches === null || matches === void 0 ? void 0 : matches[1]) ?? null;
|
|
174
185
|
};
|
|
175
186
|
const getRepository$1 = ({ env })=>{
|
|
176
187
|
if (!env.GITHUB_REPOSITORY) return null;
|
|
@@ -206,11 +217,14 @@ const service$4 = {
|
|
|
206
217
|
// If the job is triggered by from a "deployment" or a "deployment_status"
|
|
207
218
|
if (payload === null || payload === void 0 ? void 0 : payload.deployment) {
|
|
208
219
|
debug("Deployment event detected");
|
|
220
|
+
// Try to find a relevant pull request for the sha
|
|
209
221
|
const pullRequest = await getPullRequestFromHeadSha({
|
|
210
222
|
env
|
|
211
223
|
}, sha);
|
|
212
224
|
return {
|
|
213
225
|
...commonConfig,
|
|
226
|
+
// If no pull request is found, we fallback to the deployment environment as branch name
|
|
227
|
+
// Branch name is required to create a build but has no real impact on the build.
|
|
214
228
|
branch: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head.ref) || payload.deployment.environment || null,
|
|
215
229
|
prNumber: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.number) || null,
|
|
216
230
|
prHeadCommit: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head.sha) || null
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/core",
|
|
3
3
|
"description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"build": "rollup -c",
|
|
60
60
|
"e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "47e813466b9224cb428eb44ee4d4d450f737763e"
|
|
63
63
|
}
|