fix(plugins/languages): support for private repositories (#1579)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user