Skip to content

Commit

Permalink
feat: add issue response time and better since config options
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhenry committed Feb 6, 2024
1 parent a00fb81 commit 58395a4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
organization: "WorldHealthOrganization"
since: "2008-01-01"
47 changes: 38 additions & 9 deletions ts-backend/src/fetchers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ const calculateIssueResponseTime = async (
endCursor
}
nodes {
author {
login
}
createdAt
comments(first: 1) {
comments(first: 30) {
totalCount
nodes {
createdAt
author {
__typename
login
... on Bot {
id
}
}
isMinimized
}
}
}
Expand Down Expand Up @@ -178,10 +189,28 @@ const calculateIssueResponseTime = async (
};
}

// Filter out issues without comments
const issues = result.repository.issues.nodes.filter(
(issue) => issue!.comments.totalCount > 0
);
// Filter out issues without comments that meet our criteria
// Criteria:
// - not the author of the issue
// - the comment is not a bot
// - the comment is not marked as spam
//
// Also filter out issues without comments after we filtered the comments
const issues = result.repository.issues.nodes
.map((issue) => {
return {
...issue,
comments: {
nodes: issue!.comments.nodes?.filter(
(comment) =>
comment!.author?.login !== issue!.author?.login &&
comment!.author?.__typename !== "Bot" &&
!comment?.isMinimized
),
},
};
})
.filter((issue) => issue!.comments?.nodes?.length ?? 0 > 0);

const issuesCount = issues.length;

Expand Down Expand Up @@ -226,16 +255,16 @@ export const addIssueMetricsData: Fetcher = async (result, octokit, config) => {
issuesMedianAge: closedIssuesMedianAge,
} = await calculateIssueMetricsPerRepo(repoName, "closed", octokit, config);

// const { issuesResponseAverageAge, issuesResponseMedianAge } =
// await calculateIssueResponseTime(repoName, octokit, config);
const { issuesResponseAverageAge, issuesResponseMedianAge } =
await calculateIssueResponseTime(repoName, octokit, config);

const repo = result.repositories[repoName];
repo.openIssuesAverageAge = openIssuesAverageAge;
repo.openIssuesMedianAge = openIssuesMedianAge;
repo.closedIssuesAverageAge = closedIssuesAverageAge;
repo.closedIssuesMedianAge = closedIssuesMedianAge;
// repo.issuesResponseAverageAge = issuesResponseAverageAge;
// repo.issuesResponseMedianAge = issuesResponseMedianAge;
repo.issuesResponseAverageAge = issuesResponseAverageAge;
repo.issuesResponseMedianAge = issuesResponseMedianAge;
}

return result;
Expand Down
12 changes: 6 additions & 6 deletions ts-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ export interface RepositoryResult {
openIssuesMedianAge: number;
closedIssuesAverageAge: number;
closedIssuesMedianAge: number;

// Will be added at a later time
// issuesResponseAverageAge: number;
// issuesResponseMedianAge: number;
issuesResponseAverageAge: number;
issuesResponseMedianAge: number;
}

export type Fetcher = (
Expand Down Expand Up @@ -110,9 +108,11 @@ const config: Config = {
organization: "github",
includeForks: false,
includeArchived: false,
// Default since date is 180 days ago
since: new Date(Date.now() - 180 * (24 * 60 * 60 * 1000)).toISOString(),
...yamlConfig,
// Default since date is 365 days ago (1 year)
since: yamlConfig.since
? new Date(yamlConfig.since).toISOString()
: new Date(Date.now() - 365 * (24 * 60 * 60 * 1000)).toISOString(),
};

console.log(`📋 Configuration: \n${JSON.stringify(config, null, 2)}`);
Expand Down

0 comments on commit 58395a4

Please sign in to comment.