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

Fix team members and team repos ingestion; filter batched pull requests #286

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -699,6 +699,7 @@ export class APIClient {

public async iterateBatchedPullRequests(
repoIds: string[],
ingestStartDatetime: string,
iteratee: ResourceIteratee<PullRequestResponse>,
): Promise<void> {
if (!this.graphQLClient) {
@@ -707,6 +708,7 @@ export class APIClient {
const rateLimit =
await this.graphQLClient.iterateBatchedPullRequestEntities(
repoIds,
ingestStartDatetime,
iteratee,
);
this.logger.debug(
2 changes: 2 additions & 0 deletions src/client/GraphQLClient/client.ts
Original file line number Diff line number Diff line change
@@ -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);
@@ -264,6 +265,7 @@ export class GitHubGraphQLClient {
await BatchedPullRequestsQuery.iteratePullRequests(
{
repoIds,
ingestStartDatetime,
},
executor,
iteratee,
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ type QueryState = BaseQueryState;

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

const buildQuery: BuildQuery<QueryParams, QueryState> = (
@@ -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;

7 changes: 6 additions & 1 deletion src/client/OrganizationAccountClient.ts
Original file line number Diff line number Diff line change
@@ -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,
);
}

/**
6 changes: 5 additions & 1 deletion src/steps/pullRequests.ts
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion src/steps/teams.ts
Original file line number Diff line number Diff line change
@@ -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,