All files / src/aggregator/infra github-urls.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 4/4
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                  11x     11x                 1345x                   1273x                   4x                   68x    
// SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
 
/**
 * @module Aggregator/Infra/GithubUrls
 * @description Single source of truth for the `Hack23/euparliamentmonitor`
 * repository slug and helpers that build canonical GitHub URLs (blob, raw,
 * tree). Centralising the constants here removes the previous duplication
 * between `clean-artifact.ts` (which historically owned `githubBlobUrl` /
 * `githubRawUrl`) and `article-generator.ts` (which embedded the same slug
 * literally inside an `isBasedOn` template string).
 *
 * Every consumer should import from here; the legacy entry points in
 * `clean-artifact.ts` are preserved as thin re-export shims for back-compat.
 */
 
/** Hack23 repo slug used when building blob/raw/tree URLs. */
export const REPO_SLUG = 'Hack23/euparliamentmonitor';
 
/** Default branch used in generated URLs. */
export const REPO_BRANCH = 'main';
 
/**
 * Normalise a repo-relative path to POSIX form before embedding it in a URL.
 *
 * @param relPath - Repo-relative file path (POSIX or Windows separators)
 * @returns Same path with `\` replaced by `/`
 */
function toPosix(relPath: string): string {
  return relPath.replace(/\\/g, '/');
}
 
/**
 * Build a GitHub blob URL for a repo-relative file path.
 *
 * @param relPath - Repo-relative file path
 * @returns Absolute `https://github.com/.../blob/<branch>/...` URL
 */
export function blobUrl(relPath: string): string {
  return `https://github.com/${REPO_SLUG}/blob/${REPO_BRANCH}/${toPosix(relPath)}`;
}
 
/**
 * Build a `raw.githubusercontent.com` URL for a repo-relative file path.
 *
 * @param relPath - Repo-relative file path
 * @returns Absolute raw-content URL
 */
export function rawUrl(relPath: string): string {
  return `https://raw.githubusercontent.com/${REPO_SLUG}/${REPO_BRANCH}/${toPosix(relPath)}`;
}
 
/**
 * Build a GitHub tree URL for a repo-relative directory path.
 *
 * @param relPath - Repo-relative directory path (no trailing slash needed)
 * @returns Absolute `https://github.com/.../tree/<branch>/...` URL
 */
export function treeUrl(relPath: string): string {
  return `https://github.com/${REPO_SLUG}/tree/${REPO_BRANCH}/${toPosix(relPath)}`;
}