Skip to content

Commit bd72e1b

Browse files
authored
fix: use full name for head branch to allow for repo renaming (#1164)
1 parent f1a7646 commit bd72e1b

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

dist/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,11 @@ class GitHubHelper {
950950
repo: repo
951951
};
952952
}
953-
createOrUpdate(inputs, baseRepository, headBranch) {
953+
createOrUpdate(inputs, baseRepository, headRepository) {
954954
return __awaiter(this, void 0, void 0, function* () {
955+
const [headOwner] = headRepository.split('/');
956+
const headBranch = `${headOwner}:${inputs.branch}`;
957+
const headBranchFull = `${headRepository}:${inputs.branch}`;
955958
// Try to create the pull request
956959
try {
957960
core.info(`Attempting creation of pull request`);
@@ -974,7 +977,7 @@ class GitHubHelper {
974977
}
975978
// Update the pull request that exists for this branch and base
976979
core.info(`Fetching existing pull request`);
977-
const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base }));
980+
const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranchFull, base: inputs.base }));
978981
core.info(`Attempting update of pull request`);
979982
const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number, title: inputs.title, body: inputs.body }));
980983
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
@@ -996,10 +999,8 @@ class GitHubHelper {
996999
}
9971000
createOrUpdatePullRequest(inputs, baseRepository, headRepository) {
9981001
return __awaiter(this, void 0, void 0, function* () {
999-
const [headOwner] = headRepository.split('/');
1000-
const headBranch = `${headOwner}:${inputs.branch}`;
10011002
// Create or update the pull request
1002-
const pull = yield this.createOrUpdate(inputs, baseRepository, headBranch);
1003+
const pull = yield this.createOrUpdate(inputs, baseRepository, headRepository);
10031004
// Apply milestone
10041005
if (inputs.milestone) {
10051006
core.info(`Applying milestone '${inputs.milestone}'`);

src/github-helper.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ export class GitHubHelper {
3939
private async createOrUpdate(
4040
inputs: Inputs,
4141
baseRepository: string,
42-
headBranch: string
42+
headRepository: string
4343
): Promise<Pull> {
44+
const [headOwner] = headRepository.split('/')
45+
const headBranch = `${headOwner}:${inputs.branch}`
46+
const headBranchFull = `${headRepository}:${inputs.branch}`
47+
4448
// Try to create the pull request
4549
try {
4650
core.info(`Attempting creation of pull request`)
@@ -76,7 +80,7 @@ export class GitHubHelper {
7680
const {data: pulls} = await this.octokit.rest.pulls.list({
7781
...this.parseRepository(baseRepository),
7882
state: 'open',
79-
head: headBranch,
83+
head: headBranchFull,
8084
base: inputs.base
8185
})
8286
core.info(`Attempting update of pull request`)
@@ -113,11 +117,12 @@ export class GitHubHelper {
113117
baseRepository: string,
114118
headRepository: string
115119
): Promise<Pull> {
116-
const [headOwner] = headRepository.split('/')
117-
const headBranch = `${headOwner}:${inputs.branch}`
118-
119120
// Create or update the pull request
120-
const pull = await this.createOrUpdate(inputs, baseRepository, headBranch)
121+
const pull = await this.createOrUpdate(
122+
inputs,
123+
baseRepository,
124+
headRepository
125+
)
121126

122127
// Apply milestone
123128
if (inputs.milestone) {

0 commit comments

Comments
 (0)