Skip to content

Commit 995dd4a

Browse files
fix(plugins/languages): support for private repositories (#1579)
1 parent a53a585 commit 995dd4a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

source/plugins/languages/analyzer/analyzer.mjs

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os from "os"
44
import paths from "path"
55
import git from "simple-git"
66
import { filters } from "../../../app/metrics/utils.mjs"
7+
import core from "@actions/core"
78

89
/**Analyzer */
910
export class Analyzer {
@@ -86,21 +87,27 @@ export class Analyzer {
8687
/**Clone a repository */
8788
async clone(repository) {
8889
const {repo, branch, path} = this.parse(repository)
89-
let url = /^https?:\/\//.test(repo) ? repo : `https://github.com/${repo}`
90+
let token
91+
92+
if (process.env.GITHUB_ACTIONS) {
93+
token = core.getInput("token")
94+
}
95+
96+
let url = /^https?:\/\//.test(repo) ? repo : `https://${token}@github.com/${repo}`
9097
try {
91-
this.debug(`cloning ${url} to ${path}`)
98+
this.debug(`cloning https://github.com/${repo} to ${path}`)
9299
await fs.rm(path, {recursive: true, force: true})
93100
await fs.mkdir(path, {recursive: true})
94101
await git(path).clone(url, ".", ["--single-branch"]).status()
95-
this.debug(`cloned ${url} to ${path}`)
102+
this.debug(`cloned https://github.com/${repo} to ${path}`)
96103
if (branch) {
97104
this.debug(`switching to branch ${branch} for ${repo}`)
98105
await git(path).branch(branch)
99106
}
100107
return true
101108
}
102109
catch (error) {
103-
this.debug(`failed to clone ${url} (${error})`)
110+
this.debug(`failed to clone https://github.com/${repo} (${error})`)
104111
this.clean(path)
105112
return false
106113
}
@@ -176,4 +183,4 @@ export class Analyzer {
176183
debug(message) {
177184
return console.debug(`metrics/compute/${this.login}/plugins > languages > ${this.constructor.name.replace(/([a-z])([A-Z])/, (_, a, b) => `${a} ${b.toLocaleLowerCase()}`).toLocaleLowerCase()} > ${message}`)
178185
}
179-
}
186+
}

0 commit comments

Comments
 (0)