Skip to content

Commit 359b48a

Browse files
committed
consolidate pr context into concrete type
1 parent cded065 commit 359b48a

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

src/github/process-review.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getConfig } from "../config.js";
22
import { reviewDiff } from "../review/reviewer.js";
33
import { GitHubClient } from "./client.js";
4-
import { CHECK_STATUS, CHECK_CONCLUSION, PRDetails, GitHubPullRequestEvent } from "./types.js";
4+
import { CHECK_STATUS, CHECK_CONCLUSION, PRContext, GitHubPullRequestEvent } from "./types.js";
55

66
export async function processReview(
77
jobId: string,
@@ -62,18 +62,19 @@ export async function processReview(
6262

6363
console.log(`Retrieved diff content (${diffContent.length} chars)`);
6464

65-
// Create PR details object
66-
const prDetails: PRDetails = {
65+
// Create structured PR context object
66+
const prContext: PRContext = {
67+
owner,
68+
repo,
6769
pr_number: prNumber,
6870
repository_id: repositoryId,
6971
commit_sha: commitSha,
7072
pr_url: prUrl,
73+
repository_full_name: payload.repository.full_name,
7174
};
7275

73-
const prDetailsContent = `Repository: ${payload.repository.full_name},\nPR Number: ${prDetails.pr_number}\nCommit SHA: ${prDetails.commit_sha}\nPR URL: ${prDetails.pr_url}`;
74-
7576
console.log(`Calling reviewDiff() for job ${jobId}`);
76-
const reviewResult = await reviewDiff(diffContent, prDetailsContent, installationId);
77+
const reviewResult = await reviewDiff(diffContent, prContext, installationId);
7778
console.log(`Review completed for job ${jobId}`);
7879

7980
// Read collected comments from file

src/github/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ export interface PRDetails {
55
pr_url: string;
66
}
77

8+
export interface PRContext {
9+
owner: string;
10+
repo: string;
11+
pr_number: number;
12+
repository_id: number;
13+
commit_sha: string;
14+
pr_url: string;
15+
repository_full_name: string;
16+
}
17+
818
export interface GitHubPullRequestEvent {
919
action: string;
1020
number: number;

src/review/reviewer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { join } from 'path';
44
import { v4 as uuidv4 } from 'uuid';
55
import { Config, getConfig } from "../config.js";
66
import { newThread, execute } from "../amp.js";
7+
import { PRContext } from "../github/types.js";
78

89

910
export const reviewDiff = async (
1011
diffContent: string,
11-
prDetailsContent: string,
12+
prContext: PRContext,
1213
installationId: number
1314
) => {
1415

@@ -25,6 +26,9 @@ export const reviewDiff = async (
2526
// Create prompt content
2627
const ampConfig = config.amp;
2728

29+
// Format PR context for prompt
30+
const prDetailsContent = `Repository: ${prContext.repository_full_name}\nPR Number: ${prContext.pr_number}\nCommit SHA: ${prContext.commit_sha}\nPR URL: ${prContext.pr_url}`;
31+
2832
const promptContent = ampConfig.prompt_template
2933
.replace(/__PR_DETAILS_CONTENT__/g, prDetailsContent)
3034
.replace(/__DIFF_CONTENT__/g, diffContent);
@@ -57,6 +61,9 @@ export const reviewDiff = async (
5761
env: {
5862
GITHUB_INSTALLATION_ID: installationId.toString(),
5963
COMMENTS_FILE: commentsFilePath,
64+
GITHUB_OWNER: prContext.owner,
65+
GITHUB_REPO: prContext.repo,
66+
GITHUB_PR_NUMBER: prContext.pr_number.toString(),
6067
GITHUB_APP_ID: process.env.GITHUB_APP_ID || '',
6168
GITHUB_APP_PRIVATE_KEY_PATH: process.env.GITHUB_APP_PRIVATE_KEY_PATH || '',
6269
GITHUB_APP_CWD: process.env.GITHUB_APP_CWD || '',

toolbox/get-pr-comments.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ if (action === 'describe') {
1515
console.log(JSON.stringify({
1616
name: 'get_pr_comments',
1717
description: 'Get all comments on a pull request',
18-
args: {
19-
owner: ['string', 'Repository owner'],
20-
repo: ['string', 'Repository name'],
21-
pr_number: ['number', 'Pull request number']
22-
}
18+
args: {}
2319
}));
2420
process.exit(0);
2521
}
@@ -28,11 +24,13 @@ if (action === 'describe') {
2824
if (action === 'execute') {
2925
(async () => {
3026
try {
31-
const args = JSON.parse(fs.readFileSync(0, 'utf8'));
27+
// Get PR context from environment variables
28+
const owner = process.env.GITHUB_OWNER;
29+
const repo = process.env.GITHUB_REPO;
30+
const prNumber = parseInt(process.env.GITHUB_PR_NUMBER || '0');
3231

33-
// Validate required args
34-
if (!args.owner || !args.repo || typeof args.pr_number !== 'number') {
35-
throw new Error('Missing required arguments: owner, repo, pr_number');
32+
if (!owner || !repo || !prNumber) {
33+
throw new Error('Missing required environment variables: GITHUB_OWNER, GITHUB_REPO, GITHUB_PR_NUMBER');
3634
}
3735

3836
// Runtime deps from compiled output
@@ -42,7 +40,7 @@ if (action === 'execute') {
4240
const config = getConfig();
4341
const gh = GitHubClient.fromEnv(config);
4442

45-
const comments = await gh.getPRComments(args.owner, args.repo, args.pr_number);
43+
const comments = await gh.getPRComments(owner, repo, prNumber);
4644

4745
console.log(JSON.stringify({
4846
success: true,

0 commit comments

Comments
 (0)