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 paths from "path"
|
||||||
import git from "simple-git"
|
import git from "simple-git"
|
||||||
import { filters } from "../../../app/metrics/utils.mjs"
|
import { filters } from "../../../app/metrics/utils.mjs"
|
||||||
|
import core from "@actions/core"
|
||||||
|
|
||||||
/**Analyzer */
|
/**Analyzer */
|
||||||
export class Analyzer {
|
export class Analyzer {
|
||||||
@@ -86,13 +87,19 @@ export class Analyzer {
|
|||||||
/**Clone a repository */
|
/**Clone a repository */
|
||||||
async clone(repository) {
|
async clone(repository) {
|
||||||
const {repo, branch, path} = this.parse(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 {
|
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.rm(path, {recursive: true, force: true})
|
||||||
await fs.mkdir(path, {recursive: true})
|
await fs.mkdir(path, {recursive: true})
|
||||||
await git(path).clone(url, ".", ["--single-branch"]).status()
|
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) {
|
if (branch) {
|
||||||
this.debug(`switching to branch ${branch} for ${repo}`)
|
this.debug(`switching to branch ${branch} for ${repo}`)
|
||||||
await git(path).branch(branch)
|
await git(path).branch(branch)
|
||||||
@@ -100,7 +107,7 @@ export class Analyzer {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
this.debug(`failed to clone ${url} (${error})`)
|
this.debug(`failed to clone https://github.com/${repo} (${error})`)
|
||||||
this.clean(path)
|
this.clean(path)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -176,4 +183,4 @@ export class Analyzer {
|
|||||||
debug(message) {
|
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}`)
|
return console.debug(`metrics/compute/${this.login}/plugins > languages > ${this.constructor.name.replace(/([a-z])([A-Z])/, (_, a, b) => `${a} ${b.toLocaleLowerCase()}`).toLocaleLowerCase()} > ${message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user