-
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.
Refactor seeding logic to be testable and reusable
The logic used to fetch and store information about repositories and dependencies will need to be reused to allow webhooks to make changes to the database. Using the logic in the application rather than in one-off seeding scripts makes it more important that it is tested to avoid unexpected changes to behaviour. This moves the actual seed scripts to wrapper scripts in the `seed` folder, which call the methods in the original files that have been refactored to be more testable.
- Loading branch information
1 parent
33250e5
commit c3a8feb
Showing
9 changed files
with
755 additions
and
59 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
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,20 @@ | ||
import { TowtruckDatabase } from "../db/index.js"; | ||
import { | ||
fetchAllDependencyLifetimes, | ||
saveAllDependencyLifetimes, | ||
} from "../utils/endOfLifeDateApi/fetchAllDependencyEolInfo.js"; | ||
import { EndOfLifeDateApiClient } from "../utils/endOfLifeDateApi/index.js"; | ||
|
||
const seed = async () => { | ||
const db = new TowtruckDatabase(); | ||
|
||
db.deleteAllDependencies(); | ||
|
||
const allLifetimes = await fetchAllDependencyLifetimes( | ||
db, | ||
new EndOfLifeDateApiClient(), | ||
); | ||
await saveAllDependencyLifetimes(allLifetimes, db); | ||
}; | ||
|
||
await 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { TowtruckDatabase } from "../db/index.js"; | ||
import { | ||
fetchForRepo, | ||
saveAllRepos, | ||
} from "../utils/githubApi/fetchAllRepos.js"; | ||
import { OctokitApp } from "../octokitApp.js"; | ||
|
||
/** | ||
* Fetches all repos from the GitHub API. | ||
* Each repo is enriched with data fetched through further API calls | ||
* @returns {Promise<StoredRepo[]>} | ||
*/ | ||
const fetchAllRepos = async () => { | ||
const repos = []; | ||
|
||
await OctokitApp.app.eachRepository(async ({ repository, octokit }) => { | ||
const repo = await fetchForRepo(repository, octokit); | ||
|
||
if (repo) repos.push(repo); | ||
}); | ||
|
||
return repos; | ||
}; | ||
|
||
const seed = async () => { | ||
const db = new TowtruckDatabase(); | ||
|
||
db.deleteAllRepositories(); | ||
|
||
const allRepos = await fetchAllRepos(); | ||
saveAllRepos(allRepos, db); | ||
}; | ||
|
||
await 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
Oops, something went wrong.