Skip to content

Commit

Permalink
+ Add gemini input example
Browse files Browse the repository at this point in the history
  • Loading branch information
iletai committed Apr 5, 2024
1 parent d09874f commit 32d9dde
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 68 deletions.
58 changes: 24 additions & 34 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34685,67 +34685,57 @@ class GoogleGenerativeAI {



// Define the valid parity labels.
// Get Pull Request Number From Ref Revision
const getPullRequestNumber = (ref) => {
core.debug(`[GeminiAction] Parsing ref: ${ref}`);
// This assumes that the ref is in the form of `refs/pull/:prNumber/merge`
const prNumber = ref.replace(/refs\/pull\/(\d+)\/merge/, `$1`);
return parseInt(prNumber, 10);
};

const availableIssuesLabels = async (issuesNumber, owner, repo, octokit) => {
const {
data
} = await octokit.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: issuesNumber
});
if (data.length === 0) {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issuesNumber,
body: `:octopus: No Labels Found in this PR. Please add at least one of these labels: ${JSON.stringify(data.labels, null, 2)}`
});
return [];
}
// Return Data Map Lable and Avoid Undefine Labels
return data.map((label) => label.name).filter((label) => label !== undefined);
};

(async () => {
try {
const geminiModel = 'gemini-pro';
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const apiKey = core.getInput("gemini-api-key");
const githubToken = core.getInput("github-token");
const ref = github.context.ref;
const octokit = github.getOctokit(githubToken);
const pullRequestNumber = getPullRequestNumber(ref);
// Assigne Issues for Owner Repo
await octokit.rest.issues.addAssignees({
owner,
repo,
issue_number: github.context.issue.number,
assignees: [github.context.actor]
});

// Create branch base on this Issues and link it to issues.
await octokit.rest.git.createRef({
owner,
repo,
ref: `refs/heads/issue-${github.context.issue.number}`,
sha: github.context.sha
});
core.debug(`[GeminiAction] Ref: ${ref} : getPullRequestNumber(ref) => ${pullRequestNumber.number}`)
const prNumber = github.context.issue.number || getPullRequestNumber(ref);
const model = new GenerativeModel(apiKey, {
model: "gemini-pro",
model: geminiModel,
generationConfig: { temperature: 0 },
});
const availableIssuesLabels = async (issuesNumber) => {
const {
data
} = await octokit.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: issuesNumber
});
if (data.length === 0) {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issuesNumber,
body: `:octopus: No Labels Found in this PR. Please add at least one of these labels: ${JSON.stringify(data.labels, null, 2)}`
});
return [];
}
// Return Data Map Lable and Avoid Undefine Labels
return data.map((label) => label.name).filter((label) => label !== undefined);
};
core.debug(`[GeminiAction] Found PR number: ${github.context.issue.number}`);
const available = availableIssuesLabels(prNumber);
const available = await availableIssuesLabels(prNumber, owner, repo, octokit);
core.debug(`[GeminiAction] available number: ${available.number}`);
const issue = await octokit.rest.issues.get({
...github.context.issue,
Expand Down
58 changes: 24 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,57 @@ import * as core from "@actions/core";
import * as github from "@actions/github";
import { GenerativeModel } from "@google/generative-ai";

// Define the valid parity labels.
// Get Pull Request Number From Ref Revision
const getPullRequestNumber = (ref) => {
core.debug(`[GeminiAction] Parsing ref: ${ref}`);
// This assumes that the ref is in the form of `refs/pull/:prNumber/merge`
const prNumber = ref.replace(/refs\/pull\/(\d+)\/merge/, `$1`);
return parseInt(prNumber, 10);
};

const availableIssuesLabels = async (issuesNumber, owner, repo, octokit) => {
const {
data
} = await octokit.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: issuesNumber
});
if (data.length === 0) {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issuesNumber,
body: `:octopus: No Labels Found in this PR. Please add at least one of these labels: ${JSON.stringify(data.labels, null, 2)}`
});
return [];
}
// Return Data Map Lable and Avoid Undefine Labels
return data.map((label) => label.name).filter((label) => label !== undefined);
};

(async () => {
try {
const geminiModel = 'gemini-pro';
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const apiKey = core.getInput("gemini-api-key");
const githubToken = core.getInput("github-token");
const ref = github.context.ref;
const octokit = github.getOctokit(githubToken);
const pullRequestNumber = getPullRequestNumber(ref);
// Assigne Issues for Owner Repo
await octokit.rest.issues.addAssignees({
owner,
repo,
issue_number: github.context.issue.number,
assignees: [github.context.actor]
});

// Create branch base on this Issues and link it to issues.
await octokit.rest.git.createRef({
owner,
repo,
ref: `refs/heads/issue-${github.context.issue.number}`,
sha: github.context.sha
});
core.debug(`[GeminiAction] Ref: ${ref} : getPullRequestNumber(ref) => ${pullRequestNumber.number}`)
const prNumber = github.context.issue.number || getPullRequestNumber(ref);
const model = new GenerativeModel(apiKey, {
model: "gemini-pro",
model: geminiModel,
generationConfig: { temperature: 0 },
});
const availableIssuesLabels = async (issuesNumber) => {
const {
data
} = await octokit.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: issuesNumber
});
if (data.length === 0) {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issuesNumber,
body: `:octopus: No Labels Found in this PR. Please add at least one of these labels: ${JSON.stringify(data.labels, null, 2)}`
});
return [];
}
// Return Data Map Lable and Avoid Undefine Labels
return data.map((label) => label.name).filter((label) => label !== undefined);
};
core.debug(`[GeminiAction] Found PR number: ${github.context.issue.number}`);
const available = availableIssuesLabels(prNumber);
const available = await availableIssuesLabels(prNumber, owner, repo, octokit);
core.debug(`[GeminiAction] available number: ${available.number}`);
const issue = await octokit.rest.issues.get({
...github.context.issue,
Expand Down

0 comments on commit 32d9dde

Please sign in to comment.