Skip to content

Commit e7f5ea9

Browse files
committed
use separate client for branch and pull operations
1 parent 66ddf90 commit e7f5ea9

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

dist/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,9 @@ function createPullRequest(inputs) {
356356
core.endGroup();
357357
core.startGroup('Determining the base and head repositories');
358358
const baseRemote = gitConfigHelper.getGitRemote();
359-
// Init the GitHub client
360-
const githubHelper = new github_helper_1.GitHubHelper(baseRemote.hostname, inputs.token);
359+
// Init the GitHub clients
360+
const ghBranch = new github_helper_1.GitHubHelper(baseRemote.hostname, inputs.gitToken);
361+
const ghPull = new github_helper_1.GitHubHelper(baseRemote.hostname, inputs.token);
361362
// Determine the head repository; the target for the pull request branch
362363
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin';
363364
const branchRepository = inputs.pushToFork
@@ -366,8 +367,8 @@ function createPullRequest(inputs) {
366367
if (inputs.pushToFork) {
367368
// Check if the supplied fork is really a fork of the base
368369
core.info(`Checking if '${branchRepository}' is a fork of '${baseRemote.repository}'`);
369-
const baseParentRepository = yield githubHelper.getRepositoryParent(baseRemote.repository);
370-
const branchParentRepository = yield githubHelper.getRepositoryParent(branchRepository);
370+
const baseParentRepository = yield ghBranch.getRepositoryParent(baseRemote.repository);
371+
const branchParentRepository = yield ghBranch.getRepositoryParent(branchRepository);
371372
if (branchParentRepository == null) {
372373
throw new Error(`Repository '${branchRepository}' is not a fork. Unable to continue.`);
373374
}
@@ -469,7 +470,7 @@ function createPullRequest(inputs) {
469470
// Create signed commits via the GitHub API
470471
const stashed = yield git.stashPush(['--include-untracked']);
471472
yield git.checkout(inputs.branch);
472-
const pushSignedCommitsResult = yield githubHelper.pushSignedCommits(result.branchCommits, result.baseSha, repoPath, branchRepository, inputs.branch);
473+
const pushSignedCommitsResult = yield ghBranch.pushSignedCommits(result.branchCommits, result.baseSha, repoPath, branchRepository, inputs.branch);
473474
outputs.set('pull-request-head-sha', pushSignedCommitsResult.sha);
474475
outputs.set('pull-request-commits-verified', pushSignedCommitsResult.verified.toString());
475476
yield git.checkout('-');
@@ -488,7 +489,7 @@ function createPullRequest(inputs) {
488489
}
489490
if (result.hasDiffWithBase) {
490491
core.startGroup('Create or update the pull request');
491-
const pull = yield githubHelper.createOrUpdatePullRequest(inputs, baseRemote.repository, branchRepository);
492+
const pull = yield ghPull.createOrUpdatePullRequest(inputs, baseRemote.repository, branchRepository);
492493
outputs.set('pull-request-number', pull.number.toString());
493494
outputs.set('pull-request-url', pull.html_url);
494495
if (pull.created) {

src/create-pull-request.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
4646

4747
core.startGroup('Determining the base and head repositories')
4848
const baseRemote = gitConfigHelper.getGitRemote()
49-
// Init the GitHub client
50-
const githubHelper = new GitHubHelper(baseRemote.hostname, inputs.token)
49+
// Init the GitHub clients
50+
const ghBranch = new GitHubHelper(baseRemote.hostname, inputs.gitToken)
51+
const ghPull = new GitHubHelper(baseRemote.hostname, inputs.token)
5152
// Determine the head repository; the target for the pull request branch
5253
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin'
5354
const branchRepository = inputs.pushToFork
@@ -58,11 +59,11 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
5859
core.info(
5960
`Checking if '${branchRepository}' is a fork of '${baseRemote.repository}'`
6061
)
61-
const baseParentRepository = await githubHelper.getRepositoryParent(
62+
const baseParentRepository = await ghBranch.getRepositoryParent(
6263
baseRemote.repository
6364
)
6465
const branchParentRepository =
65-
await githubHelper.getRepositoryParent(branchRepository)
66+
await ghBranch.getRepositoryParent(branchRepository)
6667
if (branchParentRepository == null) {
6768
throw new Error(
6869
`Repository '${branchRepository}' is not a fork. Unable to continue.`
@@ -207,7 +208,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
207208
// Create signed commits via the GitHub API
208209
const stashed = await git.stashPush(['--include-untracked'])
209210
await git.checkout(inputs.branch)
210-
const pushSignedCommitsResult = await githubHelper.pushSignedCommits(
211+
const pushSignedCommitsResult = await ghBranch.pushSignedCommits(
211212
result.branchCommits,
212213
result.baseSha,
213214
repoPath,
@@ -235,7 +236,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
235236

236237
if (result.hasDiffWithBase) {
237238
core.startGroup('Create or update the pull request')
238-
const pull = await githubHelper.createOrUpdatePullRequest(
239+
const pull = await ghPull.createOrUpdatePullRequest(
239240
inputs,
240241
baseRemote.repository,
241242
branchRepository

0 commit comments

Comments
 (0)