release-source.mjs 1.4 KB

1234567891011121314151617181920212223
  1. export const DEFAULT_RELEASE_SOURCE = 'https://github.com/Lsamien/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@github\.com:Lsamien\/(?:hermes-yaoyao|yaoyao)(?:\.git)?\/?$/i.test(source)) return DEFAULT_RELEASE_SOURCE
  7. if (/^git@git\.samien\.cn:samien\/hermes-yaoyao(?:\.git)?\/?$/.test(source)) return DEFAULT_RELEASE_SOURCE
  8. try {
  9. const url = new URL(source)
  10. const path = url.pathname.replace(/\/$/, '').replace(/\.git$/, '')
  11. if (!url.username && !url.password && !url.search && !url.hash
  12. && ['https:', 'http:', 'ssh:'].includes(url.protocol)
  13. && ['git.samien.cn', '192.168.153.8:3000'].includes(url.host)
  14. && ['/samien/hermes-yaoyao', '/samien/yaoyao'].includes(path)) return DEFAULT_RELEASE_SOURCE
  15. if (url.protocol === 'https:' && url.hostname === 'github.com' && !url.port
  16. && !url.username && !url.password && !url.search && !url.hash && /^\/[\w.-]+\/[\w.-]+$/.test(path)) {
  17. const normalized = /^\/Lsamien\/(?:hermes-yaoyao|yaoyao)$/i.test(path) ? DEFAULT_RELEASE_SOURCE : `https://github.com${path}.git`
  18. return normalized.toLowerCase() === DEFAULT_RELEASE_SOURCE.toLowerCase() ? DEFAULT_RELEASE_SOURCE : normalized
  19. }
  20. } catch { /* Custom SSH sources retain their existing Git transport. */ }
  21. return source
  22. }