-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve GitHub API handling * consolidate metadata files * fixed import regex * fix old cli metadata * Fixed cachedFetch tests * fixed shapes * add changeset * address PR feedback
- Loading branch information
Showing
37 changed files
with
418 additions
and
2,093 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@replayio/cypress": patch | ||
"@replayio/playwright": patch | ||
--- | ||
|
||
Improved resiliency to GitHub API errors when auto-populating PR-related information metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1 @@ | ||
import { defaulted, string } from "superstruct"; | ||
|
||
type Resolver = string | ((env: NodeJS.ProcessEnv) => string | undefined); | ||
|
||
const firstEnvValueOf = | ||
(...envKeys: Resolver[]) => | ||
() => | ||
envKeys.reduce<string | undefined>( | ||
(a, k) => a || (typeof k === "function" ? k(process.env) : process.env[k]), | ||
undefined | ||
); | ||
|
||
const envString = (...envKeys: Resolver[]) => defaulted(string(), firstEnvValueOf(...envKeys)); | ||
|
||
export { firstEnvValueOf, envString }; | ||
export * from "@replay-cli/shared/recording/metadata/legacy/env"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,5 @@ | ||
import { appendFileSync } from "fs"; | ||
import path from "path"; | ||
|
||
import { Options, UnstructuredMetadata } from "../types"; | ||
import { getDirectory, maybeLog } from "../utils"; | ||
|
||
import * as test from "./test"; | ||
export { sanitizeMetadata as sanitize } from "@replay-cli/shared/recording/metadata/sanitizeMetadata"; | ||
export { addMetadata as add } from "@replay-cli/shared/recording/metadata/addMetadata"; | ||
import * as source from "./source"; | ||
|
||
// Each known metadata block should have a sanitizer that will check the contents before the upload | ||
const handlers = { | ||
test: test.validate, | ||
source: source.validate, | ||
}; | ||
|
||
type AllowedKey = keyof typeof handlers; | ||
const ALLOWED_KEYS = Object.keys(handlers); | ||
|
||
function isAllowedKey(key: string): key is AllowedKey { | ||
return ALLOWED_KEYS.includes(key); | ||
} | ||
|
||
// Sanitizing arbitrary recording metadata before uploading by removing any | ||
// non-object values (allowing null) and limiting object values to known keys or | ||
// userspace keys prefixed by `x-`. | ||
async function sanitize(metadata: UnstructuredMetadata, opts: Options = {}) { | ||
const updated: UnstructuredMetadata = {}; | ||
for (const key of Object.keys(metadata)) { | ||
const value = metadata[key]; | ||
|
||
if (typeof value !== "object") { | ||
maybeLog( | ||
opts.verbose, | ||
`Ignoring metadata key "${key}". Expected an object but received ${typeof value}` | ||
); | ||
|
||
continue; | ||
} | ||
|
||
if (value === null || key.startsWith("x-")) { | ||
// passthrough null or userspace types | ||
updated[key] = value; | ||
} else if (isAllowedKey(key)) { | ||
// validate known types | ||
const validated = await handlers[key](metadata as any); | ||
Object.assign(updated, validated); | ||
} else { | ||
// and warn when dropping all other types | ||
maybeLog( | ||
opts.verbose, | ||
`Ignoring metadata key "${key}". Custom metadata blocks must be prefixed by "x-". Try "x-${key}" instead.` | ||
); | ||
} | ||
} | ||
|
||
return updated; | ||
} | ||
|
||
/** | ||
* Adds unstructured metadata to the local recordings database. | ||
* | ||
* New metadata will be merged with existing data. If the same key is used by | ||
* multiple entries, the most recent entry's value will be used. | ||
* | ||
* Metadata is not validated until the recording is uploaded so arbitrary keys | ||
* may be used here to manage recordings before upload. | ||
* | ||
* @param recordingId UUID of the recording | ||
* @param metadata Recording metadata | ||
*/ | ||
function add(recordingId: string, metadata: UnstructuredMetadata) { | ||
const entry = { | ||
id: recordingId, | ||
kind: "addMetadata", | ||
metadata, | ||
timestamp: Date.now(), | ||
}; | ||
|
||
appendFileSync(path.join(getDirectory(), "recordings.log"), `\n${JSON.stringify(entry)}\n`); | ||
} | ||
|
||
export { add, sanitize, source, test }; | ||
import * as test from "./test"; | ||
export { source, test }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.