Skip to content

Commit

Permalink
Extract data from each GitHub API call into separate DB keyed value
Browse files Browse the repository at this point in the history
This will make it easier to update individual pieces of data in the
future, such as via a webhook.
  • Loading branch information
danlivings-dxw committed Oct 1, 2024
1 parent f2d7d38 commit 95df3c1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
Binary file modified e2es/testData/towtruck.db
Binary file not shown.
2 changes: 1 addition & 1 deletion utils/endOfLifeDateApi/fetchAllDependencyEolInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const fetchAllDependencyLifetimes = async () => {

const dependencySet = new Set();
Object.entries(persistedRepoData)
.flatMap(([, repo]) => repo.main.dependencies)
.flatMap(([, repo]) => repo.dependencies)
.forEach((dependency) => dependencySet.add(dependency.name));

const apiClient = new EndOfLifeDateApiClient();
Expand Down
15 changes: 10 additions & 5 deletions utils/githubApi/fetchAllRepos.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ const fetchAllRepos = async () => {
repository,
octokit,
}),
]).then(([dependencies, prInfo, issueInfo , alerts]) => {
repo.dependencies = dependencies;
repo = { ...repo, ...prInfo, ...issueInfo, ...alerts };
]).then(([dependencies, prInfo, issueInfo, alerts]) => {
repo = { repo, dependencies, prInfo, issueInfo, alerts };
});

repos.push(repo);
Expand All @@ -64,8 +63,14 @@ const saveAllRepos = async () => {
console.info("Saving all repos...");
const saveAllRepos = db.transaction((repos) => {
repos.forEach((repo) => {
db.saveToRepository(repo.name, "main", repo);
db.saveToRepository(repo.name, "owner", repo.owner);
const name = repo.repo.name;
const owner = repo.repo.owner;
db.saveToRepository(name, "main", repo.repo);
db.saveToRepository(name, "owner", owner);
db.saveToRepository(name, "dependencies", repo.dependencies);
db.saveToRepository(name, "pullRequests", repo.prInfo);
db.saveToRepository(name, "issues", repo.issueInfo);
db.saveToRepository(name, "dependabotAlerts", repo.alerts);
});
});

Expand Down
21 changes: 12 additions & 9 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,31 @@ export const hashToTailwindColor = (str) => {
export const mapRepoFromStorageToUi = (persistedData, persistedLifetimes) => {
const mappedRepos = Object.entries(persistedData).map(([, repo]) => {
const newDate = new Date(repo.main.updatedAt).toLocaleDateString();
const dependencies = repo.main.dependencies.map((dependency) => mapDependencyFromStorageToUi(dependency, persistedLifetimes));
const dependencies = repo.dependencies.map((dependency) => mapDependencyFromStorageToUi(dependency, persistedLifetimes));

const mostRecentPrOpenedAt = repo.main.mostRecentPrOpenedAt && formatDistanceToNow(repo.main.mostRecentPrOpenedAt, { addSuffix: true });
const oldestOpenPrOpenedAt = repo.main.oldestOpenPrOpenedAt && formatDistanceToNow(repo.main.oldestOpenPrOpenedAt, { addSuffix: true });
const mostRecentIssueOpenedAt = repo.main.mostRecentIssueOpenedAt && formatDistanceToNow(repo.main.mostRecentIssueOpenedAt, { addSuffix: true });
const oldestOpenIssueOpenedAt = repo.main.oldestOpenIssueOpenedAt && formatDistanceToNow(repo.main.oldestOpenIssueOpenedAt, { addSuffix: true });
const mostRecentPrOpenedAt = repo.pullRequests.mostRecentPrOpenedAt && formatDistanceToNow(repo.pullRequests.mostRecentPrOpenedAt, { addSuffix: true });
const oldestOpenPrOpenedAt = repo.pullRequests.oldestOpenPrOpenedAt && formatDistanceToNow(repo.pullRequests.oldestOpenPrOpenedAt, { addSuffix: true });
const mostRecentIssueOpenedAt = repo.issues.mostRecentIssueOpenedAt && formatDistanceToNow(repo.issues.mostRecentIssueOpenedAt, { addSuffix: true });
const oldestOpenIssueOpenedAt = repo.issues.oldestOpenIssueOpenedAt && formatDistanceToNow(repo.issues.oldestOpenIssueOpenedAt, { addSuffix: true });

const languageColor = hashToTailwindColor(repo.main.language);

return {
...repo.main,
...repo.dependabotAlerts,
...repo.pullRequests,
...repo.issues,
updatedAt: newDate,
updatedAtISO8601: repo.main.updatedAt,
dependencies,
mostRecentPrOpenedAt,
mostRecentPrOpenedAtISO8601: repo.main.mostRecentPrOpenedAt,
mostRecentPrOpenedAtISO8601: repo.pullRequests.mostRecentPrOpenedAt,
oldestOpenPrOpenedAt,
oldestOpenPrOpenedAtISO8601: repo.main.oldestOpenPrOpenedAt,
oldestOpenPrOpenedAtISO8601: repo.pullRequests.oldestOpenPrOpenedAt,
mostRecentIssueOpenedAt,
mostRecentIssueOpenedAtISO8601: repo.main.mostRecentIssueOpenedAt,
mostRecentIssueOpenedAtISO8601: repo.issues.mostRecentIssueOpenedAt,
oldestOpenIssueOpenedAt,
oldestOpenIssueOpenedAtISO8601: repo.main.oldestOpenIssueOpenedAt,
oldestOpenIssueOpenedAtISO8601: repo.issues.oldestOpenIssueOpenedAt,
languageColor,
};
});
Expand Down
54 changes: 45 additions & 9 deletions utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ describe("mapRepoFromStorageToUi", () => {
issuesUrl: "http://api.com/repo1/issues",
language: null,
topics: [],
openIssues: 0,
dependencies: [],
},
pullRequests: {
mostRecentPrOpenedAt: "2021-01-01T00:00:00Z",
oldestOpenPrOpenedAt: "2022-02-02T00:00:00Z",
},
issues: {
openIssues: 0,
mostRecentIssueOpenedAt: "2023-03-03T00:00:00Z",
oldestOpenIssueOpenedAt: "2024-04-04T00:00:00Z",
},
dependencies: [],
},
};

Expand Down Expand Up @@ -71,13 +75,17 @@ describe("mapRepoFromStorageToUi", () => {
issuesUrl: "http://api.com/repo1/issues",
language: "Ruby",
topics: [],
openIssues: 0,
dependencies: [],
},
pullRequests: {
mostRecentPrOpenedAt: "2021-01-01T00:00:00Z",
oldestOpenPrOpenedAt: "2022-02-02T00:00:00Z",
},
issues: {
openIssues: 0,
mostRecentIssueOpenedAt: "2023-03-03T00:00:00Z",
oldestOpenIssueOpenedAt: "2024-04-04T00:00:00Z",
},
dependencies: [],
},
repo2: {
owner: "dxw",
Expand All @@ -91,13 +99,17 @@ describe("mapRepoFromStorageToUi", () => {
issuesUrl: "http://api.com/repo2/issues",
language: "TypeScript",
topics: [],
openIssues: 0,
dependencies: [],
},
pullRequests: {
mostRecentPrOpenedAt: "2021-01-01T00:00:00Z",
oldestOpenPrOpenedAt: "2022-02-02T00:00:00Z",
},
issues: {
openIssues: 0,
mostRecentIssueOpenedAt: "2023-03-03T00:00:00Z",
oldestOpenIssueOpenedAt: "2024-04-04T00:00:00Z",
},
dependencies: [],
},
};

Expand Down Expand Up @@ -167,9 +179,17 @@ describe("mapRepoFromStorageToUi", () => {
issuesUrl: "http://api.com/repo1/issues",
language: null,
topics: [],
},
pullRequests: {
mostRecentPrOpenedAt: "2021-01-01T00:00:00Z",
oldestOpenPrOpenedAt: "2022-02-02T00:00:00Z",
},
issues: {
openIssues: 0,
dependencies: [],
mostRecentIssueOpenedAt: "2023-03-03T00:00:00Z",
oldestOpenIssueOpenedAt: "2024-04-04T00:00:00Z",
},
dependencies: [],
},
repo2: {
owner: "dxw",
Expand All @@ -183,9 +203,17 @@ describe("mapRepoFromStorageToUi", () => {
issuesUrl: "http://api.com/repo2/issues",
language: null,
topics: [],
},
pullRequests: {
mostRecentPrOpenedAt: "2021-01-01T00:00:00Z",
oldestOpenPrOpenedAt: "2022-02-02T00:00:00Z",
},
issues: {
openIssues: 0,
dependencies: [],
mostRecentIssueOpenedAt: "2023-03-03T00:00:00Z",
oldestOpenIssueOpenedAt: "2024-04-04T00:00:00Z",
},
dependencies: [],
},
repo3: {
owner: "dxw",
Expand All @@ -199,9 +227,17 @@ describe("mapRepoFromStorageToUi", () => {
issuesUrl: "http://api.com/repo3/issues",
language: null,
topics: [],
},
pullRequests: {
mostRecentPrOpenedAt: "2021-01-01T00:00:00Z",
oldestOpenPrOpenedAt: "2022-02-02T00:00:00Z",
},
issues: {
openIssues: 0,
dependencies: [],
mostRecentIssueOpenedAt: "2023-03-03T00:00:00Z",
oldestOpenIssueOpenedAt: "2024-04-04T00:00:00Z",
},
dependencies: [],
},
};

Expand Down

0 comments on commit 95df3c1

Please sign in to comment.