forked from pomber/git-history
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
450 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
webpack: { | ||
configure: { | ||
output: { | ||
// I need "this" for workerize-loader | ||
globalObject: "this" | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const cache = {}; | ||
|
||
async function getCommits({ repo, sha, path, last, token }) { | ||
if (!cache[path]) { | ||
let fields = | ||
"values.path,values.commit.date,values.commit.message,values.commit.hash,values.commit.author.*,values.commit.links.html, values.commit.author.user.nickname, values.commit.author.user.links.avatar.href, values.commit.links.html.href"; | ||
// fields = "*.*.*.*.*"; | ||
const commitsResponse = await fetch( | ||
`https://api.bitbucket.org/2.0/repositories/${repo}/filehistory/${sha}/${path}?fields=${fields}`, | ||
{ headers: token ? { Authorization: `bearer ${token}` } : {} } | ||
); | ||
|
||
if (!commitsResponse.ok) { | ||
throw { | ||
status: commitsResponse.status === 403 ? 404 : commitsResponse.status, | ||
body: commitsJson | ||
}; | ||
} | ||
|
||
const commitsJson = await commitsResponse.json(); | ||
|
||
cache[path] = commitsJson.values.map(({ commit }) => ({ | ||
sha: commit.hash, | ||
date: new Date(commit.date), | ||
author: { | ||
login: commit.author.user | ||
? commit.author.user.nickname | ||
: commit.author.raw, | ||
avatar: commit.author.user && commit.author.user.links.avatar.href | ||
}, | ||
commitUrl: commit.links.html.href, | ||
message: commit.message | ||
})); | ||
} | ||
|
||
const commits = cache[path].slice(0, last); | ||
|
||
await Promise.all( | ||
commits.map(async commit => { | ||
if (!commit.content) { | ||
const info = await getContent(repo, commit.sha, path, token); | ||
commit.content = info.content; | ||
} | ||
}) | ||
); | ||
|
||
return commits; | ||
} | ||
|
||
async function getContent(repo, sha, path, token) { | ||
const contentResponse = await fetch( | ||
`https://api.bitbucket.org/2.0/repositories/${repo}/src/${sha}/${path}`, | ||
{ headers: token ? { Authorization: `bearer ${token}` } : {} } | ||
); | ||
|
||
if (contentResponse.status === 404) { | ||
return { content: "" }; | ||
} | ||
|
||
if (!contentResponse.ok) { | ||
throw { | ||
status: contentResponse.status, | ||
body: contentJson | ||
}; | ||
} | ||
|
||
const content = await contentResponse.text(); | ||
|
||
return { content }; | ||
} | ||
|
||
export default { | ||
getCommits | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
async function getCommits({ path, last }) { | ||
// TODO cache | ||
const response = await fetch( | ||
`/api/commits?path=${encodeURIComponent(path)}&last=${last}` | ||
); | ||
const commits = await response.json(); | ||
commits.forEach(c => (c.date = new Date(c.date))); | ||
|
||
return commits; | ||
} | ||
|
||
export default { | ||
getCommits | ||
}; |
Oops, something went wrong.