Skip to content

Commit 7dd5dbb

Browse files
committed
refactor(github-actions): move constructor of IssueLabeling to protected (#3456)
PR Close #3456
1 parent 9cc4778 commit 7dd5dbb

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class IssueLabeling {
2323
/** The issue data fetched from Github. */
2424
issueData?: components['schemas']['issue'];
2525

26-
constructor(
26+
protected constructor(
2727
private git: Octokit,
2828
private coreService: typeof core,
2929
) {}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import {context} from '@actions/github';
44
import {GoogleGenAI} from '@google/genai';
55
import {IssueLabeling} from './issue-labeling.js';
66

7+
class TestableIssueLabeling extends IssueLabeling {
8+
public constructor(git: Octokit, coreService: typeof core) {
9+
super(git, coreService);
10+
}
11+
}
12+
713
describe('IssueLabeling', () => {
814
let mockGit: {
915
paginate: jasmine.Spy;
@@ -37,10 +43,7 @@ describe('IssueLabeling', () => {
3743
},
3844
}),
3945
);
40-
mockGit.paginate.and.callFake((fn: any, opts: any) => {
41-
// Return value matching listLabelsForRepo signature
42-
return Promise.resolve([{name: 'area: core'}, {name: 'area: router'}, {name: 'bug'}]);
43-
});
46+
mockGit.paginate.and.resolveTo([{name: 'area: core'}, {name: 'area: router'}, {name: 'bug'}]);
4447

4548
mockAI = {
4649
models: jasmine.createSpyObj('models', ['generateContent']),
@@ -60,9 +63,10 @@ describe('IssueLabeling', () => {
6063
mockCore.debug.and.callFake(console.debug);
6164
mockCore.setFailed.and.callFake(console.error);
6265

66+
6367
// We must cast the mock to Octokit because the mock only implements the subset used by the class.
6468
// This is standard for mocking large interfaces like Octokit.
65-
issueLabeling = new IssueLabeling(mockGit as unknown as Octokit, mockCore);
69+
issueLabeling = new TestableIssueLabeling(mockGit as unknown as Octokit, mockCore);
6670

6771
spyOn(issueLabeling, 'getGenerativeAI').and.returnValue(mockAI);
6872
});

0 commit comments

Comments
 (0)