Fix Bug Workflow #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Using Gemini Action In WorkFlows. | |
on: | |
issues: | |
types: [opened, edited] | |
jobs: | |
example_gemini: | |
name: Example Usable | |
runs-on: macos-latest | |
steps: | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn config get cacheFolder)" | |
- name: Cache yarn dependencies | |
id: checkout | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Cache npm dependencies | |
uses: actions/cache@v4 | |
with: | |
path: '~/.npm' | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
- name: Install NPM dependencies | |
run: npm i @google/generative-ai | |
- name: Using Scripts | |
id: scriptgemini | |
uses: actions/github-script@v7 | |
continue-on-error: true | |
env: | |
APIKEY: ${{ secrets.GEMINI_API_KEY }} | |
with: | |
script: | | |
const modelName = { | |
model: ["gemini-pro"], | |
generationConfig: { temperature: 0 }, | |
}; | |
const { GenerativeModel } = require("@google/generative-ai"); | |
const model = new GenerativeModel(process.env.APIKEY, modelName); | |
const { data: availableLabels } = await github.rest.issues.listLabelsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.issue.number, | |
}); | |
const prompt = ` | |
You have a role to manage a GitHub repository. Given an issue information (subject and body), choose suitable labels to it from the labels available for the repository. | |
Use the following format: | |
LABELS: "the names of the chosen labels, each name must not be surrounded double quotes, separated by a comma" | |
Only use the following labels: | |
\`\`\` | |
${availableLabels.map((label) => label.name).join(", ")} | |
\`\`\` | |
## ISSUE ## | |
SUBJECT: ${context.payload.issue.title} | |
BODY: ${context.payload.issue.body} | |
`; | |
const result = await model.generateContent(prompt); | |
const labels = /LABELS\: (.+)/g.exec(result.response.text()); | |
const label = labels[1].trim().split(/,\s*/); | |
return label | |
- name: Add Labels | |
uses: actions/github-script@v7 | |
env: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
RESULT_GEMINI: ${{ steps.scriptgemini.outputs.result }} | |
with: | |
script: | | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.issue.number, | |
body: `The labels are ${JSON.parse(process.env.RESULT_GEMINI)}` | |
}); | |
await github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: JSON.parse(process.env.RESULT_GEMINI) | |
}); | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.issue.number, | |
state: "closed" | |
}); | |