Skip to content

Apply all review comments from PR #1: TypeScript migration, token consolidation, style fixes - #2

Draft
TechQuery with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-all-comments-from-review
Draft

TechQuery with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-all-comments-from-review

Conversation

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown

Addresses all unresolved review comments from the initial PR review. Changes span configuration hygiene, breaking API simplification, and a full TypeScript migration.

Configuration & CI

  • Upgrade actions/checkout and actions/setup-node to @v7; add npm install step to CI
  • action.yml: merge github-token + organization-token into a single github-token (caller controls permission level); native boolean default values (no more string literals)
  • fail-on-high-risk now throws Error instead of setting process.exitCode; description updated accordingly
  • README.md: YAML native list style for types:; example updated to reflect single token

TypeScript migration

  • src/analyze.mjs → src/analyze.ts, test/analyze.test.mjs → test/analyze.test.ts
  • New src/utility.ts — all GitHub API helpers (github, resolveTarget, syncRepositoryState, renderComment, writeSummary, output) extracted from dist/index.mjs
  • New src/index.ts — main orchestration logic, previously living only in the bundle
  • dist/index.mjs rebuilt via esbuild; tsx added for running TypeScript tests with node --test

Code style

  • clamp simplified to arrow expression
  • URLSearchParams object form replaces manual encodeURIComponent query-string building
  • Env vars destructured as named constants at module top
  • Blank lines between declarations and logic blocks
  • FinalContributorReport interface introduced — narrows ContributorReport so syncRepositoryState, renderComment, and writeSummary require author, number, and blocked rather than accepting them as optional
// Before: three separate GitHub search calls with manual encoding
github(`/search/issues?q=${encodeURIComponent(`type:pr author:${login}`)}&per_page=1`)

// After: URLSearchParams object form
github(token, `/search/issues?${new URLSearchParams({ q: `type:pr author:${login}`, per_page: '1' })}`)

Copilot AI and others added 2 commits August 31, 2026 12:38
…ew changes

Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
…/blocked fields

Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>

@TechQuery TechQuery left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 所有的问题通篇都要改

Comment thread package.json Outdated
Comment on lines 10 to 19
"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"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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"
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — devDependencies moved before scripts, typescript bumped to ^6.0.2.

Comment thread package-lock.json Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此文件删掉并忽略,改用 PNPM 11 管理。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/analyze.test.ts Outdated
Comment on lines +69 to +70
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'] };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReturnType<typeof analyzeContributor>['facts'] 这种复杂类型在顶端声明,并在下面引用。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emptyFacts: ContributorFacts is now declared at the top of the test file and reused throughout.

Comment thread src/analyze.ts Outdated
Comment on lines +11 to +73
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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大量的类型统一放到 src/type.ts

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/analyze.ts Outdated
Comment on lines +25 to +34
export interface ContributorFacts {
accountAgeDays: number;
publicRepositories: number;
followers: number;
following: number;
recentPublicEvents: number;
authoredPullRequests: number;
authoredIssues: number;
organizationPullRequests: number;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改用 type + Record 简写

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to type ContributorFacts = Record<string, number>.

Comment thread src/utility.ts Outdated
Comment on lines +52 to +57
export async function github(
token: string,
path: string,
options: RequestInit = {},
allowNotFound = false,
): Promise<unknown> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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> {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — github is now async function github<T>(token: string, path: string, options: RequestInit = {}, allowNotFound = false): Promise<T>.

Comment thread src/utility.ts Outdated
Comment on lines +79 to +86
}: {
token: string;
owner: string;
profile: GitHubProfile;
report: ContributorReport;
target: ContributorTarget;
blockHighConfidenceAutomation: boolean;
}): Promise<boolean> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复杂类型先声明再引用

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — BlockContributorOptions and ReviewWithGitHubModelsOptions interfaces are now declared at the top of src/utility.ts before the functions that reference them.

Comment thread src/utility.ts
Comment thread src/utility.ts
Comment thread src/utility.ts Outdated
);
}

const existing = comments.find(comment => comment.body?.includes(marker));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const existing = comments.find(comment => comment.body?.includes(marker));
const existing = comments.find(({ body }) => body?.includes(marker));

尽量直接在函数参数上解构。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — comments.find(({ body }) => body?.includes(marker)).

…le fixes

Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown
Author

@copilot 所有的问题通篇都要改

All issues addressed in this commit — see the checklist in the PR description for the full list of changes.

Copilot AI requested a review from TechQuery August 31, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants