Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Fix team members and team repos ingestion; filter batched pull reques…
Browse files Browse the repository at this point in the history
…ts (#286)
  • Loading branch information
RonaldEAM authored Nov 21, 2023
1 parent ad7c0bf commit 6df56e2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ export class APIClient {

public async iterateBatchedPullRequests(
repoIds: string[],
ingestStartDatetime: string,
iteratee: ResourceIteratee<PullRequestResponse>,
): Promise<void> {
if (!this.graphQLClient) {
Expand All @@ -707,6 +708,7 @@ export class APIClient {
const rateLimit =
await this.graphQLClient.iterateBatchedPullRequestEntities(
repoIds,
ingestStartDatetime,
iteratee,
);
this.logger.debug(
Expand Down
2 changes: 2 additions & 0 deletions src/client/GraphQLClient/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export class GitHubGraphQLClient {

public async iterateBatchedPullRequests(
repoIds: string[],
ingestStartDatetime: string,
iteratee: ResourceIteratee<PullRequestResponse>,
): Promise<RateLimitStepSummary> {
const executor = createQueryExecutor(this, this.logger);
Expand All @@ -264,6 +265,7 @@ export class GitHubGraphQLClient {
await BatchedPullRequestsQuery.iteratePullRequests(
{
repoIds,
ingestStartDatetime,
},
executor,
iteratee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type QueryState = BaseQueryState;

type QueryParams = {
repoIds: string[];
ingestStartDatetime: string;
};

const buildQuery: BuildQuery<QueryParams, QueryState> = (
Expand Down Expand Up @@ -91,7 +92,15 @@ const iteratePullRequests = async (
let queryState: QueryState = {};
const executable = buildQuery(queryParams, queryState);
const response = await execute(executable);
queryState = await processResponseData(response, iteratee);
const filterIteratee = async (pullRequest: PullRequestResponse) => {
if (
new Date(pullRequest.updatedAt) >=
new Date(queryParams.ingestStartDatetime)
) {
await iteratee(pullRequest);
}
};
queryState = await processResponseData(response, filterIteratee);

const queryCost = queryState?.rateLimit?.cost ?? 0;

Expand Down
7 changes: 6 additions & 1 deletion src/client/OrganizationAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,18 @@ export default class OrganizationAccountClient {

async iterateBatchedPullRequestEntities(
repoIds: string[],
ingestStartDatetime: string, //expect Date.toISOString format
iteratee: ResourceIteratee<PullRequestResponse>,
): Promise<RateLimitStepSummary> {
if (!this.authorizedForPullRequests) {
this.logger.info('Account not authorized for ingesting pull requests.');
return { totalCost: 0 };
}
return await this.v4.iterateBatchedPullRequests(repoIds, iteratee);
return await this.v4.iterateBatchedPullRequests(
repoIds,
ingestStartDatetime,
iteratee,
);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/steps/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,11 @@ export async function fetchPrs(
totalConnectionsById: pullRequestsTotalByRepo,
threshold: 25,
batchCb: async (repoKeys) => {
await apiClient.iterateBatchedPullRequests(repoKeys, iteratee);
await apiClient.iterateBatchedPullRequests(
repoKeys,
ingestStartDatetime,
iteratee,
);
},
singleCb: async (repoKey) => {
const repoData = repoTags.get(repoKey);
Expand Down
2 changes: 1 addition & 1 deletion src/steps/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function fetchTeams({
}),
);

teamDataMap.set(teamEntity._key, { name: team.name });
teamDataMap.set(teamEntity._key, { name: team.slug });
if (team.repositories.totalCount) {
repositoriesTotalByTeam.set(
teamEntity._key,
Expand Down

0 comments on commit 6df56e2

Please sign in to comment.