Skip to content

Commit

Permalink
refactor: handle different types of octokit.repos.getContents()
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Feb 3, 2020
1 parent 57af545 commit a64f0b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/platforms/github/GitHubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ export const fileContentsGenerator = (
owner: repoSlug.split("/")[0],
}
try {
// response of getContents() can be one of 4 things. We are interested in file responses only
// https://developer.github.com/v3/repos/contents/#get-contents
const response = await api.repos.getContents(opts)
if (response && response.data && response.data.type === "file") {
if (Array.isArray(response.data)) {
return ""
}
if (response && response.data && response.data.content) {
const buffer = new Buffer(response.data.content, response.data.encoding)
return buffer.toString()
} else {
Expand Down
6 changes: 6 additions & 0 deletions source/platforms/github/comms/checks/resultsToCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ export const resultsToCheck = async (

const getBlobUrlForPath = async (path: string) => {
try {
// response of getContents() can be one of 4 things. We are interested in file responses only
// https://developer.github.com/v3/repos/contents/#get-contents
const { data } = await api.repos.getContents({ repo: pr.head.repo.name, owner: pr.head.repo.owner.login, path })
if (Array.isArray(data)) {
console.error(`Path "${path}" is a folder - ignoring`)
return ""
}
d("Got content data for: ", path)
// https://developer.github.com/v3/checks/runs/#example-of-completed-conclusion
// e.g. "blob_href": "http://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md",
Expand Down

0 comments on commit a64f0b4

Please sign in to comment.