Skip to content

Commit 40fd675

Browse files
author
Adam Duncan
committed
Ensure files determiner works on PRs and new branches
1 parent 2282d53 commit 40fd675

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/files-changed-determiner.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ const getCommit = gh => async data => {
33
let commitData = null
44
const options = {
55
user: data.repo.namespace,
6-
repo: data.repo.name,
7-
base: data.build.before,
8-
head: data.build.after
6+
repo: data.repo.name
97
}
10-
const comparison = await promisify(gh.repos.compareCommits)(options)
8+
9+
let action = 'compareCommits'
10+
// github sends this in some instances: first commit on a new branch?
11+
if (!data.build.before || data.build.before === '0000000000000000000000000000000000000000') {
12+
options.sha = data.build.after
13+
action = 'getCommit'
14+
} else {
15+
options.base = data.build.before
16+
options.head = data.build.after
17+
}
18+
19+
const comparison = await promisify(gh.repos[action])(options)
1120
return comparison.files.map(f => f.filename)
1221
}
1322

0 commit comments

Comments
 (0)