diff --git a/config.yml b/config.yml index 52f3991..733e397 100644 --- a/config.yml +++ b/config.yml @@ -1,2 +1,3 @@ --- organization: "WorldHealthOrganization" +since: "2008-01-01" diff --git a/ts-backend/src/fetchers/issues.ts b/ts-backend/src/fetchers/issues.ts index e8000e0..6707745 100644 --- a/ts-backend/src/fetchers/issues.ts +++ b/ts-backend/src/fetchers/issues.ts @@ -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 } } } @@ -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; @@ -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; diff --git a/ts-backend/src/index.ts b/ts-backend/src/index.ts index 9c87d81..2f777ab 100644 --- a/ts-backend/src/index.ts +++ b/ts-backend/src/index.ts @@ -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 = ( @@ -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)}`);