Skip to content

Commit

Permalink
feat: add logs
Browse files Browse the repository at this point in the history
Signed-off-by: 0x73746F66 <[email protected]>
  • Loading branch information
0x73746F66 committed Jun 12, 2024
1 parent bb5370c commit e366043
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions functions/github/repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ export async function onRequestGet(context) {
}
try {
const fetcher = new GitHubRepoFetcher(access_token)
console.log('fetcher', fetcher)
const details = await fetcher.getRepoDetails()
console.log('details', details)
const repos = JSON.stringify(details, null, 2)
console.log('repos', repos)
return Response.json(repos)
} catch (e) {
console.error(e)
return Response.json(e)
}
}

class GitHubRepoFetcher {
constructor(accessKey) {
this.repos = []
this.accessKey = accessKey
this.headers = {
'Authorization': 'Bearer ${this.accessKey}',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer ${this.accessKey}" is used as
authorization header
.
Expand All @@ -53,6 +57,7 @@ class GitHubRepoFetcher {
this.baseUrl = "https://api.github.com"
}
async fetchJSON(url) {
console.log(url)
const response = await fetch(url, { headers: this.headers })
if (!response.ok) {
throw new Error(`GitHubRepoFetcher error! status: ${response.status}`)
Expand All @@ -70,6 +75,7 @@ class GitHubRepoFetcher {
}
async getFileContents(repo, branch) {
const fileUrl = `${this.baseUrl}/repos/${repo.full_name}/contents/.trivialsec?ref=${branch.name}`
console.log(fileUrl)
try {
const fileResponse = await fetch(fileUrl, { headers: this.headers })
if (!fileResponse.ok) {
Expand All @@ -88,7 +94,6 @@ class GitHubRepoFetcher {
}
async getRepoDetails() {
const repos = await this.getRepos()
const repoDetails = []

for (const repo of repos) {
const branches = await this.getBranches(repo)
Expand All @@ -97,7 +102,7 @@ class GitHubRepoFetcher {
const latestCommit = await this.getLatestCommit(repo, branch)
const fileDetails = await this.getFileContents(repo, branch)

repoDetails.push({
this.repos.push({
ghid: repo.id,
fullName: repo.full_name,
branch: branch.name,
Expand All @@ -120,6 +125,6 @@ class GitHubRepoFetcher {
}
}

return repoDetails
return this.repos
}
}

0 comments on commit e366043

Please sign in to comment.