(
ref: RepoRef,
opts: FetchOptions = {}
)
| 266 | }; |
| 267 | |
| 268 | export async function fetchRepoMeta( |
| 269 | ref: RepoRef, |
| 270 | opts: FetchOptions = {} |
| 271 | ): Promise<RepoMeta | null> { |
| 272 | switch (ref.host) { |
| 273 | case "github": { |
| 274 | const r = await fetchJSON<any>( |
| 275 | `https://api.github.com/repos/${ref.owner}/${ref.repo}`, |
| 276 | { ...opts, allow404: true } |
| 277 | ); |
| 278 | if (!r) return null; |
| 279 | return { |
| 280 | // `html_url` is the canonical location: GitHub resolves renames and |
| 281 | // transfers transparently, so this is how a moved repo is detected. |
| 282 | url: r.html_url, |
| 283 | stars: r.stargazers_count ?? 0, |
| 284 | homepage: (r.homepage ?? "").trim(), |
| 285 | license: cleanLicense(r.license?.spdx_id), |
| 286 | pushedAt: iso(r.pushed_at), |
| 287 | archived: Boolean(r.archived), |
| 288 | }; |
| 289 | } |
| 290 | case "codeberg": { |
| 291 | const r = await fetchJSON<any>( |
| 292 | `https://codeberg.org/api/v1/repos/${ref.owner}/${ref.repo}`, |
| 293 | { ...opts, allow404: true } |
| 294 | ); |
| 295 | if (!r) return null; |
| 296 | return { |
| 297 | url: r.html_url, |
| 298 | stars: r.stars_count ?? 0, |
| 299 | homepage: (r.website ?? "").trim(), |
| 300 | license: "", |
| 301 | pushedAt: iso(r.updated_at), |
| 302 | archived: Boolean(r.archived), |
| 303 | }; |
| 304 | } |
| 305 | case "gitlab": { |
| 306 | const id = encodeURIComponent(`${ref.owner}/${ref.repo}`); |
| 307 | const r = await fetchJSON<any>( |
| 308 | `https://gitlab.com/api/v4/projects/${id}?license=true`, |
| 309 | { ...opts, allow404: true } |
| 310 | ); |
| 311 | if (!r) return null; |
| 312 | return { |
| 313 | url: r.web_url, |
| 314 | stars: r.star_count ?? 0, |
| 315 | homepage: "", |
| 316 | license: cleanLicense(r.license?.key?.toUpperCase()), |
| 317 | pushedAt: iso(r.last_activity_at), |
| 318 | archived: Boolean(r.archived), |
| 319 | }; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // --------------------------------------------------------------------------- |
| 325 | // Releases |
no test coverage detected