Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions github-actions/issue-labeling/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ts_project(
deps = [
":node_modules/@actions/core",
":node_modules/@actions/github",
":node_modules/@google/generative-ai",
":node_modules/@google/genai",
":node_modules/@octokit/openapi-types",
":node_modules/@octokit/rest",
":node_modules/@types/node",
Expand All @@ -32,7 +32,7 @@ ts_project(
":lib",
":node_modules/@actions/core",
":node_modules/@actions/github",
":node_modules/@google/generative-ai",
":node_modules/@google/genai",
":node_modules/@octokit/openapi-types",
":node_modules/@octokit/rest",
":node_modules/@types/jasmine",
Expand Down
17 changes: 9 additions & 8 deletions github-actions/issue-labeling/lib/issue-labeling.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import {context} from '@actions/github';
import {GoogleGenerativeAI} from '@google/generative-ai';
import {GoogleGenAI} from '@google/genai';
import {Octokit} from '@octokit/rest';
import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js';
import {components} from '@octokit/openapi-types';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class IssueLabeling {
// Initialize labels and issue data
await this.initialize();

const model = this.getGenerativeModel();
const ai = this.getGenerativeAI();

const prompt = `
You are a helper for an open source repository.
Expand All @@ -61,9 +61,11 @@ If no area label applies, respond with "none".
`;

try {
const result = await model.generateContent(prompt);
const response = result.response;
const text = response.text().trim();
const response = await ai.models.generateContent({
model: 'gemini-2.0-flash',
contents: prompt,
});
const text = (response.text || '').trim();

this.coreService.info(`Gemini suggested label: ${text}`);

Expand All @@ -80,10 +82,9 @@ If no area label applies, respond with "none".
}
}

getGenerativeModel() {
getGenerativeAI() {
const apiKey = this.coreService.getInput('google-generative-ai-key', {required: true});
const genAI = new GoogleGenerativeAI(apiKey);
return genAI.getGenerativeModel({model: 'gemini-2.0-flash'});
return new GoogleGenAI({apiKey});
}

async addLabel(label: string) {
Expand Down
28 changes: 12 additions & 16 deletions github-actions/issue-labeling/lib/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Octokit} from '@octokit/rest';
import * as core from '@actions/core';
import {context} from '@actions/github';
import {GenerativeModel} from '@google/generative-ai';
import {GoogleGenAI} from '@google/genai';
import {IssueLabeling} from './issue-labeling.js';

describe('IssueLabeling', () => {
Expand All @@ -13,7 +13,7 @@ describe('IssueLabeling', () => {
get: jasmine.Spy;
};
};
let mockModel: jasmine.SpyObj<GenerativeModel>;
let mockAI: any;
let mockCore: jasmine.SpyObj<typeof core>;
let issueLabeling: IssueLabeling;

Expand Down Expand Up @@ -41,7 +41,9 @@ describe('IssueLabeling', () => {
return Promise.resolve([{name: 'area: core'}, {name: 'area: router'}, {name: 'bug'}]);
});

mockModel = jasmine.createSpyObj<GenerativeModel>('GenerativeModel', ['generateContent']);
mockAI = {
models: jasmine.createSpyObj('models', ['generateContent']),
};
mockCore = jasmine.createSpyObj<typeof core>('core', [
'getInput',
'info',
Expand All @@ -61,7 +63,7 @@ describe('IssueLabeling', () => {
// This is standard for mocking large interfaces like Octokit.
issueLabeling = new IssueLabeling(mockGit as unknown as Octokit, mockCore);

spyOn(issueLabeling, 'getGenerativeModel').and.returnValue(mockModel);
spyOn(issueLabeling, 'getGenerativeAI').and.returnValue(mockAI);
});

it('should initialize labels correctly', async () => {
Expand All @@ -72,11 +74,9 @@ describe('IssueLabeling', () => {
});

it('should apply a label when Gemini is confident', async () => {
mockModel.generateContent.and.returnValue(
mockAI.models.generateContent.and.returnValue(
Promise.resolve({
response: {
text: () => 'area: core',
} as any, // Cast response structure as any because it's deeply nested and hard to construct manually
text: 'area: core',
}),
);

Expand All @@ -90,11 +90,9 @@ describe('IssueLabeling', () => {
});

it('should NOT apply a label when Gemini returns "ambiguous"', async () => {
mockModel.generateContent.and.returnValue(
mockAI.models.generateContent.and.returnValue(
Promise.resolve({
response: {
text: () => 'ambiguous',
} as any,
text: 'ambiguous',
}),
);

Expand All @@ -104,11 +102,9 @@ describe('IssueLabeling', () => {
});

it('should NOT apply a label when Gemini returns an invalid label', async () => {
mockModel.generateContent.and.returnValue(
mockAI.models.generateContent.and.returnValue(
Promise.resolve({
response: {
text: () => 'area: invalid',
} as any,
text: 'area: invalid',
}),
);

Expand Down
Loading