File tree Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,6 @@ node_modules/
4343jspm_packages /
4444
4545
46- #
47- src /
48-
4946# Snowpack dependency directory (https://snowpack.dev/)
5047web_modules /
5148
9390
9491# Nuxt.js build / generate output
9592.nuxt
93+ local-test /
9694
9795
9896# Gatsby files
Original file line number Diff line number Diff line change 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 '
33author : " Pradumna Saraf"
44
55inputs :
@@ -14,7 +14,6 @@ inputs:
1414 description : ' Your Gemini API Key'
1515 required : true
1616
17-
1817runs :
1918 using : ' node20'
2019 main : ' dist/index.js'
Original file line number Diff line number Diff line change 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 ( ) ;
You can’t perform that action at this time.
0 commit comments