Skip to content

Commit 0271f31

Browse files
committed
🐛 Fix compareCommits url encoding issue for octokit/rest@v16.x
Resolves wei#236
1 parent 6d6df14 commit 0271f31

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎lib/pull.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ module.exports = class Pull {
121121

122122
async hasDiff (base, upstream) {
123123
try {
124+
// TODO Remove encodeURIComponent after upgrading to probot@v10 or octokit/rest@v17 or above
124125
const comparison = await this.github.repos.compareCommits({
125126
owner: this.config.owner,
126127
repo: this.config.repo,
127-
head: upstream,
128-
base
128+
head: encodeURIComponent(upstream),
129+
base: encodeURIComponent(base)
129130
})
130131
return comparison.data.total_commits > 0
131132
} catch (e) {

‎test/pull.test.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ describe('pull - routineCheck', () => {
109109
const pull = getPull()
110110
await pull.routineCheck()
111111
expect(github.repos.compareCommits).nthCalledWith(1, {
112-
owner: 'wei', repo: 'fork', base: 'master', head: 'upstream:master'
112+
owner: 'wei', repo: 'fork', base: 'master', head: 'upstream%3Amaster'
113113
})
114114
expect(github.repos.compareCommits).nthCalledWith(3, {
115-
owner: 'wei', repo: 'fork', base: 'hotfix/bug-1', head: 'upstream:dev'
115+
owner: 'wei', repo: 'fork', base: 'hotfix%2Fbug-1', head: 'upstream%3Adev'
116116
})
117117
expect(github.repos.compareCommits).nthCalledWith(2, {
118-
owner: 'wei', repo: 'fork', base: 'feature/new-1', head: 'upstream:dev'
118+
owner: 'wei', repo: 'fork', base: 'feature%2Fnew-1', head: 'upstream%3Adev'
119119
})
120120
expect(github.issues.listForRepo).not.toHaveBeenCalled()
121121
expect(github.pulls.create).not.toHaveBeenCalled()
@@ -230,22 +230,22 @@ describe('pull - routineCheck', () => {
230230
const pull = getPull()
231231
await pull.routineCheck()
232232
expect(github.repos.compareCommits).nthCalledWith(1, {
233-
owner: 'wei', repo: 'fork', base: 'master', head: 'upstream:master'
233+
owner: 'wei', repo: 'fork', base: 'master', head: 'upstream%3Amaster'
234234
})
235235
expect(github.issues.listForRepo).toHaveBeenCalled()
236236
expect(github.pulls.get).nthCalledWith(1, { owner: 'wei', repo: 'fork', pull_number: 13 })
237237
expect(github.pulls.get).nthCalledWith(2, { owner: 'wei', repo: 'fork', pull_number: 12 })
238238
expect(github.pulls.merge).not.toHaveBeenCalledWith()
239239

240240
expect(github.repos.compareCommits).nthCalledWith(2, {
241-
owner: 'wei', repo: 'fork', base: 'feature/new-1', head: 'upstream:dev'
241+
owner: 'wei', repo: 'fork', base: 'feature%2Fnew-1', head: 'upstream%3Adev'
242242
})
243243
expect(github.issues.listForRepo).toHaveBeenCalled()
244244
expect(github.pulls.get).nthCalledWith(3, { owner: 'wei', repo: 'fork', pull_number: 13 })
245245
expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 13, merge_method: 'rebase' })
246246

247247
expect(github.repos.compareCommits).nthCalledWith(3, {
248-
owner: 'wei', repo: 'fork', base: 'hotfix/bug-1', head: 'upstream:dev'
248+
owner: 'wei', repo: 'fork', base: 'hotfix%2Fbug-1', head: 'upstream%3Adev'
249249
})
250250
expect(github.issues.listForRepo).toHaveBeenCalled()
251251
expect(github.pulls.get).nthCalledWith(4, { owner: 'wei', repo: 'fork', pull_number: 13 })
@@ -284,13 +284,13 @@ describe('pull - routineCheck', () => {
284284
const pull = getPull()
285285
await pull.routineCheck()
286286
expect(github.repos.compareCommits).nthCalledWith(1, {
287-
owner: 'wei', repo: 'fork', base: 'master', head: 'upstream:master'
287+
owner: 'wei', repo: 'fork', base: 'master', head: 'upstream%3Amaster'
288288
})
289289
expect(github.repos.compareCommits).nthCalledWith(2, {
290-
owner: 'wei', repo: 'fork', base: 'feature/new-1', head: 'upstream:dev'
290+
owner: 'wei', repo: 'fork', base: 'feature%2Fnew-1', head: 'upstream%3Adev'
291291
})
292292
expect(github.repos.compareCommits).nthCalledWith(3, {
293-
owner: 'wei', repo: 'fork', base: 'hotfix/bug-1', head: 'upstream:dev'
293+
owner: 'wei', repo: 'fork', base: 'hotfix%2Fbug-1', head: 'upstream%3Adev'
294294
})
295295
expect(github.issues.listForRepo).toHaveBeenCalledTimes(3)
296296
expect(github.pulls.create).toHaveBeenCalledTimes(2)

0 commit comments

Comments
 (0)