-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from dxw/add-repos-data
Add seed data
- Loading branch information
Showing
11 changed files
with
380 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,6 @@ dist | |
# Local config | ||
towtruck.private-key.pem | ||
.mygitignore | ||
|
||
# Sensitive repo data | ||
/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { OctokitApp } from "../octokitApp.js"; | ||
import { writeFile, mkdir } from "fs/promises"; | ||
import { mapRepoFromApiForStorage } from "../utils.js"; | ||
import path from "path"; | ||
import { getDependenciesForRepo } from "../renovate/dependencyDashboard.js"; | ||
|
||
const fetchAllRepos = async () => { | ||
const repos = []; | ||
|
||
await OctokitApp.app.eachRepository(async ({ repository, octokit }) => { | ||
if (repository.archived) return; | ||
|
||
repository.dependencies = await getDependenciesForRepo({ | ||
repository, | ||
octokit, | ||
}); | ||
|
||
repos.push(mapRepoFromApiForStorage(repository)); | ||
}); | ||
|
||
return repos; | ||
}; | ||
|
||
const installationOctokit = await OctokitApp.app.octokit.request( | ||
"GET /app/installations" | ||
); | ||
|
||
const saveAllRepos = async () => { | ||
console.info("Fetching all repos..."); | ||
const repos = await fetchAllRepos(); | ||
|
||
try { | ||
const dir = path.dirname("./data/repos.json"); | ||
await mkdir(dir, { recursive: true }); | ||
|
||
console.info("Saving all repos..."); | ||
const toSave = { | ||
org: installationOctokit.data[0].account.login, | ||
repos, | ||
}; | ||
|
||
await writeFile("./data/repos.json", JSON.stringify(toSave), { | ||
encoding: "utf-8", | ||
flag: "w", | ||
}); | ||
} catch (error) { | ||
console.error("Error saving all repos", error); | ||
} | ||
}; | ||
|
||
await saveAllRepos(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# script/seed: Seeds the necessary data | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
echo "==> Seeding data..." | ||
npm run seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
export const orgRespositoriesToUiRepositories = (apiResponse) => { | ||
const repos = apiResponse.repositories.map((repo) => ({ | ||
name: repo.name, | ||
updatedAt: new Date(repo.updated_at).toLocaleDateString(), | ||
url: repo.html_url, | ||
issuesUrl: repo.issues_url, | ||
description: repo.description, | ||
})); | ||
const totalRepos = apiResponse.total_count; | ||
|
||
return { repos, totalRepos }; | ||
import { readFile } from "fs/promises"; | ||
export const mapRepoFromStorageToUi = (persistedData) => { | ||
const mappedRepos = persistedData.repos.map((repo) => { | ||
const newDate = new Date(repo.updatedAt).toLocaleDateString(); | ||
return { | ||
...repo, | ||
updatedAt: newDate, | ||
}; | ||
}); | ||
|
||
const totalRepos = mappedRepos.length; | ||
|
||
return { ...persistedData, repos: mappedRepos, totalRepos }; | ||
}; | ||
|
||
export const getReposFromJson = async (filePath) => { | ||
const reposJson = await readFile(filePath, { encoding: "utf-8" }); | ||
const persistedData = JSON.parse(reposJson); | ||
|
||
return persistedData; | ||
}; | ||
|
||
export const mapRepoFromApiForStorage = (repo) => ({ | ||
name: repo.name, | ||
description: repo.description, | ||
htmlUrl: repo.html_url, | ||
apiUrl: repo.url, | ||
pullsUrl: repo.pulls_url, | ||
issuesUrl: repo.issues_url, | ||
updatedAt: repo.updated_at, | ||
language: repo.language, | ||
topics: repo.topics, | ||
openIssues: repo.open_issues, | ||
}); |
Oops, something went wrong.