Skip to content

Commit c677f16

Browse files
committed
mock octokit
1 parent 4d6aa15 commit c677f16

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

scripts/release/__tests__/createReleasePR.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { gitAuthor } from '../../../config/release.config.json';
2+
import * as common from '../../common';
23
import {
34
parseCommit,
45
getVersionChangesText,
@@ -25,7 +26,22 @@ const buildTestCommit = (
2526

2627
describe('createReleasePR', () => {
2728
beforeAll(() => {
28-
process.env.GITHUB_TOKEN = 'mocked';
29+
// Mock `getOctokit` to bypass the API call and credential requirements
30+
jest.spyOn(common, 'getOctokit').mockImplementation((): any => {
31+
return {
32+
search: {
33+
users: (): any => ({
34+
data: {
35+
total_count: 0,
36+
},
37+
}),
38+
},
39+
};
40+
});
41+
});
42+
43+
afterAll(() => {
44+
jest.spyOn(common, 'getOctokit').mockRestore();
2945
});
3046

3147
it('reads versions of the current language', () => {

scripts/release/__tests__/updateAPIVersions.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { getNextVersion } from '../createReleasePR';
22
import { getVersionsToRelease } from '../updateAPIVersions';
33

44
describe('updateAPIversions', () => {
5-
beforeAll(() => {
6-
process.env.GITHUB_TOKEN = 'mocked';
7-
});
8-
95
it('gets versions to release', () => {
106
const versions = getVersionsToRelease({
117
javascript: {

scripts/release/createReleasePR.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { updateAPIVersions } from './updateAPIVersions';
3535
dotenv.config({ path: ROOT_ENV_PATH });
3636

3737
export const COMMON_SCOPES = ['specs', 'clients'];
38-
const octokit = getOctokit();
3938

4039
// Prevent fetching the same user multiple times
4140
const fetchedUsers: Record<string, string> = {};
@@ -148,6 +147,7 @@ export async function parseCommit(commit: string): Promise<Commit> {
148147

149148
// Retrieve the author GitHub username if publicly available
150149
if (!fetchedUsers[authorEmail]) {
150+
const octokit = getOctokit();
151151
const { data } = await octokit.search.users({
152152
q: authorEmail,
153153
});
@@ -465,6 +465,7 @@ async function createReleasePR(): Promise<void> {
465465
await run(`git checkout ${MAIN_BRANCH}`, { verbose: true });
466466

467467
console.log('Creating prepare release pull request...');
468+
const octokit = getOctokit();
468469
const { data } = await octokit.pulls.create({
469470
owner: OWNER,
470471
repo: REPO,

0 commit comments

Comments
 (0)