Skip to content

Commit f5e9b9d

Browse files
committed
event_name is no longer input and workflow run event supported
1 parent ac08e9b commit f5e9b9d

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

action.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ inputs:
99
github_token:
1010
description: 'GitHub token for API access'
1111
required: true
12-
event_name:
13-
description: 'The GitHub event name (pull_request, pull_request_review_comment, or issue_comment)'
14-
required: true
1512
prompt:
1613
description: 'The prompt to send to Auggie agent'
1714
required: true
@@ -54,11 +51,11 @@ runs:
5451
shell: bash
5552
env:
5653
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
57-
INPUT_EVENT_NAME: ${{ inputs.event_name }}
5854
INPUT_PROMPT: ${{ inputs.prompt }}
5955
INPUT_AUGMENT_API_KEY: ${{ inputs.augment_api_key }}
6056
INPUT_AUGMENT_API_URL: ${{ inputs.augment_api_url }}
6157
INPUT_WORKSPACE_ROOT: ${{ inputs.workspace_root }}
6258
GITHUB_REPOSITORY: ${{ github.repository }}
59+
GITHUB_EVENT_NAME: ${{ github.event_name }}
6360
GITHUB_STEP_SUMMARY: ${{ env.GITHUB_STEP_SUMMARY }}
6461

src/utils/index.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2-
import { getInput, parseRepository } from "./index";
2+
import { getInput, parseRepository, getEventName } from "./index";
33

44
describe("getInput", () => {
55
const originalEnv = process.env;
@@ -127,3 +127,46 @@ describe("parseRepository", () => {
127127
expect(result).toEqual({ owner: "owner", repo: "repo" });
128128
});
129129
});
130+
131+
describe("getEventName", () => {
132+
const originalEnv = process.env;
133+
134+
beforeEach(() => {
135+
// Reset environment before each test
136+
process.env = { ...originalEnv };
137+
});
138+
139+
afterEach(() => {
140+
// Restore original environment after each test
141+
process.env = originalEnv;
142+
});
143+
144+
test("should get event name from GITHUB_EVENT_NAME", () => {
145+
process.env.GITHUB_EVENT_NAME = "pull_request";
146+
expect(getEventName()).toBe("pull_request");
147+
});
148+
149+
test("should get workflow_run event name", () => {
150+
process.env.GITHUB_EVENT_NAME = "workflow_run";
151+
expect(getEventName()).toBe("workflow_run");
152+
});
153+
154+
test("should get issue_comment event name", () => {
155+
process.env.GITHUB_EVENT_NAME = "issue_comment";
156+
expect(getEventName()).toBe("issue_comment");
157+
});
158+
159+
test("should throw error when GITHUB_EVENT_NAME is not set", () => {
160+
process.env.GITHUB_EVENT_NAME = undefined;
161+
expect(() => getEventName()).toThrow(
162+
"GITHUB_EVENT_NAME environment variable not found"
163+
);
164+
});
165+
166+
test("should throw error when GITHUB_EVENT_NAME is empty", () => {
167+
process.env.GITHUB_EVENT_NAME = "";
168+
expect(() => getEventName()).toThrow(
169+
"GITHUB_EVENT_NAME environment variable not found"
170+
);
171+
});
172+
});

src/utils/index.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,37 @@ type ReactToCommentParams = {
9898
eventName: string;
9999
};
100100

101+
// Event types that support comment reactions
102+
const COMMENT_EVENT_TYPES = [
103+
"issue_comment",
104+
"pull_request_review_comment",
105+
] as const;
106+
107+
type CommentEventType = (typeof COMMENT_EVENT_TYPES)[number];
108+
109+
function isCommentEvent(eventName: string): eventName is CommentEventType {
110+
return COMMENT_EVENT_TYPES.includes(eventName as CommentEventType);
111+
}
112+
101113
/**
102114
* React to a comment with an emoji
103115
* Extracts comment ID from event payload and reacts if present
116+
* Gracefully skips for non-comment events (e.g., workflow_run, pull_request)
104117
*/
105118
export async function reactToComment({
106119
octokit,
107120
owner,
108121
repo,
109122
eventName,
110123
}: ReactToCommentParams): Promise<void> {
124+
// Skip reaction for non-comment events
125+
if (!isCommentEvent(eventName)) {
126+
core.info(
127+
`ℹ️ Event type '${eventName}' does not support comment reactions, skipping`,
128+
);
129+
return;
130+
}
131+
111132
// Extract comment_id from GitHub event payload
112133
const commentId = getCommentIdFromEvent();
113134

@@ -136,8 +157,6 @@ export async function reactToComment({
136157
comment_id: commentId,
137158
content: "eyes",
138159
});
139-
} else {
140-
throw new Error(`Unsupported event type: ${eventName}`);
141160
}
142161

143162
core.info(`✅ Successfully added :eyes: reaction to comment ${commentId}`);
@@ -153,9 +172,20 @@ type AuggieParams = {
153172
commentBody: string | undefined;
154173
};
155174

175+
/**
176+
* Get the GitHub event name from environment variable
177+
*/
178+
export function getEventName(): string {
179+
const eventName = process.env.GITHUB_EVENT_NAME;
180+
if (!eventName) {
181+
throw new Error("GITHUB_EVENT_NAME environment variable not found");
182+
}
183+
return eventName;
184+
}
185+
156186
export function getAuggieParams(): AuggieParams {
157187
const githubToken = getInput("github_token", true);
158-
const eventName = getInput("event_name", true);
188+
const eventName = getEventName();
159189
const prompt = getInput("prompt", true);
160190
const augmentApiKey = getInput("augment_api_key", true);
161191
const augmentApiUrl = getInput("augment_api_url", true);

0 commit comments

Comments
 (0)