Repository navigation
Conversation
…ew changes Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
…/blocked fields Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
| "scripts": { | ||
| "test": "node --import tsx/esm --test test/**/*.ts", | ||
| "build": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.mjs" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^24.0.0", | ||
| "esbuild": "^0.25.0", | ||
| "tsx": "^4.0.0", | ||
| "typescript": "^5.0.0" | ||
| } |
There was a problem hiding this comment.
| "scripts": { | |
| "test": "node --import tsx/esm --test test/**/*.ts", | |
| "build": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.mjs" | |
| }, | |
| "devDependencies": { | |
| "@types/node": "^24.0.0", | |
| "esbuild": "^0.25.0", | |
| "tsx": "^4.0.0", | |
| "typescript": "^5.0.0" | |
| } | |
| "devDependencies": { | |
| "@types/node": "^24.0.0", | |
| "esbuild": "^0.25.0", | |
| "tsx": "^4.0.0", | |
| "typescript": "^6.0.2" | |
| }, | |
| "scripts": { | |
| "test": "node --import tsx/esm --test test/**/*.ts", | |
| "build": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.mjs" | |
| } |
There was a problem hiding this comment.
Done — devDependencies moved before scripts, typescript bumped to ^6.0.2.
There was a problem hiding this comment.
package-lock.json deleted and added to .gitignore. Added pnpm-workspace.yaml (with allowBuilds: { esbuild: true }) and pnpm-lock.yaml. CI updated to use pnpm/action-setup@v4 and pnpm install/pnpm test.
| test('AI only changes the score when confidence is strong', () => { | ||
| const base = { score: 40, level: 'medium', reasons: [], facts: {} }; | ||
| const base = { score: 40, level: 'medium' as const, trusted: false, reasons: [], facts: {} as ReturnType<typeof analyzeContributor>['facts'] }; |
There was a problem hiding this comment.
ReturnType<typeof analyzeContributor>['facts'] 这种复杂类型在顶端声明,并在下面引用。
There was a problem hiding this comment.
emptyFacts: ContributorFacts is now declared at the top of the test file and reused throughout.
| export interface GitHubProfile { | ||
| login: string; | ||
| type: string; | ||
| created_at: string; | ||
| public_repos?: number; | ||
| followers?: number; | ||
| following?: number; | ||
| name?: string; | ||
| bio?: string; | ||
| company?: string; | ||
| blog?: string; | ||
| location?: string; | ||
| } | ||
|
|
||
| export interface ContributorFacts { | ||
| accountAgeDays: number; | ||
| publicRepositories: number; | ||
| followers: number; | ||
| following: number; | ||
| recentPublicEvents: number; | ||
| authoredPullRequests: number; | ||
| authoredIssues: number; | ||
| organizationPullRequests: number; | ||
| } | ||
|
|
||
| export interface ContributorReport { | ||
| score: number; | ||
| level: 'low' | 'medium' | 'high'; | ||
| trusted: boolean; | ||
| reasons: string[]; | ||
| facts: ContributorFacts; | ||
| author?: string; | ||
| subject?: string; | ||
| number?: number; | ||
| blocked?: boolean; | ||
| aiReview?: AiReview; | ||
| aiError?: string; | ||
| } | ||
|
|
||
| export interface FinalContributorReport extends ContributorReport { | ||
| author: string; | ||
| subject: string; | ||
| number: number; | ||
| blocked: boolean; | ||
| } | ||
|
|
||
| export interface AiReview { | ||
| classification: 'likely-human' | 'inconclusive' | 'likely-automated'; | ||
| confidence: number; | ||
| reasons: string[]; | ||
| recommendation: string; | ||
| } | ||
|
|
||
| export interface AnalyzeContributorOptions { | ||
| profile: GitHubProfile; | ||
| events?: unknown[]; | ||
| authoredPullRequests?: number; | ||
| authoredIssues?: number; | ||
| organizationPullRequests?: number; | ||
| association?: string; | ||
| content?: string; | ||
| now?: Date; | ||
| } |
There was a problem hiding this comment.
All type definitions have been extracted to src/type.ts. Both src/analyze.ts and src/utility.ts import from there and re-export as needed.
| export interface ContributorFacts { | ||
| accountAgeDays: number; | ||
| publicRepositories: number; | ||
| followers: number; | ||
| following: number; | ||
| recentPublicEvents: number; | ||
| authoredPullRequests: number; | ||
| authoredIssues: number; | ||
| organizationPullRequests: number; | ||
| } |
There was a problem hiding this comment.
Changed to type ContributorFacts = Record<string, number>.
| export async function github( | ||
| token: string, | ||
| path: string, | ||
| options: RequestInit = {}, | ||
| allowNotFound = false, | ||
| ): Promise<unknown> { |
There was a problem hiding this comment.
| export async function github( | |
| token: string, | |
| path: string, | |
| options: RequestInit = {}, | |
| allowNotFound = false, | |
| ): Promise<unknown> { | |
| export async function github<T>( | |
| token: string, | |
| path: string, | |
| options: RequestInit = {}, | |
| allowNotFound = false, | |
| ): Promise<T> { |
There was a problem hiding this comment.
Done — github is now async function github<T>(token: string, path: string, options: RequestInit = {}, allowNotFound = false): Promise<T>.
| }: { | ||
| token: string; | ||
| owner: string; | ||
| profile: GitHubProfile; | ||
| report: ContributorReport; | ||
| target: ContributorTarget; | ||
| blockHighConfidenceAutomation: boolean; | ||
| }): Promise<boolean> { |
There was a problem hiding this comment.
Done — BlockContributorOptions and ReviewWithGitHubModelsOptions interfaces are now declared at the top of src/utility.ts before the functions that reference them.
| ); | ||
| } | ||
|
|
||
| const existing = comments.find(comment => comment.body?.includes(marker)); |
There was a problem hiding this comment.
| const existing = comments.find(comment => comment.body?.includes(marker)); | |
| const existing = comments.find(({ body }) => body?.includes(marker)); |
尽量直接在函数参数上解构。
There was a problem hiding this comment.
Done — comments.find(({ body }) => body?.includes(marker)).
…le fixes Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
All issues addressed in this commit — see the checklist in the PR description for the full list of changes. |
Addresses all unresolved review comments from the initial PR review. Changes span configuration hygiene, breaking API simplification, and a full TypeScript migration.
Configuration & CI
actions/checkoutandactions/setup-nodeto@v7; addnpm installstep to CIaction.yml: mergegithub-token+organization-tokeninto a singlegithub-token(caller controls permission level); native booleandefaultvalues (no more string literals)fail-on-high-risknow throwsErrorinstead of settingprocess.exitCode; description updated accordinglyREADME.md: YAML native list style fortypes:; example updated to reflect single tokenTypeScript migration
src/analyze.mjs→src/analyze.ts,test/analyze.test.mjs→test/analyze.test.tssrc/utility.ts— all GitHub API helpers (github,resolveTarget,syncRepositoryState,renderComment,writeSummary,output) extracted fromdist/index.mjssrc/index.ts— main orchestration logic, previously living only in the bundledist/index.mjsrebuilt viaesbuild;tsxadded for running TypeScript tests withnode --testCode style
clampsimplified to arrow expressionURLSearchParamsobject form replaces manualencodeURIComponentquery-string buildingFinalContributorReportinterface introduced — narrowsContributorReportsosyncRepositoryState,renderComment, andwriteSummaryrequireauthor,number, andblockedrather than accepting them as optional