Skip to content

Commit

Permalink
fix(plugins/languages): support for private repositories (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanRosenbaum authored Dec 18, 2023
1 parent a53a585 commit 995dd4a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions source/plugins/languages/analyzer/analyzer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,21 +87,27 @@ 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)
}
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
}
Expand Down Expand Up @@ -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}`)
}
}
}

5 comments on commit 995dd4a

@Nurerumana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nurerumana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Nurerumana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nurerumana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h

@Nurerumana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source/plugins/languages/analyzer/analyzer.mjs

Please sign in to comment.