Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ function buildHeader(fileA, fileB) {
}

function buildContent(github, owner, repo, base, head, file) {
const {filename, patch, status} = file;
const {filename, patch, status, sha} = file;

// Get the content for the files
switch (status) {
case 'removed':
return getContent(github, owner, repo, filename, base).then(content => {
return getContent(github, owner, repo, filename, base, sha).then(content => {
return {filename, patch, status, header: buildHeader(filename, filename), fileA: atob(content)};
});

case 'added':
return getContent(github, owner, repo, filename, head).then(content => {
return getContent(github, owner, repo, filename, head, sha).then(content => {
return {filename, patch, status, header: buildHeader(filename, filename), fileB: atob(content)};
});

case 'modified':
return Promise.all([
getContent(github, owner, repo, filename, base),
getContent(github, owner, repo, filename, head),
getContent(github, owner, repo, filename, base, sha),
getContent(github, owner, repo, filename, head, sha),
]).then(files => {
const [fileA, fileB] = files;
return {filename, patch, status, header: buildHeader(filename, filename), fileA: atob(fileA), fileB: atob(fileB)};
});

case 'renamed':
return getContent(github, owner, repo, filename, head).then(content => {
return getContent(github, owner, repo, filename, head, sha).then(content => {
const decodedFile = atob(content);
const previousFilename = file.previous_filename;
const header = buildHeader(filename, previousFilename);
Expand All @@ -77,7 +77,7 @@ function buildContent(github, owner, repo, base, head, file) {
}
}

function getContent(github, owner, repo, path, commit) {
function getContent(github, owner, repo, path, commit, commitSha) {
return github.repos.getContent({
owner,
repo,
Expand All @@ -94,7 +94,10 @@ function getContent(github, owner, repo, path, commit) {
repo,
sha: commit
})
.then(commit => commit.files.find(file => file.filename === path).sha)
.then(commit => {
const file = commit.files.find(file => file.filename === path)
return file ? file.sha : commitSha
})
.then(sha => github.gitdata.getBlob({
owner,
repo,
Expand Down