release-source.mjs 1.2 KB

12345678910111213141516171819202122
  1. export const DEFAULT_RELEASE_SOURCE = 'https://github.com/Lsamien/hermes-yaoyao.git'
  2. /** Only the former official repository is migrated; private forks stay private. */
  3. export function normalizeReleaseSource(value) {
  4. const source = value?.trim()
  5. if (!source) return DEFAULT_RELEASE_SOURCE
  6. if (/^git@git\.samien\.cn:samien\/hermes-yaoyao(?:\.git)?\/?$/.test(source)) return DEFAULT_RELEASE_SOURCE
  7. try {
  8. const url = new URL(source)
  9. const path = url.pathname.replace(/\/$/, '').replace(/\.git$/, '')
  10. if (!url.username && !url.password && !url.search && !url.hash
  11. && ['https:', 'http:', 'ssh:'].includes(url.protocol)
  12. && ['git.samien.cn', '192.168.153.8:3000'].includes(url.host)
  13. && path === '/samien/hermes-yaoyao') return DEFAULT_RELEASE_SOURCE
  14. if (url.protocol === 'https:' && url.hostname === 'github.com' && !url.port
  15. && !url.username && !url.password && !url.search && !url.hash && /^\/[\w.-]+\/[\w.-]+$/.test(path)) {
  16. const normalized = `https://github.com${path}.git`
  17. return normalized.toLowerCase() === DEFAULT_RELEASE_SOURCE.toLowerCase() ? DEFAULT_RELEASE_SOURCE : normalized
  18. }
  19. } catch { /* Custom SSH sources retain their existing Git transport. */ }
  20. return source
  21. }