- portable UTF-8 base64 helpers (Hermes-safe), used for file round-trips - endpoints: updateFileContents, createFileContents, createPull - hooks: useCommitFile (invalidates repo cache), useCreatePull - FileEdit screen: native monospace editor, dirty/discard, branch picker, commit-to-new-branch, protected-branch handling, post-commit PR creation; stale-SHA 409 surfaces as a conflict message - settings: editor URL template; repo overview 'Open in editor' (no token) - tests: base64 round-trips (accents/emoji), editor URL expansion
27 lines
826 B
TypeScript
27 lines
826 B
TypeScript
/**
|
|
* Expands the user's editor/IDE URL template for the repository action.
|
|
*
|
|
* The template is opened with `Linking.openURL` only — the API token is never
|
|
* part of the template or the resulting URL, so IDE auth stays separate.
|
|
*/
|
|
|
|
export interface EditorUrlParts {
|
|
owner: string;
|
|
name: string;
|
|
cloneUrl?: string;
|
|
htmlUrl?: string;
|
|
}
|
|
|
|
/** Replaces `{owner}`, `{repo}`, `{cloneUrl}` and `{htmlUrl}`, URI-encoding each value. */
|
|
export function buildEditorUrl(template: string, parts: EditorUrlParts): string {
|
|
return template
|
|
.split('{owner}')
|
|
.join(encodeURIComponent(parts.owner))
|
|
.split('{repo}')
|
|
.join(encodeURIComponent(parts.name))
|
|
.split('{cloneUrl}')
|
|
.join(encodeURIComponent(parts.cloneUrl ?? ''))
|
|
.split('{htmlUrl}')
|
|
.join(encodeURIComponent(parts.htmlUrl ?? ''));
|
|
}
|