johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
// What the pages say of shared steps: where each is, what it asks for,
// and the lines a workflow uses one with.
import type { AtIdentifierString, AtUriString } from '@atproto/lex';
import type { StepViewDetailed } from '#lib/lexicons/dev/knotless/defs.ts';
import { plural, urlPath } from '#lib/format.ts';
/** The directory of steps: everyone's, or those of `owner`'s repository `name`. */
export const stepsHref = (owner?: string, name?: string) =>
owner && name ? `/steps?${new URLSearchParams({ repo: `${owner}/${name}` })}` : '/steps';
/** The record of `owner`'s repository `name`, as the step queries name it. */
export const repoUri = (owner: string, name: string): AtUriString =>
`at://${owner as AtIdentifierString}/dev.knotless.repo/${name}`;
/** The page of the step `step` in `owner`'s repository `name`. */
export const stepHref = (owner: string, name: string, step: string) =>
`/steps/${urlPath(owner)}/${urlPath(name)}/${urlPath(step)}`;
/** The step a release's package is, `@step/<name>`, if it is one. */
export const stepOf = (pkg: string) => /^@step\/([A-Za-z0-9_-]{1,64})$/.exec(pkg)?.[1];
/** What a step asks to be given, in a few words. */
export const asksFor = (secrets: number) =>
secrets ? `Asks for ${plural(secrets, 'secret', 'secrets')}` : 'No secrets';
/**
* A workflow step that uses `s` at its latest major version, its
* required inputs left to fill in and the secrets it asks for passed on,
* as YAML to paste under `steps:`.
*/
export function usesLines(s: StepViewDetailed): string {
const lines = [`- uses: ${s.uses}`];
const required = s.inputs.filter((i) => i.required && i.default === undefined);
if (required.length) lines.push(' with:', ...required.map((i) => ` ${i.name}: ""`));
if (s.secrets.length) lines.push(` secrets: [${s.secrets.map((x) => x.name).join(', ')}]`);
return lines.join('\n');
}