mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-22 01:06:50 +02:00
handle invalid sha
This commit is contained in:
+15
-6
@@ -76,8 +76,13 @@ function tree2tree(tree, partialTree, parentPath) {
|
|||||||
async function getTruncatedTree(repoConfig, truncatedTree, sha, parentPath) {
|
async function getTruncatedTree(repoConfig, truncatedTree, sha, parentPath) {
|
||||||
const repo = gh(repoConfig.fullName);
|
const repo = gh(repoConfig.fullName);
|
||||||
|
|
||||||
if (!sha) {
|
if (!sha || !/^[a-f0-9]+$/.test(sha)) {
|
||||||
sha = repoConfig.commit ? repoConfig.commit : "HEAD";
|
if (repoConfig.commit && /^[a-f0-9]+$/.test(repoConfig.commit)) {
|
||||||
|
sha = repoConfig.commit;
|
||||||
|
} else {
|
||||||
|
sha = "HEAD";
|
||||||
|
}
|
||||||
|
repoConfig.commit = sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
@@ -119,13 +124,14 @@ async function getTruncatedTree(repoConfig, truncatedTree, sha, parentPath) {
|
|||||||
module.exports.getTree = async (repoConfig, sha, truncatedTree, parentPath) => {
|
module.exports.getTree = async (repoConfig, sha, truncatedTree, parentPath) => {
|
||||||
const repo = gh(repoConfig.fullName);
|
const repo = gh(repoConfig.fullName);
|
||||||
|
|
||||||
if (!sha) {
|
if (!sha || !/^[a-f0-9]+$/.test(sha)) {
|
||||||
if (repoConfig.commit && !/^[a-f0-9]+$/.test(repoConfig.commit)) {
|
if (repoConfig.commit && /^[a-f0-9]+$/.test(repoConfig.commit)) {
|
||||||
sha = repoConfig.commit
|
sha = repoConfig.commit;
|
||||||
} else {
|
} else {
|
||||||
sha = "HEAD"
|
sha = "HEAD";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parentPath) parentPath = "";
|
if (!parentPath) parentPath = "";
|
||||||
|
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
@@ -137,6 +143,8 @@ module.exports.getTree = async (repoConfig, sha, truncatedTree, parentPath) => {
|
|||||||
tree_sha: sha,
|
tree_sha: sha,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
sha = ghRes.data.sha;
|
||||||
|
repoConfig.commit = sha;
|
||||||
|
|
||||||
const tree = tree2tree(ghRes.data.tree, truncatedTree, parentPath);
|
const tree = tree2tree(ghRes.data.tree, truncatedTree, parentPath);
|
||||||
if (ghRes.data.truncated) {
|
if (ghRes.data.truncated) {
|
||||||
@@ -172,6 +180,7 @@ module.exports.getFileList = async (options) => {
|
|||||||
{ repoId: repoConfig.repoId },
|
{ repoId: repoConfig.repoId },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
|
commit: repoConfig.commit,
|
||||||
originalFiles: tree.child,
|
originalFiles: tree.child,
|
||||||
files,
|
files,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user