Files
gitea-native/src/core/utils/editor-url.ts
T
JustZoe101 c9dd49446a feat(phase4): Quick Edit, Contents API commit flow, editor workspace
- 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
2026-10-09 17:19:06 +02:00

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 ?? ''));
}