From 995dd4a8e1f60d8f140c214cd197a15b317049ef Mon Sep 17 00:00:00 2001 From: Ilan <39036916+ilanRosenbaum@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:01:01 -0600 Subject: [PATCH] fix(plugins/languages): support for private repositories (#1579) --- source/plugins/languages/analyzer/analyzer.mjs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/plugins/languages/analyzer/analyzer.mjs b/source/plugins/languages/analyzer/analyzer.mjs index 529a367e5cf..e0042cb1dc3 100644 --- a/source/plugins/languages/analyzer/analyzer.mjs +++ b/source/plugins/languages/analyzer/analyzer.mjs @@ -4,6 +4,7 @@ import os from "os" import paths from "path" import git from "simple-git" import { filters } from "../../../app/metrics/utils.mjs" +import core from "@actions/core" /**Analyzer */ export class Analyzer { @@ -86,13 +87,19 @@ export class Analyzer { /**Clone a repository */ async clone(repository) { const {repo, branch, path} = this.parse(repository) - let url = /^https?:\/\//.test(repo) ? repo : `https://github.com/${repo}` + let token + + if (process.env.GITHUB_ACTIONS) { + token = core.getInput("token") + } + + let url = /^https?:\/\//.test(repo) ? repo : `https://${token}@github.com/${repo}` try { - this.debug(`cloning ${url} to ${path}`) + this.debug(`cloning https://github.com/${repo} to ${path}`) await fs.rm(path, {recursive: true, force: true}) await fs.mkdir(path, {recursive: true}) await git(path).clone(url, ".", ["--single-branch"]).status() - this.debug(`cloned ${url} to ${path}`) + this.debug(`cloned https://github.com/${repo} to ${path}`) if (branch) { this.debug(`switching to branch ${branch} for ${repo}`) await git(path).branch(branch) @@ -100,7 +107,7 @@ export class Analyzer { return true } catch (error) { - this.debug(`failed to clone ${url} (${error})`) + this.debug(`failed to clone https://github.com/${repo} (${error})`) this.clean(path) return false } @@ -176,4 +183,4 @@ export class Analyzer { debug(message) { return console.debug(`metrics/compute/${this.login}/plugins > languages > ${this.constructor.name.replace(/([a-z])([A-Z])/, (_, a, b) => `${a} ${b.toLocaleLowerCase()}`).toLocaleLowerCase()} > ${message}`) } -} +} \ No newline at end of file