Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions functions/generateLeaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}

Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down