Skip to content

Commit d8ad0b7

Browse files
thePunderWomanjosephperrott
authored andcommitted
refactor(github-actions): Update dependency to use google/genai instead of deprecated one
No more deprecated package.
1 parent 2167290 commit d8ad0b7

7 files changed

Lines changed: 44649 additions & 5492 deletions

File tree

github-actions/issue-labeling/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ts_project(
1515
deps = [
1616
":node_modules/@actions/core",
1717
":node_modules/@actions/github",
18-
":node_modules/@google/generative-ai",
18+
":node_modules/@google/genai",
1919
":node_modules/@octokit/openapi-types",
2020
":node_modules/@octokit/rest",
2121
":node_modules/@types/node",
@@ -32,7 +32,7 @@ ts_project(
3232
":lib",
3333
":node_modules/@actions/core",
3434
":node_modules/@actions/github",
35-
":node_modules/@google/generative-ai",
35+
":node_modules/@google/genai",
3636
":node_modules/@octokit/openapi-types",
3737
":node_modules/@octokit/rest",
3838
":node_modules/@types/jasmine",

github-actions/issue-labeling/lib/issue-labeling.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core';
22
import {context} from '@actions/github';
3-
import {GoogleGenerativeAI} from '@google/generative-ai';
3+
import {GoogleGenAI} from '@google/genai';
44
import {Octokit} from '@octokit/rest';
55
import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js';
66
import {components} from '@octokit/openapi-types';
@@ -38,7 +38,7 @@ export class IssueLabeling {
3838
// Initialize labels and issue data
3939
await this.initialize();
4040

41-
const model = this.getGenerativeModel();
41+
const ai = this.getGenerativeAI();
4242

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

6363
try {
64-
const result = await model.generateContent(prompt);
65-
const response = result.response;
66-
const text = response.text().trim();
64+
const response = await ai.models.generateContent({
65+
model: 'gemini-2.0-flash',
66+
contents: prompt,
67+
});
68+
const text = (response.text || '').trim();
6769

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

@@ -80,10 +82,9 @@ If no area label applies, respond with "none".
8082
}
8183
}
8284

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

8990
async addLabel(label: string) {

github-actions/issue-labeling/lib/main.spec.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Octokit} from '@octokit/rest';
22
import * as core from '@actions/core';
33
import {context} from '@actions/github';
4-
import {GenerativeModel} from '@google/generative-ai';
4+
import {GoogleGenAI} from '@google/genai';
55
import {IssueLabeling} from './issue-labeling.js';
66

77
describe('IssueLabeling', () => {
@@ -13,7 +13,7 @@ describe('IssueLabeling', () => {
1313
get: jasmine.Spy;
1414
};
1515
};
16-
let mockModel: jasmine.SpyObj<GenerativeModel>;
16+
let mockAI: any;
1717
let mockCore: jasmine.SpyObj<typeof core>;
1818
let issueLabeling: IssueLabeling;
1919

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

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

64-
spyOn(issueLabeling, 'getGenerativeModel').and.returnValue(mockModel);
66+
spyOn(issueLabeling, 'getGenerativeAI').and.returnValue(mockAI);
6567
});
6668

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

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

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

9292
it('should NOT apply a label when Gemini returns "ambiguous"', async () => {
93-
mockModel.generateContent.and.returnValue(
93+
mockAI.models.generateContent.and.returnValue(
9494
Promise.resolve({
95-
response: {
96-
text: () => 'ambiguous',
97-
} as any,
95+
text: 'ambiguous',
9896
}),
9997
);
10098

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

106104
it('should NOT apply a label when Gemini returns an invalid label', async () => {
107-
mockModel.generateContent.and.returnValue(
105+
mockAI.models.generateContent.and.returnValue(
108106
Promise.resolve({
109-
response: {
110-
text: () => 'area: invalid',
111-
} as any,
107+
text: 'area: invalid',
112108
}),
113109
);
114110

0 commit comments

Comments
 (0)