Skip to content

Commit

Permalink
Merge pull request #120 from snyk/fix/remove-gh-raw-rewrite
Browse files Browse the repository at this point in the history
fix: remove GHE /raw rewrite rule
  • Loading branch information
adrukh authored Jul 1, 2018
2 parents 0cb0d94 + 633c3de commit 1b69b84
Show file tree
Hide file tree
Showing 3 changed files with 8,376 additions and 53 deletions.
27 changes: 0 additions & 27 deletions lib/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,8 @@ function requestHandler(filterRules) {
function responseHandler(filterRules, config) {
const filters = Filters(filterRules);

const supportedFiles = (filterRules || [])
.filter(f => f.path && f.path.includes('/contents/'))
.map(f => f.path.split('/').pop());

return (brokerToken) => ({ url, headers, method, body = null } = {}, emit) => {

// Changing old /raw endpoint to /contents api for GH clients.
// Since GH enterprise 2.11 version the /raw endpoint is deprecated
// This piece of code allow us to move to the new /content API without
// breaking old broker clients.
// Once all our GHE client will move to this new version of the broker
// client we could remove this code.
function rewriteRawApi() {
// find urls that ends with manifest files
const file = supportedFiles.find(f => url.endsWith(f));
if (file && url) {
headers.accept = 'application/vnd.github.2.11.raw';
// switching urls from: /:name/:repo/:branch*/:path
// to /repos/:name/:repo/contents/:path?ref=:branch
// $1 - repo/owner, $2 - branch, $3 - path
url = url
.replace(/(\/.+?\/.+?\/)(.+?)(\/.*)/, `/repos$1contents$3?ref=$2`);
}
}

if (config.GITHUB) {
rewriteRawApi();
}

logger.info({ method, url, headers }, 'request captured');
filters({ url, method, body, headers }, (error, result) => {
if (error) {
Expand Down
Loading

0 comments on commit 1b69b84

Please sign in to comment.