From 9477b31c062886833917e6bb7e985fda89f12e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B8ran=20A=2E=20Slettemark?= Date: Thu, 5 Dec 2024 07:57:50 +0100 Subject: [PATCH] Changed master to main --- app/defaults.js | 3 +++ app/interpreter.js | 15 +++++++++++---- static/index.html | 2 +- test/download.js | 6 +++--- test/interpreter.js | 6 +++--- 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 app/defaults.js diff --git a/app/defaults.js b/app/defaults.js new file mode 100644 index 0000000..4733d17 --- /dev/null +++ b/app/defaults.js @@ -0,0 +1,3 @@ +module.exports = { + DEFAULT_BRANCH: 'main' +} diff --git a/app/interpreter.js b/app/interpreter.js index 769f339..db4c961 100644 --- a/app/interpreter.js +++ b/app/interpreter.js @@ -12,6 +12,8 @@ const { } = require('@highcharts/highcharts-assembler/src/dependencies.js') const { join, sep, relative } = require('path') +const { DEFAULT_BRANCH } = require('./defaults') + // Constants const BRANCH_TYPES = [ 'bugfix', @@ -28,8 +30,10 @@ const PRODUCTS = ['stock', 'maps', 'gantt'] const replaceAll = (str, search, replace) => str.split(search).join(replace) /** - * Finds which branch, tag, or commit that is requested by the client. Defaults - * to master. Returns a string with the resulting reference. + * Finds which branch, tag, or commit that is requested by the client, + * or responds with the default branch + * + * Returns a string with the resulting reference. * * @param {string} url The request URL. */ @@ -43,7 +47,7 @@ async function getBranch (url) { !(str.endsWith('.js') || str.endsWith('.css')) // Not a file ) - let branch = 'master' + let branch = DEFAULT_BRANCH const sections = url.substring(1).split('/') // We have more than one section if (sections.length > 1 && BRANCH_TYPES.includes(sections[0])) { @@ -72,7 +76,10 @@ async function getBranch (url) { */ function getFile (branch, type, url) { // Replace branches in url, since we save by commit sha - url = url.replace(/^\/master/, '') + if (url.startsWith('/' + DEFAULT_BRANCH)) { + url = url.replace('/' + DEFAULT_BRANCH, '') + } + url = url.replace(/^\/v[0-9]+\//, '/') const regex = new RegExp(`^\\/(${BRANCH_TYPES.join('|')})\\/([A-Za-z]|[0-9]|-)+\\/`) if (regex.test(url)) { diff --git a/static/index.html b/static/index.html index a566e1e..86dc100 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@

Highcharts Github File Service

Latest development from GitHub

The file path can be pointed to a specific branch, commit or tag in our GitHub repo. Both Highcharts and Highstock share the same repo, so you'll find highcharts.src.js and highstock.src.js on the same level.

-

Branch: "master"

+

Branch: "main"