Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.catch(error => {
if (error.status === 401) {
if (error.message === 'Bad credentials') {
throw new APIError(
'Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.',
error.status,
'Git Gateway',
);
} else {
return false;
}
} else if (
error.status === 404 &&
(error.message === undefined || error.message === 'Unable to locate site configuration')
) {
throw new APIError(
`Git Gateway Error: Please make sure Git Gateway is enabled on your site.`,
error.status,
'Git Gateway',
);
} else {
console.error('Problem fetching repo data from Git Gateway');
throw error;
}
});
}
const { nodes } = data.repository.refs;
if (nodes.length > 0) {
const branches = [];
nodes.forEach(({ associatedPullRequests }) => {
associatedPullRequests.nodes.forEach(({ headRef }) => {
branches.push({ ref: `${headRef.prefix}${headRef.name}` });
});
});
return await Promise.all(branches.map(branch => this.migrateBranch(branch)));
} else {
console.log(
'%c No Unpublished entries',
'line-height: 30px;text-align: center;font-weight: bold',
);
throw new APIError('Not Found', 404, 'GitHub');
}
}
async retrieveContent({ path, branch, repoURL, parseText }) {
const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL);
const { is_null, is_binary, text } = await this.retrieveBlobObject(
owner,
name,
`${branch}:${path}`,
);
if (is_null) {
throw new APIError('Not Found', 404, 'GitHub');
} else if (!is_binary) {
return text;
} else {
return super.retrieveContent({ path, branch, repoURL, parseText });
}
}
.catch(error => {
if (error.status === 401) {
if (error.message === 'Bad credentials') {
throw new APIError(
'Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.',
error.status,
'Git Gateway',
);
} else {
return false;
}
} else if (
error.status === 404 &&
(error.message === undefined || error.message === 'Unable to locate site configuration')
) {
throw new APIError(
`Git Gateway Error: Please make sure Git Gateway is enabled on your site.`,
error.status,
'Git Gateway',
);
handleRequestError(error, responseStatus) {
throw new APIError(error.message || error.msg, responseStatus, 'Git Gateway');
}
return this.client.query(options).catch(error => {
throw new APIError(error.message, 500, 'GitHub');
});
}
p => p.catch(err => Promise.reject(new APIError(err.message, null, 'BitBucket'))),
])(req);
p => p.catch(err => Promise.reject(new APIError(err.message, null, 'GitLab'))),
])(req);
parseResponse = async (res, { expectingOk = true, expectingFormat = 'text' }) => {
let body;
try {
const formatter = this.responseFormats.get(expectingFormat, false);
if (!formatter) {
throw new Error(`${expectingFormat} is not a supported response format.`);
}
body = await formatter(res);
} catch (err) {
throw new APIError(err.message, res.status, 'GitLab');
}
if (expectingOk && !res.ok) {
const isJSON = expectingFormat === 'json';
throw new APIError(isJSON && body.message ? body.message : body, res.status, 'GitLab');
}
return body;
};
async listFiles(path, { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {}) {
const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL);
const { data } = await this.query({
query: queries.files(depth),
variables: { owner, name, expression: `${branch}:${path}` },
});
if (data.repository.object) {
const allFiles = this.getAllFiles(data.repository.object.entries, path);
return allFiles;
} else {
throw new APIError('Not Found', 404, 'GitHub');
}
}