Skip to content

Commit b03b402

Browse files
sinchangjakebolam
authored andcommitted
feat: create pull request on the default branches (#46)
1 parent bc42436 commit b03b402

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/Repository/index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ class Repository {
6161
return multipleFilesByPath
6262
}
6363

64-
async getHeadRef() {
64+
async getHeadRef(defaultBranch) {
6565
const result = await this.github.git.getRef({
6666
owner: this.owner,
6767
repo: this.repo,
68-
ref: `heads/master`,
68+
ref: `heads/${defaultBranch}`,
6969
})
7070
return result.data.object.sha
7171
}
7272

73-
async createBranch(branchName) {
74-
const fromSha = await this.getHeadRef()
73+
async createBranch({ branchName, defaultBranch }) {
74+
const fromSha = await this.getHeadRef(defaultBranch)
7575

7676
// https://octokit.github.io/rest.js/#api-Git-createRef
7777
await this.github.git.createRef({
@@ -140,21 +140,27 @@ class Repository {
140140
await Promise.all(createOrUpdateFilesMultiple)
141141
}
142142

143-
async createPullRequest({ title, body, branchName }) {
143+
async createPullRequest({ title, body, branchName, defaultBranch }) {
144144
const result = await this.github.pulls.create({
145145
owner: this.owner,
146146
repo: this.repo,
147147
title,
148148
body,
149149
head: branchName,
150-
base: 'master',
150+
base: defaultBranch,
151151
maintainer_can_modify: true,
152152
})
153153
return result.data.html_url
154154
}
155155

156-
async createPullRequestFromFiles({ title, body, filesByPath, branchName }) {
157-
await this.createBranch(branchName)
156+
async createPullRequestFromFiles({
157+
title,
158+
body,
159+
filesByPath,
160+
branchName,
161+
defaultBranch,
162+
}) {
163+
await this.createBranch({ branchName, defaultBranch })
158164

159165
await this.createOrUpdateFiles({
160166
filesByPath,
@@ -165,6 +171,7 @@ class Repository {
165171
title,
166172
body,
167173
branchName,
174+
defaultBranch,
168175
})
169176

170177
return pullRequestURL

src/processIssueComment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function processAddContributor({
2020
optionsConfig,
2121
who,
2222
contributions,
23+
defaultBranch,
2324
}) {
2425
const { name, avatar_url, profile } = await getUserDetails({
2526
github: context.github,
@@ -55,6 +56,7 @@ async function processAddContributor({
5556
)}.\n\nThis was requested by ${commentReply.replyingToWho()} [in this comment](${commentReply.replyingToWhere()})`,
5657
filesByPath: filesByPathToUpdate,
5758
branchName: `all-contributors/add-${who}`,
59+
defaultBranch,
5860
})
5961

6062
commentReply.reply(
@@ -92,6 +94,7 @@ async function processIssueComment({ context, commentReply }) {
9294
optionsConfig,
9395
who: parsedComment.who,
9496
contributions: parsedComment.contributions,
97+
defaultBranch: context.payload.repository.default_branch,
9598
})
9699
return
97100
}

test/Repository/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe('Repository', () => {
9595
},
9696
},
9797
branchName: 'all-contributors/add-jakebolam',
98+
defaultBranch: 'master',
9899
})
99100
expect(pullRequestNumber).toEqual(
100101
'https://github.com/all-contributors/all-contributors-bot/pull/1347',

0 commit comments

Comments
 (0)