Skip to content

Commit 38713fd

Browse files
author
Tulga Tsogtgerel
committed
refactor: move reaction to separate action.yml step for instant feedback
Move the emoji reaction from TypeScript code to a separate github-script step in action.yml. This provides even faster user feedback since: - No need to wait for Node.js setup - No need to wait for npm install - Reaction happens immediately before any processing Benefits: - Reaction appears in ~1-2 seconds instead of ~10-15 seconds - Cleaner separation of concerns - Simpler TypeScript code (removed unused reaction logic) - Better user experience with instant visual feedback
1 parent cb8d090 commit 38713fd

File tree

2 files changed

+34
-79
lines changed

2 files changed

+34
-79
lines changed

assistant/action.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,46 @@ outputs:
3434
runs:
3535
using: "composite"
3636
steps:
37+
- name: Add reaction for quick feedback
38+
uses: actions/github-script@v7
39+
with:
40+
github-token: ${{ inputs.github_token }}
41+
script: |
42+
const commentId = parseInt('${{ inputs.comment_id }}');
43+
const eventName = '${{ inputs.event_name }}';
44+
const reaction = '${{ inputs.reaction }}' || 'eyes';
45+
46+
try {
47+
if (eventName === 'pull_request_review_comment') {
48+
await github.rest.reactions.createForPullRequestReviewComment({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
comment_id: commentId,
52+
content: reaction
53+
});
54+
} else if (eventName === 'issue_comment') {
55+
await github.rest.reactions.createForIssueComment({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
comment_id: commentId,
59+
content: reaction
60+
});
61+
}
62+
console.log(`Added :${reaction}: reaction to comment ${commentId}`);
63+
} catch (error) {
64+
console.warn(`Failed to add reaction: ${error.message}`);
65+
}
66+
3767
- name: Setup Node
3868
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3969
with:
4070
node-version: 22
71+
4172
- name: Install Action Dependencies
4273
run: npm install --production
4374
shell: bash
4475
working-directory: ${{ github.action_path }}
76+
4577
- name: Run PR Assistant
4678
id: react
4779
run: npx tsx ${{ github.action_path }}/src/index.ts

assistant/src/index.ts

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,7 @@ import * as exec from '@actions/exec';
1010
import { Octokit } from '@octokit/rest';
1111
import { Auggie } from '@augmentcode/auggie-sdk';
1212

13-
/**
14-
* Valid GitHub reaction types
15-
*/
16-
const VALID_REACTIONS = [
17-
'+1',
18-
'-1',
19-
'laugh',
20-
'confused',
21-
'heart',
22-
'hooray',
23-
'rocket',
24-
'eyes',
25-
] as const;
26-
27-
type ReactionType = (typeof VALID_REACTIONS)[number];
13+
2814

2915
/**
3016
* PR Context gathered from GitHub
@@ -81,64 +67,7 @@ function parseRepository(): { owner: string; repo: string } {
8167
return { owner, repo };
8268
}
8369

84-
/**
85-
* Validate reaction type
86-
*/
87-
function validateReaction(reaction: string): ReactionType {
88-
if (!VALID_REACTIONS.includes(reaction as ReactionType)) {
89-
throw new Error(
90-
`Invalid reaction type: ${reaction}. Valid reactions: ${VALID_REACTIONS.join(', ')}`
91-
);
92-
}
93-
return reaction as ReactionType;
94-
}
9570

96-
/**
97-
* Add reaction to a comment
98-
*/
99-
async function addReaction(
100-
octokit: Octokit,
101-
owner: string,
102-
repo: string,
103-
commentId: number,
104-
eventName: string,
105-
reaction: ReactionType
106-
): Promise<void> {
107-
try {
108-
if (eventName === 'pull_request_review_comment') {
109-
await octokit.rest.reactions.createForPullRequestReviewComment({
110-
owner,
111-
repo,
112-
comment_id: commentId,
113-
content: reaction,
114-
});
115-
core.info(`✅ Added :${reaction}: reaction to PR review comment ${commentId}`);
116-
} else if (eventName === 'issue_comment') {
117-
await octokit.rest.reactions.createForIssueComment({
118-
owner,
119-
repo,
120-
comment_id: commentId,
121-
content: reaction,
122-
});
123-
core.info(`✅ Added :${reaction}: reaction to issue comment ${commentId}`);
124-
} else {
125-
throw new Error(
126-
`Unsupported event type: ${eventName}. Supported: pull_request_review_comment, issue_comment`
127-
);
128-
}
129-
} catch (error) {
130-
if (error instanceof Error) {
131-
// biome-ignore lint/suspicious/noExplicitAny: POC
132-
const apiError = error as any;
133-
const requestId = apiError.response?.headers?.['x-github-request-id'] || 'unknown';
134-
const status = apiError.status || '';
135-
throw new Error(
136-
`Failed to add :${reaction}: reaction (${status}): ${error.message}; requestId=${requestId}`
137-
);
138-
}
139-
throw error;
140-
}
141-
}
14271

14372
/**
14473
* Get PR number from comment
@@ -423,25 +352,19 @@ async function main(): Promise<void> {
423352
const githubToken = getInput('github_token', true);
424353
const commentIdStr = getInput('comment_id', true);
425354
const eventName = getInput('event_name', true);
426-
const reactionInput = getInput('reaction') || 'eyes';
427355

428356
// Validate inputs
429357
const commentId = Number.parseInt(commentIdStr, 10);
430358
if (Number.isNaN(commentId)) {
431359
throw new Error(`Invalid comment_id: ${commentIdStr}. Must be a number.`);
432360
}
433361

434-
const reaction = validateReaction(reactionInput);
435362
const { owner, repo } = parseRepository();
436363

437364
// Create Octokit instance
438365
const octokit = new Octokit({ auth: githubToken });
439366

440-
// Step 1: Add reaction IMMEDIATELY to give user quick feedback
441-
core.info('👀 Adding reaction to comment for quick feedback...');
442-
await addReaction(octokit, owner, repo, commentId, eventName, reaction);
443-
444-
// Now start the actual processing
367+
// Note: Reaction is added in action.yml for immediate feedback
445368
core.info(`🎯 Starting PR Assistant for comment ${commentId}`);
446369
core.info(`📦 Repository: ${owner}/${repo}`);
447370
core.info(`📝 Event: ${eventName}`);

0 commit comments

Comments
 (0)