@argos-ci/core
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -79,2 +79,9 @@ import * as _argos_ci_util from '@argos-ci/util'; | ||
metadata?: BuildMetadata; | ||
/** | ||
* Preview URL configuration. | ||
* Accepts a base URL or a function that receives the URL and returns the preview URL. | ||
*/ | ||
previewUrl?: { | ||
baseUrl: string; | ||
} | ((url: string) => string); | ||
} | ||
@@ -88,3 +95,3 @@ /** | ||
number: number; | ||
status: ("accepted" | "rejected") | ("stable" | "diffDetected") | ("expired" | "pending" | "progress" | "error" | "aborted"); | ||
status: ("accepted" | "rejected") | ("no-changes" | "changes-detected") | ("expired" | "pending" | "progress" | "error" | "aborted"); | ||
url: string; | ||
@@ -129,3 +136,3 @@ notification: { | ||
/** @description The status of the build */ | ||
status: ("accepted" | "rejected") | ("stable" | "diffDetected") | ("expired" | "pending" | "progress" | "error" | "aborted"); | ||
status: ("accepted" | "rejected") | ("no-changes" | "changes-detected") | ("expired" | "pending" | "progress" | "error" | "aborted"); | ||
/** | ||
@@ -174,2 +181,3 @@ * Format: uri | ||
url?: string; | ||
previewUrl?: string; | ||
viewport?: { | ||
@@ -281,2 +289,3 @@ width: number; | ||
threshold: number | null; | ||
previewBaseUrl: string | null; | ||
} | ||
@@ -283,0 +292,0 @@ declare function readConfig(options?: Partial<Config>): Promise<Config>; |
// src/upload.ts | ||
import { | ||
createClient, | ||
throwAPIError | ||
} from "@argos-ci/api-client"; | ||
import { createClient, throwAPIError } from "@argos-ci/api-client"; | ||
@@ -254,8 +251,14 @@ // src/config.ts | ||
function getRepositoryFromContext({ env }) { | ||
if (!env.GITHUB_REPOSITORY) return null; | ||
if (!env.GITHUB_REPOSITORY) { | ||
return null; | ||
} | ||
return env.GITHUB_REPOSITORY.split("/")[1] || null; | ||
} | ||
function readEventPayload({ env }) { | ||
if (!env.GITHUB_EVENT_PATH) return null; | ||
if (!existsSync(env.GITHUB_EVENT_PATH)) return null; | ||
if (!env.GITHUB_EVENT_PATH) { | ||
return null; | ||
} | ||
if (!existsSync(env.GITHUB_EVENT_PATH)) { | ||
return null; | ||
} | ||
return JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf-8")); | ||
@@ -294,3 +297,3 @@ } | ||
runAttempt: env.GITHUB_RUN_ATTEMPT ? Number(env.GITHUB_RUN_ATTEMPT) : null, | ||
nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null, | ||
nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}`, | ||
branch: getBranchFromContext(context) || pullRequest?.head.ref || (payload ? getBranchFromPayload(payload) : null) || null, | ||
@@ -342,11 +345,17 @@ prNumber: pullRequest?.number || null, | ||
var getOwner = ({ env }) => { | ||
if (!env.TRAVIS_REPO_SLUG) return null; | ||
if (!env.TRAVIS_REPO_SLUG) { | ||
return null; | ||
} | ||
return env.TRAVIS_REPO_SLUG.split("/")[0] || null; | ||
}; | ||
var getRepository = ({ env }) => { | ||
if (!env.TRAVIS_REPO_SLUG) return null; | ||
if (!env.TRAVIS_REPO_SLUG) { | ||
return null; | ||
} | ||
return env.TRAVIS_REPO_SLUG.split("/")[1] || null; | ||
}; | ||
var getPrNumber3 = ({ env }) => { | ||
if (env.TRAVIS_PULL_REQUEST) return Number(env.TRAVIS_PULL_REQUEST); | ||
if (env.TRAVIS_PULL_REQUEST) { | ||
return Number(env.TRAVIS_PULL_REQUEST); | ||
} | ||
return null; | ||
@@ -482,3 +491,3 @@ }; | ||
var mustBeApiBaseUrl = (value) => { | ||
const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/; | ||
const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/; | ||
if (!URL_REGEX.test(value)) { | ||
@@ -635,2 +644,8 @@ throw new Error("Invalid Argos API base URL"); | ||
nullable: true | ||
}, | ||
previewBaseUrl: { | ||
env: "ARGOS_PREVIEW_BASE_URL", | ||
format: String, | ||
default: null, | ||
nullable: true | ||
} | ||
@@ -667,3 +682,4 @@ }; | ||
mode: options.mode || config.get("mode") || null, | ||
ciProvider: ciEnv?.key || null | ||
ciProvider: ciEnv?.key || null, | ||
previewBaseUrl: config.get("previewBaseUrl") || null | ||
}); | ||
@@ -826,4 +842,4 @@ config.validate(); | ||
for (let x = 0; x < Math.ceil(collection.length / size); x++) { | ||
let start = x * size; | ||
let end = start + size; | ||
const start = x * size; | ||
const end = start + size; | ||
result.push(collection.slice(start, end)); | ||
@@ -885,2 +901,12 @@ } | ||
} | ||
function formatPreviewUrl(url, formatter) { | ||
if (typeof formatter === "function") { | ||
return formatter(url); | ||
} | ||
const urlObj = new URL(url); | ||
return new URL( | ||
urlObj.pathname + urlObj.search + urlObj.hash, | ||
formatter.baseUrl | ||
).href; | ||
} | ||
async function upload2(params) { | ||
@@ -892,2 +918,3 @@ debug("Starting upload with params", params); | ||
]); | ||
const previewUrlFormatter = params.previewUrl ?? (config.previewBaseUrl ? { baseUrl: config.previewBaseUrl } : void 0); | ||
const files = params.files ?? ["**/*.{png,jpg,jpeg}"]; | ||
@@ -920,2 +947,8 @@ debug("Using config and files", config, files); | ||
delete metadata.transient; | ||
if (metadata.url && previewUrlFormatter) { | ||
metadata.previewUrl = formatPreviewUrl( | ||
metadata.url, | ||
previewUrlFormatter | ||
); | ||
} | ||
} | ||
@@ -922,0 +955,0 @@ return { |
{ | ||
"name": "@argos-ci/core", | ||
"description": "Node.js SDK for visual testing with Argos.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"type": "module", | ||
@@ -43,4 +43,4 @@ "main": "./dist/index.cjs", | ||
"dependencies": { | ||
"@argos-ci/api-client": "0.7.2", | ||
"@argos-ci/util": "2.2.2", | ||
"@argos-ci/api-client": "0.8.0", | ||
"@argos-ci/util": "2.3.0", | ||
"axios": "^1.7.9", | ||
@@ -64,3 +64,3 @@ "convict": "^6.2.4", | ||
}, | ||
"gitHead": "0c91306ae0cb8bec5ef93db79565635e405086f7" | ||
"gitHead": "8d46b4d4fc2b59b4fe93bac6fda02fb18440f935" | ||
} |
43573
1385
79
2
37
+ Added@argos-ci/api-client@0.8.0(transitive)
+ Added@argos-ci/util@2.3.0(transitive)
- Removed@argos-ci/api-client@0.7.2(transitive)
- Removed@argos-ci/util@2.2.2(transitive)
Updated@argos-ci/api-client@0.8.0
Updated@argos-ci/util@2.3.0