Skip to content

Commit 7e76449

Browse files
fix: clean up (#1)
1 parent ad3899f commit 7e76449

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ node_modules/
4343
jspm_packages/
4444

4545

46-
#
47-
src/
48-
4946
# Snowpack dependency directory (https://snowpack.dev/)
5047
web_modules/
5148

@@ -93,6 +90,7 @@ out
9390

9491
# Nuxt.js build / generate output
9592
.nuxt
93+
local-test/
9694

9795

9896
# Gatsby files

action.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'Hello World JS Action'
2-
description: 'Greet someone and record the time'
1+
name: 'PullPrompt'
2+
description: 'A GitHub Actions that comments on a pull request with a user given prompt and uses the Google Gemini API to generate a response'
33
author: "Pradumna Saraf"
44

55
inputs:
@@ -14,7 +14,6 @@ inputs:
1414
description: 'Your Gemini API Key'
1515
required: true
1616

17-
1817
runs:
1918
using: 'node20'
2019
main: 'dist/index.js'

src/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { getInput, setFailed } from "@actions/core";
2+
import { context, getOctokit } from "@actions/github";
3+
import { GoogleGenerativeAI } from "@google/generative-ai";
4+
5+
async function run() {
6+
try {
7+
const token = getInput("github-token", { required: true });
8+
const geminiApiKey = getInput("gemini-api-key", { required: true });
9+
const prompt = getInput("user-prompt");
10+
11+
const octokit = getOctokit(token);
12+
13+
if (context.payload.pull_request == null) {
14+
throw new Error("This action can only be run on pull_request events");
15+
}
16+
17+
const { owner, repo } = context.repo;
18+
const { number } = context.payload.pull_request;
19+
const commentBody = await geminiCall(geminiApiKey, prompt);
20+
await octokit.rest.issues.createComment({
21+
owner,
22+
repo,
23+
issue_number: number,
24+
body: commentBody,
25+
});
26+
} catch (error) {
27+
setFailed(error.message);
28+
}
29+
}
30+
31+
async function geminiCall(key, prompt) {
32+
try {
33+
const genAI = new GoogleGenerativeAI(key);
34+
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
35+
36+
const result = await model.generateContent(prompt);
37+
38+
return result.response.text();
39+
} catch (error) {
40+
setFailed("Error generating content with Gemini:", error);
41+
return "An error occurred while generating content.";
42+
}
43+
}
44+
45+
run();

0 commit comments

Comments
 (0)