Skip to content

Commit 3239ac8

Browse files
committed
chore: extract octokit generation
1 parent 097026e commit 3239ac8

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

scripts/ci/codegen/upsertGenerationComment.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
import { Octokit } from '@octokit/rest';
33

44
import { run } from '../../common';
5-
import { OWNER, REPO } from '../../release/common';
5+
import { getOctokit, OWNER, REPO } from '../../release/common';
66

77
import commentText from './text';
88

99
const BOT_NAME = 'algolia-bot';
1010
const PR_NUMBER = parseInt(process.env.PR_NUMBER || '0', 10);
11-
const octokit = new Octokit({
12-
auth: `token ${process.env.GITHUB_TOKEN}`,
13-
});
11+
const octokit = getOctokit(process.env.GITHUB_TOKEN!);
1412

1513
const args = process.argv.slice(2);
1614
const allowedTriggers = ['notification', 'codegen', 'noGen', 'cleanup'];

scripts/release/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import path from 'path';
22

3+
import { Octokit } from '@octokit/rest';
4+
35
import clientsConfig from '../../config/clients.config.json';
46
import config from '../../config/release.config.json';
57
import { getGitHubUrl, run } from '../common';
@@ -19,6 +21,12 @@ export const MAIN_PACKAGE = Object.keys(clientsConfig).reduce(
1921
{}
2022
);
2123

24+
export function getOctokit(githubToken: string): Octokit {
25+
return new Octokit({
26+
auth: `token ${githubToken}`,
27+
});
28+
}
29+
2230
export function getTargetBranch(language: string): string {
2331
return config.targetBranch[language] || config.defaultTargetBranch;
2432
}

scripts/release/create-release-issue.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import semver from 'semver';
66
import { LANGUAGES, ROOT_ENV_PATH, run, getPackageVersion } from '../common';
77
import type { Language } from '../types';
88

9-
import { RELEASED_TAG, MAIN_BRANCH, OWNER, REPO, MAIN_PACKAGE } from './common';
9+
import {
10+
RELEASED_TAG,
11+
MAIN_BRANCH,
12+
OWNER,
13+
REPO,
14+
MAIN_PACKAGE,
15+
getOctokit,
16+
} from './common';
1017
import TEXT from './text';
1118
import type {
1219
Versions,
@@ -246,9 +253,7 @@ async function createReleaseIssue(): Promise<void> {
246253
TEXT.approval,
247254
].join('\n\n');
248255

249-
const octokit = new Octokit({
250-
auth: `token ${process.env.GITHUB_TOKEN}`,
251-
});
256+
const octokit = getOctokit(process.env.GITHUB_TOKEN!);
252257

253258
octokit.rest.issues
254259
.create({

scripts/release/process-release.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ import {
2828
getMarkdownSection,
2929
configureGitHubAuthor,
3030
cloneRepository,
31+
getOctokit,
3132
} from './common';
3233
import TEXT from './text';
3334
import type { VersionsToRelease } from './types';
3435

3536
dotenv.config({ path: ROOT_ENV_PATH });
3637

37-
const octokit = new Octokit({
38-
auth: `token ${process.env.GITHUB_TOKEN}`,
39-
});
40-
4138
type BeforeClientGenerationCommand = (params: {
4239
releaseType: ReleaseType;
4340
dir: string;
@@ -52,6 +49,7 @@ const BEFORE_CLIENT_GENERATION: {
5249
};
5350

5451
async function getIssueBody(): Promise<string> {
52+
const octokit = getOctokit(process.env.GITHUB_TOKEN!);
5553
const {
5654
data: { body },
5755
} = await octokit.rest.issues.get({
@@ -163,6 +161,7 @@ async function updateChangelog({
163161
}
164162

165163
async function isAuthorizedRelease(): Promise<boolean> {
164+
const octokit = getOctokit(process.env.GITHUB_TOKEN!);
166165
const { data: members } = await octokit.rest.teams.listMembersInOrg({
167166
org: OWNER,
168167
team_slug: TEAM_SLUG,

0 commit comments

Comments
 (0)