[validate-next-docs] declare how github urls are determined

This commit is contained in:
spalger 2023-02-10 10:54:11 -06:00
parent 648786e532
commit fe93e71412
No known key found for this signature in database

View file

@ -24,13 +24,14 @@ function lines(read: NodeJS.ReadableStream) {
}); });
} }
function getGithubBase() { function getGithubBase(log: ToolingLog) {
try { try {
const originUrl = execa.sync('git', ['remote', 'get-url', 'origin'], { const originUrl = execa.sync('git', ['remote', 'get-url', 'origin'], {
encoding: 'utf8', encoding: 'utf8',
}).stdout; }).stdout;
if (originUrl.startsWith('git@')) { if (originUrl.startsWith('git@')) {
log.warning('using ssh urls for Github repos');
return `git@github.com:`; return `git@github.com:`;
} }
} catch { } catch {
@ -38,9 +39,11 @@ function getGithubBase() {
} }
if (process.env.GITHUB_TOKEN) { if (process.env.GITHUB_TOKEN) {
return `https://${process.env.GITHUB_TOKEN}@github.com/`; log.warning('using https urls for Github repos (with token)');
return `https://token:${process.env.GITHUB_TOKEN}@github.com/`;
} }
log.warning('using https urls for Github repos');
return `https://github.com/`; return `https://github.com/`;
} }
@ -146,10 +149,12 @@ export class Repo {
} }
export class Repos { export class Repos {
githubBase = getGithubBase(); githubBase: string;
repoDir = Path.resolve(Os.userInfo().homedir, '.cache/next-docs/repos'); repoDir = Path.resolve(Os.userInfo().homedir, '.cache/next-docs/repos');
constructor(private readonly log: ToolingLog) {} constructor(private readonly log: ToolingLog) {
this.githubBase = getGithubBase(this.log);
}
async init(repoName: string) { async init(repoName: string) {
const repo = new Repo( const repo = new Repo(