diff --git a/dataScripts/fetchAllRepos.js b/dataScripts/fetchAllRepos.js index 625ce4e..d5d6c25 100644 --- a/dataScripts/fetchAllRepos.js +++ b/dataScripts/fetchAllRepos.js @@ -2,7 +2,10 @@ 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"; +import { + getDependenciesForRepo, + getOpenPRsForRepo, +} from "../renovate/dependencyDashboard.js"; const fetchAllRepos = async () => { const repos = []; @@ -10,9 +13,18 @@ const fetchAllRepos = async () => { await OctokitApp.app.eachRepository(async ({ repository, octokit }) => { if (repository.archived) return; - repository.dependencies = await getDependenciesForRepo({ - repository, - octokit, + await Promise.all([ + await getDependenciesForRepo({ + repository, + octokit, + }), + await getOpenPRsForRepo({ + repository, + octokit, + }), + ]).then(([dependencies, openPrsCount]) => { + repository.dependencies = dependencies; + repository.openPrsCount = openPrsCount; }); repos.push(mapRepoFromApiForStorage(repository)); diff --git a/index.njk b/index.njk index 8227ee1..e351c48 100644 --- a/index.njk +++ b/index.njk @@ -35,6 +35,7 @@ Language Topics Open issues count + Open PRs count Last updated Dependencies @@ -47,6 +48,7 @@ {{ repo.language }} {{ repo.topics | join(", ")}} {{ repo.openIssues }} + {{ repo.openPrsCount }} {{ repo.updatedAt }} {% if repo.dependencies.length %} diff --git a/renovate/dependencyDashboard.js b/renovate/dependencyDashboard.js index 6773b64..94c697e 100644 --- a/renovate/dependencyDashboard.js +++ b/renovate/dependencyDashboard.js @@ -52,7 +52,13 @@ export const handleIssuesApiResponse = (response) => { return parseDependenciesFromDashboard(dependencyDashboardIssue); } + +export const handlePrsApiResponse = ({ data }) => data?.length || 0; + export const getDependenciesForRepo = ({ octokit, repository }) => { return octokit.request(repository.issues_url).then(handleIssuesApiResponse); }; +export const getOpenPRsForRepo = ({ octokit, repository }) => { + return octokit.request(repository.pulls_url).then(handlePrsApiResponse); +}; diff --git a/renovate/dependencyDashboard.test.js b/renovate/dependencyDashboard.test.js index 5d17d1f..7e061ae 100644 --- a/renovate/dependencyDashboard.test.js +++ b/renovate/dependencyDashboard.test.js @@ -1,6 +1,6 @@ import { describe, it } from "node:test"; import expect from "node:assert"; -import { Dependency, handleIssuesApiResponse } from "./dependencyDashboard.js"; +import { Dependency, handleIssuesApiResponse, handlePrsApiResponse } from "./dependencyDashboard.js"; describe("handleIssuesApiResponse", () => { it("should extract dependency version information from the Renovate Dependency Dashboard if it exists", async () => { @@ -68,4 +68,14 @@ describe("handleIssuesApiResponse", () => { expectedDependencies, ); }); + + describe("handlePrsApiResponse", () => { + it("returns the length of the array containing PRs", () => { + expect.equal(handlePrsApiResponse({ data: [1, 2, 3] }), 3); + }); + + it("returns 0 if there are no open PRs", () => { + expect.equal(handlePrsApiResponse({ data: undefined }), 0); + }); + }); }); diff --git a/utils.js b/utils.js index c8aa7b3..5fcbefe 100644 --- a/utils.js +++ b/utils.js @@ -32,4 +32,5 @@ export const mapRepoFromApiForStorage = (repo) => ({ topics: repo.topics, openIssues: repo.open_issues, dependencies: repo.dependencies, + openPrsCount: repo.openPrsCount, }); diff --git a/utils.test.js b/utils.test.js index 52988b7..0eaf171 100644 --- a/utils.test.js +++ b/utils.test.js @@ -253,6 +253,7 @@ describe("mapRepoFromStorageToUi", () => { pull: false, }, dependencies: repoDependencies, + openPrsCount: 0, }; const repoToSave = { @@ -270,6 +271,7 @@ describe("mapRepoFromStorageToUi", () => { topics: ["delivery-plus", "internal", "tech-ops"], openIssues: 2, dependencies: repoDependencies, + openPrsCount: 0, }; expect.deepEqual(mapRepoFromApiForStorage(apiRepo), repoToSave);