Skip to content

Commit ac08e9b

Browse files
author
Tulga Tsogtgerel
committed
User specific comment included in the full prompt
1 parent 4df380c commit ac08e9b

File tree

4 files changed

+122
-98
lines changed

4 files changed

+122
-98
lines changed

src/auggie.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ export type RunAuggieOptions = {
1313
workspaceRoot?: string;
1414
githubToken?: string;
1515
context?: GithubPullRequest;
16+
/** The body of the comment that triggered this action, if triggered by a comment */
17+
commentBody?: string;
1618
};
1719

1820
/**
1921
* Run Auggie agent with the given prompt and return the response
2022
*/
2123
export async function runAuggie(options: RunAuggieOptions): Promise<string> {
22-
const { userPrompt, apiKey, apiUrl, workspaceRoot, githubToken, context } =
23-
options;
24+
const {
25+
userPrompt,
26+
apiKey,
27+
apiUrl,
28+
workspaceRoot,
29+
githubToken,
30+
context,
31+
commentBody,
32+
} = options;
2433

2534
const workspace = workspaceRoot || process.cwd();
2635

@@ -53,7 +62,13 @@ export async function runAuggie(options: RunAuggieOptions): Promise<string> {
5362
// Add context information if provided
5463
if (context) {
5564
const contextPrompt = generateContextPrompt(context);
56-
fullPrompt = `${fullPrompt}\n\n${contextPrompt}`;
65+
fullPrompt = `${fullPrompt}\n\n## PR Context:\n${contextPrompt}`;
66+
}
67+
68+
// Add user comment request if triggered by a comment
69+
if (commentBody) {
70+
fullPrompt = `${fullPrompt}\n\n## User Specific Request:\n${commentBody}`;
71+
core.info("📨 User comment included in prompt");
5772
}
5873

5974
// Add user prompt

src/index.ts

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import * as core from "@actions/core";
33
import { Octokit } from "@octokit/rest";
44
import { runAuggie } from "./auggie";
55
import {
6-
getCommentIdFromEvent,
7-
getInput,
6+
getAuggieParams,
87
parseRepository,
98
reactToComment,
109
} from "./utils";
@@ -13,47 +12,29 @@ import {
1312
* Main function
1413
*/
1514
async function main(): Promise<void> {
16-
const githubToken = getInput("github_token", true);
17-
const eventName = getInput("event_name", true);
18-
const prompt = getInput("prompt", true);
19-
const augmentApiKey = getInput("augment_api_key");
20-
const augmentApiUrl = getInput("augment_api_url");
21-
const workspaceRoot = getInput("workspace_root");
22-
15+
const {
16+
githubToken,
17+
eventName,
18+
prompt,
19+
augmentApiKey,
20+
augmentApiUrl,
21+
workspaceRoot,
22+
commentBody,
23+
} = getAuggieParams();
2324
const { owner, repo } = parseRepository();
24-
25-
// Create Octokit instance
2625
const octokit = new Octokit({ auth: githubToken });
2726

28-
// Extract comment_id from GitHub event payload
29-
const commentId = getCommentIdFromEvent();
30-
31-
// React to the comment to acknowledge receipt (only for comment events)
32-
if (commentId) {
33-
core.info(`📝 Found comment ID ${commentId} from event payload`);
34-
await reactToComment({ octokit, owner, repo, commentId, eventName });
35-
} else {
36-
core.info(
37-
`ℹ️ No comment found in event payload, skipping comment reaction (event: ${eventName})`,
38-
);
39-
}
4027

41-
// Log GITHUB_STEP_SUMMARY availability
42-
const stepSummaryPath = process.env.GITHUB_STEP_SUMMARY;
43-
if (stepSummaryPath) {
44-
core.info(`📊 GITHUB_STEP_SUMMARY available at: ${stepSummaryPath}`);
45-
} else {
46-
core.warning("⚠️ GITHUB_STEP_SUMMARY not available");
47-
}
28+
await reactToComment({ octokit, owner, repo, eventName });
4829

49-
// Run Auggie agent with the prompt
50-
core.info("🚀 Running Auggie agent...");
30+
core.info("Running Auggie agent...");
5131
await runAuggie({
5232
userPrompt: prompt,
5333
apiKey: augmentApiKey,
5434
apiUrl: augmentApiUrl,
5535
workspaceRoot: workspaceRoot || undefined,
5636
githubToken,
37+
commentBody,
5738
});
5839

5940
core.info("✅ Auggie agent completed successfully");

src/utils/index.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ describe("getInput", () => {
3434
expect(getInput("test")).toBe("value");
3535
});
3636

37-
test("should return empty string for missing optional input", () => {
38-
expect(getInput("missing_input", false)).toBe("");
37+
test("should return undefined for missing optional input", () => {
38+
expect(getInput("missing_input", false)).toBeUndefined();
39+
});
40+
41+
test("should return undefined for missing input with no required parameter", () => {
42+
expect(getInput("missing_input")).toBeUndefined();
3943
});
4044

4145
test("should throw error for missing required input", () => {
@@ -44,9 +48,9 @@ describe("getInput", () => {
4448
);
4549
});
4650

47-
test("should not throw error for empty string when not required", () => {
51+
test("should return undefined for empty string when not required", () => {
4852
process.env.INPUT_OPTIONAL = "";
49-
expect(getInput("optional", false)).toBe("");
53+
expect(getInput("optional", false)).toBeUndefined();
5054
});
5155

5256
test("should throw error for empty string when required", () => {

src/utils/index.ts

Lines changed: 83 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,76 @@ import type { Octokit } from "@octokit/rest";
55
/**
66
* Get input from environment variables (GitHub Actions pattern)
77
*/
8-
export function getInput(name: string, required = false): string {
8+
export function getInput(name: string, required: true): string;
9+
export function getInput(name: string, required?: false): string | undefined;
10+
export function getInput(name: string, required = false): string | undefined {
911
const envName = `INPUT_${name.toUpperCase().replace(/ /g, "_")}`;
10-
const value = process.env[envName] || "";
12+
const value = process.env[envName];
1113

1214
if (required && !value) {
1315
throw new Error(`Input required and not supplied: ${name}`);
1416
}
1517

16-
return value.trim();
18+
return value?.trim() || undefined;
1719
}
1820

1921
/**
20-
* Extract comment ID from GitHub event payload
21-
* Returns undefined if the event doesn't have a comment
22+
* Read and parse GitHub event payload
23+
* Returns undefined if the event payload cannot be read
2224
*/
23-
export function getCommentIdFromEvent(): number | undefined {
25+
function getEventPayload(): Record<string, unknown> | undefined {
2426
const eventPath = process.env.GITHUB_EVENT_PATH;
2527
if (!eventPath) {
2628
core.warning("GITHUB_EVENT_PATH not found");
2729
return undefined;
2830
}
2931

3032
try {
31-
const eventData = JSON.parse(readFileSync(eventPath, "utf8"));
32-
33-
// Check if event has a comment object
34-
if (eventData.comment?.id) {
35-
return eventData.comment.id;
36-
}
37-
38-
return undefined;
33+
return JSON.parse(readFileSync(eventPath, "utf8"));
3934
} catch (error) {
4035
core.warning(`Failed to read event payload: ${error}`);
4136
return undefined;
4237
}
4338
}
4439

40+
/**
41+
* Extract comment ID from GitHub event payload
42+
* Returns undefined if the event doesn't have a comment
43+
*/
44+
export function getCommentIdFromEvent(): number | undefined {
45+
const eventData = getEventPayload();
46+
if (!eventData) {
47+
return undefined;
48+
}
49+
50+
// Check if event has a comment object
51+
const comment = eventData.comment as { id?: number } | undefined;
52+
if (comment?.id) {
53+
return comment.id;
54+
}
55+
56+
return undefined;
57+
}
58+
59+
/**
60+
* Extract comment body from GitHub event payload
61+
* Returns undefined if the event doesn't have a comment
62+
*/
63+
export function getCommentBodyFromEvent(): string | undefined {
64+
const eventData = getEventPayload();
65+
if (!eventData) {
66+
return undefined;
67+
}
68+
69+
// Check if event has a comment object with body
70+
const comment = eventData.comment as { body?: string } | undefined;
71+
if (comment?.body) {
72+
return comment.body;
73+
}
74+
75+
return undefined;
76+
}
77+
4578
/**
4679
* Parse repository owner and name from GITHUB_REPOSITORY
4780
*/
@@ -62,23 +95,31 @@ type ReactToCommentParams = {
6295
octokit: Octokit;
6396
owner: string;
6497
repo: string;
65-
commentId: number;
6698
eventName: string;
6799
};
68100

69101
/**
70102
* React to a comment with an emoji
103+
* Extracts comment ID from event payload and reacts if present
71104
*/
72105
export async function reactToComment({
73106
octokit,
74107
owner,
75108
repo,
76-
commentId,
77109
eventName,
78110
}: ReactToCommentParams): Promise<void> {
79-
core.info(`🎯 Reacting to comment ${commentId} with :eyes:`);
80-
core.info(`📦 Repository: ${owner}/${repo}`);
81-
core.info(`📝 Event: ${eventName}`);
111+
// Extract comment_id from GitHub event payload
112+
const commentId = getCommentIdFromEvent();
113+
114+
// Only react if we have a comment ID
115+
if (!commentId) {
116+
core.info(
117+
`ℹ️ No comment found in event payload, skipping comment reaction (event: ${eventName})`,
118+
);
119+
return;
120+
}
121+
122+
core.info("👀 Reacting to comment");
82123

83124
// React based on event type
84125
if (eventName === "pull_request_review_comment") {
@@ -102,48 +143,31 @@ export async function reactToComment({
102143
core.info(`✅ Successfully added :eyes: reaction to comment ${commentId}`);
103144
}
104145

105-
type PostCommentParams = {
106-
octokit: Octokit;
107-
owner: string;
108-
repo: string;
109-
issueNumber: number;
110-
body: string;
146+
type AuggieParams = {
147+
githubToken: string;
111148
eventName: string;
149+
prompt: string;
150+
augmentApiKey: string;
151+
augmentApiUrl: string;
152+
workspaceRoot: string | undefined;
153+
commentBody: string | undefined;
112154
};
113155

114-
/**
115-
* Post a reply comment
116-
*/
117-
export async function postComment({
118-
octokit,
119-
owner,
120-
repo,
121-
issueNumber,
122-
body,
123-
eventName,
124-
}: PostCommentParams): Promise<void> {
125-
core.info("💬 Posting comment reply...");
126-
127-
// Post comment based on event type
128-
if (eventName === "pull_request_review_comment") {
129-
// For PR review comments, we need to post as a regular issue comment
130-
// since we can't reply directly to review comments via API
131-
await octokit.rest.issues.createComment({
132-
owner,
133-
repo,
134-
issue_number: issueNumber,
135-
body,
136-
});
137-
} else if (eventName === "issue_comment") {
138-
await octokit.rest.issues.createComment({
139-
owner,
140-
repo,
141-
issue_number: issueNumber,
142-
body,
143-
});
144-
} else {
145-
throw new Error(`Unsupported event type: ${eventName}`);
156+
export function getAuggieParams(): AuggieParams {
157+
const githubToken = getInput("github_token", true);
158+
const eventName = getInput("event_name", true);
159+
const prompt = getInput("prompt", true);
160+
const augmentApiKey = getInput("augment_api_key", true);
161+
const augmentApiUrl = getInput("augment_api_url", true);
162+
const workspaceRoot = getInput("workspace_root");
163+
const commentBody = getCommentBodyFromEvent();
164+
return {
165+
githubToken,
166+
eventName,
167+
prompt,
168+
augmentApiKey,
169+
augmentApiUrl,
170+
workspaceRoot,
171+
commentBody,
146172
}
147-
148-
core.info("✅ Successfully posted comment");
149173
}

0 commit comments

Comments
 (0)