Skip to content

Commit a8d9aa6

Browse files
committed
apply changes from suggestion
1 parent 8f3272a commit a8d9aa6

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

scripts/ci/codegen/cleanGeneratedBranch.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/* eslint-disable no-console */
22
import { run } from '../../common';
33

4-
import { branchExists } from './common';
5-
64
/**
7-
* Deletes a branch for it's `generated/headRef` name on origin.
5+
* Deletes a branch for it's `generated/${headRef}` name on origin.
86
*
97
* @param headRef - The name of the branch to search for.
108
*/
@@ -15,19 +13,17 @@ export async function cleanGeneratedBranch(headRef?: string): Promise<void> {
1513

1614
const generatedCodeBranch = `generated/${process.env.HEAD_REF || headRef}`;
1715

18-
if (!(await branchExists(generatedCodeBranch))) {
16+
if (!(await run(`git ls-remote --heads origin ${generatedCodeBranch}`))) {
1917
console.log(`No branch named '${generatedCodeBranch}' was found.`);
2018

2119
return;
2220
}
2321

2422
// Delete previous generations to avoid conflicts and out of date code
25-
if (await branchExists(generatedCodeBranch)) {
26-
console.log(`Deleting generated branch: '${generatedCodeBranch}'`);
23+
console.log(`Deleting generated branch: '${generatedCodeBranch}'`);
2724

28-
await run(`git fetch origin ${generatedCodeBranch}`);
29-
await run(`git push -d origin ${generatedCodeBranch}`);
30-
}
25+
await run(`git fetch origin ${generatedCodeBranch}`);
26+
await run(`git push -d origin ${generatedCodeBranch}`);
3127
}
3228

3329
if (process.env.HEAD_REF) {

scripts/ci/codegen/common.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/ci/codegen/pushGeneratedCode.ts

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

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

77
import { cleanGeneratedBranch } from './cleanGeneratedBranch';
88

@@ -12,7 +12,6 @@ if (!process.env.GITHUB_TOKEN) {
1212

1313
const PR_NUMBER = parseInt(process.env.PR_NUMBER || '0', 10);
1414
const FOLDERS_TO_CHECK = ['clients', 'specs/bundled'];
15-
const REPOSITORY_URL = `https://github.com/algolia/api-clients-automation`;
1615
// this should be changed to the bot name once we have the logs
1716
const BOT_NAME = 'shortcuts';
1817

@@ -21,9 +20,10 @@ const octokit = new Octokit({
2120
});
2221

2322
async function getCommentBody(commit: string, branch: string): Promise<string> {
23+
const repoUrl = `https://github.com/${OWNER}/${REPO}`;
2424
const generatedCommit = await run('git show -s --format=%H');
25-
const header = `✔️ codegen triggered on commit [${commit}](${REPOSITORY_URL}/pull/${PR_NUMBER}/commits/${commit}).`;
26-
const body = `🔍 Browse the generated code on branch [${branch}](${REPOSITORY_URL}/tree/${branch}): [${generatedCommit}](${REPOSITORY_URL}/commit/${generatedCommit}).`;
25+
const header = `✔️ codegen triggered on commit [${commit}](${repoUrl}/pull/${PR_NUMBER}/commits/${commit}).`;
26+
const body = `🔍 Browse the generated code on branch [${branch}](${repoUrl}/tree/${branch}): [${generatedCommit}](${repoUrl}/commit/${generatedCommit}).`;
2727

2828
return `${header}
2929
@@ -33,13 +33,13 @@ ${body}`;
3333
/**
3434
* Add or update comment to the current `PR_NUMBER`.
3535
*/
36-
async function addCommentToPullRequest(
36+
async function upsertCommentToPullRequest(
3737
baseCommit: string,
3838
generatedCodeBranch: string
3939
): Promise<void> {
4040
const baseOctokitConfig = {
41-
owner: 'algolia',
42-
repo: 'api-clients-automation',
41+
owner: OWNER,
42+
repo: REPO,
4343
issue_number: PR_NUMBER,
4444
};
4545

@@ -126,7 +126,7 @@ Co-authored-by: %an <%ae>"`);
126126
await run(`git push origin ${generatedCodeBranch}`);
127127

128128
if (PR_NUMBER) {
129-
await addCommentToPullRequest(baseCommit, generatedCodeBranch);
129+
await upsertCommentToPullRequest(baseCommit, generatedCodeBranch);
130130
}
131131
}
132132

scripts/release/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export function getMarkdownSection(markdown: string, title: string): string {
3131
}
3232

3333
export async function configureGitHubAuthor(cwd?: string): Promise<void> {
34-
await run(`git config user.name "${getGitAuthor().name}"`, { cwd });
35-
await run(`git config user.email "${getGitAuthor().email}"`, {
36-
cwd,
37-
});
34+
const { name, email } = getGitAuthor();
35+
36+
await run(`git config user.name "${name}"`, { cwd });
37+
await run(`git config user.email "${email}"`, { cwd });
3838
}

0 commit comments

Comments
 (0)