Skip to content
Merged
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
23 changes: 23 additions & 0 deletions src/db/repositories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { and, desc, eq, gte, inArray, not, or, sql, type SQL } from "drizzle-orm";

Check warning on line 1 in src/db/repositories.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 1 in src/db/repositories.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1 in src/db/repositories.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 1 in src/db/repositories.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
import { getDb } from "./client";
import {
advisories,
Expand Down Expand Up @@ -129,6 +129,7 @@
ProductUsageSurface,
ProductUsageSurfaceActivationFunnel,
ProductUsageSurfaceRetention,
PullRequestFilePathRecord,
PullRequestFileRecord,
PullRequestDetailSyncStateRecord,
PullRequestRecord,
Expand Down Expand Up @@ -2657,6 +2658,28 @@
return rows.map(toPullRequestFileRecord);
}

export async function listRepoPullRequestFilePaths(
env: Env,
fullName: string,
options: { pullNumbers?: number[] | undefined; limit?: number | undefined } = {},
): Promise<PullRequestFilePathRecord[]> {
const db = getDb(env.DB);
const pullNumbers = [...new Set(options.pullNumbers ?? [])].filter((number) => Number.isInteger(number) && number > 0);
if (options.pullNumbers && pullNumbers.length === 0) return [];
const where = pullNumbers.length > 0
? and(eq(pullRequestFiles.repoFullName, fullName), inArray(pullRequestFiles.pullNumber, pullNumbers))
: eq(pullRequestFiles.repoFullName, fullName);
return db
.select({
repoFullName: pullRequestFiles.repoFullName,
pullNumber: pullRequestFiles.pullNumber,
path: pullRequestFiles.path,
})
.from(pullRequestFiles)
.where(where)
.limit(Math.max(0, Math.min(options.limit ?? 500, 500)));
}

export async function listRepoPullRequestFiles(env: Env, fullName: string): Promise<PullRequestFileRecord[]> {
const db = getDb(env.DB);
const rows = await db.select().from(pullRequestFiles).where(eq(pullRequestFiles.repoFullName, fullName)).limit(2000);
Expand Down
60 changes: 46 additions & 14 deletions src/queue/processors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {

Check warning on line 1 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 1 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 1 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
countOpenIssues,
countOpenPullRequests,
getAgentCommandAnswer,
Expand Down Expand Up @@ -30,7 +30,7 @@
listRecentMergedPullRequests,
updatePullRequestSlopAssessment,
listRepoLabels,
listRepoPullRequestFiles,
listRepoPullRequestFilePaths,
listRepoSyncStates,
listRepoSyncSegments,
listRepositories,
Expand Down Expand Up @@ -140,6 +140,7 @@
detectGittensorContributor,
PR_PANEL_RETRIGGER_MARKER,
unionScopedOverlapClusters,
type ContributorProfile,
} from "../signals/engine";
import { buildIssueSlopAssessment, buildSlopAssessment, type SlopBand } from "../signals/slop";
import { runGittensoryAiSlopAdvisory } from "../services/ai-slop";
Expand All @@ -148,7 +149,7 @@
import { buildFocusManifestGuidance, resolveEffectiveSettings } from "../signals/focus-manifest";
import type { LocalBranchAnalysisInput } from "../signals/local-branch";
import { runGittensoryAiReview } from "../services/ai-review";
import type { AdvisoryFinding, ContributorEvidenceRecord, DetectedNotificationEvent, GitHubWebhookPayload, JobMessage, JsonValue, PullRequestRecord, RepositorySettings } from "../types";
import type { AdvisoryFinding, ContributorEvidenceRecord, ContributorRepoStatRecord, DetectedNotificationEvent, GitHubWebhookPayload, IssueRecord, JobMessage, JsonValue, PullRequestFilePathRecord, PullRequestRecord, RepositoryRecord, RepositorySettings } from "../types";
import { sha256Hex } from "../utils/crypto";
import { errorMessage, nowIso } from "../utils/json";

Expand Down Expand Up @@ -545,6 +546,41 @@
return [...new Set([...pullRequests, ...issues].flatMap((record) => (record.authorLogin ? [record.authorLogin] : [])))].slice(0, 200);
}

const CONTRIBUTOR_EVIDENCE_MAX_PR_FILE_PATHS = 2000;
const CONTRIBUTOR_EVIDENCE_PR_FILE_PATHS_PER_REPO = 200;

async function loadContributorPullRequestFilePaths(
env: Env,
args: {
login: string;
profile: ContributorProfile;
pullRequests: PullRequestRecord[];
issues: IssueRecord[];
repoStats: ContributorRepoStatRecord[];
repositories: RepositoryRecord[];
},
): Promise<PullRequestFilePathRecord[]> {
const pullNumbersByRepo = new Map<string, Set<number>>();
for (const pr of args.pullRequests) {
if (pr.authorLogin?.toLowerCase() !== args.login.toLowerCase()) continue;
const key = pr.repoFullName.toLowerCase();
const current = pullNumbersByRepo.get(key) ?? new Set<number>();
current.add(pr.number);
pullNumbersByRepo.set(key, current);
}
const files: PullRequestFilePathRecord[] = [];
for (const repoFullName of evidenceGraphTouchedRepoFullNames(args)) {
if (files.length >= CONTRIBUTOR_EVIDENCE_MAX_PR_FILE_PATHS) break;
const remaining = CONTRIBUTOR_EVIDENCE_MAX_PR_FILE_PATHS - files.length;
const repoFiles = await listRepoPullRequestFilePaths(env, repoFullName, {
pullNumbers: [...(pullNumbersByRepo.get(repoFullName.toLowerCase()) ?? [])],
limit: Math.min(CONTRIBUTOR_EVIDENCE_PR_FILE_PATHS_PER_REPO, remaining),
});
files.push(...repoFiles);
}
return files;
}

async function buildContributorEvidence(env: Env, login?: string): Promise<void> {
const [allPullRequests, allIssues, repositories, syncStates, allBounties, snapshot] = await Promise.all([
listAllPullRequests(env),
Expand All @@ -569,18 +605,14 @@
]);
const repoStats = authoritativeContributorRepoStats(gittensorSnapshot, cachedRepoStats);
const profile = buildContributorProfile(contributorLogin, github, contributorPullRequests, contributorIssues, repoStats, gittensorSnapshot);
const pullRequestFiles = (
await Promise.all(
evidenceGraphTouchedRepoFullNames({
login: contributorLogin,
profile,
pullRequests: contributorPullRequests,
issues: contributorIssues,
repoStats,
repositories,
}).map((repoFullName) => listRepoPullRequestFiles(env, repoFullName)),
)
).flat();
const pullRequestFiles = await loadContributorPullRequestFilePaths(env, {
login: contributorLogin,
profile,
pullRequests: contributorPullRequests,
issues: contributorIssues,
repoStats,
repositories,
});
const fit = buildContributorFit(profile, repositories, allIssues, allPullRequests, syncStates, repoStats, allBounties, issueQualityByRepo);
const scoringProfile = buildContributorScoringProfile({ login: contributorLogin, fit, scoringSnapshot: snapshot });
const outcomeHistory = buildContributorOutcomeHistory({ login: contributorLogin, profile, repositories, pullRequests: allPullRequests, issues: allIssues, repoStats, cachedRepoStats });
Expand Down
6 changes: 3 additions & 3 deletions src/services/contributor-evidence-graph.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { GittensorContributorSnapshot } from "../gittensor/api";

Check warning on line 1 in src/services/contributor-evidence-graph.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 1 in src/services/contributor-evidence-graph.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1 in src/services/contributor-evidence-graph.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 1 in src/services/contributor-evidence-graph.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
import type { ContributorOutcomeHistory, ContributorProfile, RoleContext } from "../signals/engine";
import type {
ContributorRepoStatRecord,
IssueRecord,
PullRequestFileRecord,
PullRequestFilePathRecord,
PullRequestRecord,
RepositoryRecord,
RepoSyncStateRecord,
Expand Down Expand Up @@ -153,7 +153,7 @@
issues?: IssueRecord[] | undefined;
repoStats?: ContributorRepoStatRecord[] | undefined;
syncStates?: RepoSyncStateRecord[] | undefined;
pullRequestFiles?: PullRequestFileRecord[] | undefined;
pullRequestFiles?: PullRequestFilePathRecord[] | undefined;
gittensorSnapshot?: GittensorContributorSnapshot | null | undefined;
};

Expand Down Expand Up @@ -374,7 +374,7 @@
);
}

function buildPathEdges(login: string, contributorPullRequests: PullRequestRecord[], files: PullRequestFileRecord[], generatedAt: string): ContributorEvidenceGraphPath[] {
function buildPathEdges(login: string, contributorPullRequests: PullRequestRecord[], files: PullRequestFilePathRecord[], generatedAt: string): ContributorEvidenceGraphPath[] {
const prByKey = new Map(contributorPullRequests.filter((pr) => sameLogin(pr.authorLogin, login)).map((pr) => [`${pr.repoFullName.toLowerCase()}#${pr.number}`, pr]));
const buckets = new Map<string, PathBucket>();
for (const file of files) {
Expand Down
60 changes: 45 additions & 15 deletions src/services/decision-pack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadRepoFocusManifests } from "../signals/focus-manifest-loader";

Check warning on line 1 in src/services/decision-pack.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 1 in src/services/decision-pack.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1 in src/services/decision-pack.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 1 in src/services/decision-pack.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
import type { FocusManifest, FocusManifestIssueDiscoveryPolicy, FocusManifestLinkedIssuePolicy, FocusManifestSource } from "../signals/focus-manifest";
import { isFocusManifestPublicSafe } from "../signals/focus-manifest";
import {
Expand All @@ -10,7 +10,7 @@
listContributorPullRequests,
listContributorRepoStats,
listLatestRepoGithubTotalsSnapshots,
listRepoPullRequestFiles,
listRepoPullRequestFilePaths,
listRepositories,
listRepoSyncSegments,
listRepoSyncStates,
Expand Down Expand Up @@ -57,7 +57,7 @@
ContributorRepoStatRecord,
IssueRecord,
JsonValue,
PullRequestFileRecord,
PullRequestFilePathRecord,
PullRequestRecord,
RepositoryRecord,
RepoGithubTotalsSnapshotRecord,
Expand All @@ -71,6 +71,8 @@
export const CONTRIBUTOR_DECISION_PACK_SIGNAL = "contributor-decision-pack";
export const DECISION_PACK_MAX_AGE_MS = 6 * 60 * 60 * 1000;
const DEFAULT_OSS_EMISSION_SHARE = DEFAULT_SCORING_CONSTANTS.OSS_EMISSION_SHARE ?? 0.9;
const DECISION_PACK_MAX_PR_FILE_PATHS = 2000;
const DECISION_PACK_PR_FILE_PATHS_PER_REPO = 200;

function resolveOssEmissionShare(constants: Record<string, number> | undefined): number {
const value = constants?.OSS_EMISSION_SHARE;
Expand All @@ -79,6 +81,38 @@
export const DECISION_PACK_REBUILD_DEBOUNCE_MS = 15 * 1000;
const pendingDecisionPackRebuilds = new Map<string, Promise<boolean>>();

async function loadContributorPullRequestFilePaths(
env: Env,
args: {
login: string;
profile: ContributorProfile;
pullRequests: PullRequestRecord[];
issues: IssueRecord[];
repoStats: ContributorRepoStatRecord[];
repositories: RepositoryRecord[];
},
): Promise<PullRequestFilePathRecord[]> {
const pullNumbersByRepo = new Map<string, Set<number>>();
for (const pr of args.pullRequests) {
if (pr.authorLogin?.toLowerCase() !== args.login.toLowerCase()) continue;
const key = pr.repoFullName.toLowerCase();
const current = pullNumbersByRepo.get(key) ?? new Set<number>();
current.add(pr.number);
pullNumbersByRepo.set(key, current);
}
const files: PullRequestFilePathRecord[] = [];
for (const repoFullName of evidenceGraphTouchedRepoFullNames(args)) {
if (files.length >= DECISION_PACK_MAX_PR_FILE_PATHS) break;
const remaining = DECISION_PACK_MAX_PR_FILE_PATHS - files.length;
const repoFiles = await listRepoPullRequestFilePaths(env, repoFullName, {
pullNumbers: [...(pullNumbersByRepo.get(repoFullName.toLowerCase()) ?? [])],
limit: Math.min(DECISION_PACK_PR_FILE_PATHS_PER_REPO, remaining),
});
files.push(...repoFiles);
}
return files;
}

export type DecisionRecommendation = "pursue" | "cleanup_first" | "maintainer_lane" | "avoid_for_now" | "watch";
export type DecisionActionKind = "cleanup_existing_prs" | "land_existing_prs" | "open_new_direct_pr" | "file_issue_discovery" | "maintainer_lane_improve_repo" | "maintainer_cut_readiness";
export type DecisionPackFreshness = "fresh" | "stale" | "rebuilding" | "missing";
Expand Down Expand Up @@ -442,18 +476,14 @@
repositories.filter((repo) => repo.isRegistered).map((repo) => repo.fullName),
);
const profile = buildContributorProfile(login, github, contributorPullRequests, contributorIssues, repoStats, gittensorSnapshot);
const pullRequestFiles = (
await Promise.all(
evidenceGraphTouchedRepoFullNames({
login,
profile,
pullRequests: contributorPullRequests,
issues: contributorIssues,
repoStats,
repositories,
}).map((repoFullName) => listRepoPullRequestFiles(env, repoFullName)),
)
).flat();
const pullRequestFiles = await loadContributorPullRequestFilePaths(env, {
login,
profile,
pullRequests: contributorPullRequests,
issues: contributorIssues,
repoStats,
repositories,
});
const outcomeHistory = buildContributorOutcomeHistory({
login,
profile,
Expand Down Expand Up @@ -547,7 +577,7 @@
contributorPullRequests: Parameters<typeof buildRoleContext>[0]["pullRequests"];
contributorIssues: Parameters<typeof buildRoleContext>[0]["issues"];
repoStats?: ContributorRepoStatRecord[] | undefined;
pullRequestFiles?: PullRequestFileRecord[] | undefined;
pullRequestFiles?: PullRequestFilePathRecord[] | undefined;
gittensorSnapshot?: Awaited<ReturnType<typeof fetchGittensorContributorSnapshot>> | undefined;
issueQualityByRepo?: Map<string, IssueQualityReport> | undefined;
openPrMonitor: ContributorOpenPrMonitor;
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type JsonPrimitive = string | number | boolean | null;

Check warning on line 1 in src/types.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 1 in src/types.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1 in src/types.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 1 in src/types.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };

export type JobMessage =
Expand Down Expand Up @@ -703,6 +703,8 @@
payload: Record<string, JsonValue>;
};

export type PullRequestFilePathRecord = Pick<PullRequestFileRecord, "repoFullName" | "pullNumber" | "path">;

export type PullRequestReviewRecord = {
id: string;
repoFullName: string;
Expand Down
Loading
Loading