diff --git a/functions/generateLeaderboard.js b/functions/generateLeaderboard.js index 6e35f7a..f4a0767 100644 --- a/functions/generateLeaderboard.js +++ b/functions/generateLeaderboard.js @@ -60,30 +60,26 @@ const getOrgReposQuery = (cursor = null) => { const getGraphQLQuery = (repoOwner, repoName, cursor = null) => { return ` query { - search(query: "repo:${repoOwner}/${repoName} is:pr is:merged label:recode", type: ISSUE, first: 100, after: ${ - cursor ? `"${cursor}"` : "null" - }) { - pageInfo { - endCursor - hasNextPage - } - edges { - node { - ... on PullRequest { - title + repository(owner: "${repoOwner}", name: "${repoName}") { + pullRequests(states: MERGED, first: 100, after: ${cursor ? `"${cursor}"` : "null"}) { + pageInfo { + endCursor + hasNextPage + } + nodes { + title + url + mergedAt + number + author { + login + avatarUrl url - mergedAt - number - author { - login - avatarUrl - url - } - labels(first: 20) { - edges { - node { - name - } + } + labels(first: 20) { + edges { + node { + name } } } @@ -234,9 +230,8 @@ const calculatePointsForPR = (labels) => { * Parses page PRs, checks validity, and aggregates data. */ const processPRData = (response, leaderboard, repoName) => { - const edges = response.data.data?.search?.edges || []; - for (const edge of edges) { - const pr = edge.node; + const prs = response.data.data?.repository?.pullRequests?.nodes || []; + for (const pr of prs) { const author = pr.author; if (!author || !author.login) continue; @@ -304,7 +299,7 @@ const calculateStreak = (prDates) => { const prevDate = new Date(sortedDates[j - 1]); const currDate = new Date(sortedDates[j]); - const diffInDays = (currDate - prevDate) / (1000 * 60 * 60 * 24); + const diffInDays = Math.round((currDate - prevDate) / (1000 * 60 * 60 * 24)); if (diffInDays === 1) { streak += 1; @@ -363,11 +358,11 @@ async function generateLeaderboard() { processPRData(response, leaderboard, repo.name); - const searchData = response.data.data?.search; - if (!searchData) break; + const prData = response.data.data?.repository?.pullRequests; + if (!prData) break; - hasNextPage = searchData.pageInfo.hasNextPage; - cursor = searchData.pageInfo.endCursor; + hasNextPage = prData.pageInfo.hasNextPage; + cursor = prData.pageInfo.endCursor; pageCount++; } diff --git a/server.js b/server.js index f8789cc..c72f107 100644 --- a/server.js +++ b/server.js @@ -36,8 +36,9 @@ ensureCacheFiles() console.error("Failed to initialize cache files on startup:", err); }); +// Health check endpoint (vital for Railway uptime monitoring) app.get("/", (req, res) => { - res.send("Hello World"); + res.status(200).json({ status: "healthy", service: "recode-leaderboard-backend" }); }); // Helper function to safely serve JSON cache files with fallback/error handling