Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
DEFAULT_BRANCH: 'main'
}
15 changes: 11 additions & 4 deletions app/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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.
*/
Expand All @@ -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])) {
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>Highcharts Github File Service</h1>
<h2>Latest development from GitHub</h2>
<p>The file path can be pointed to a specific branch, commit or tag in <a href="https://github.com/highcharts/highcharts/">our GitHub repo</a>. Both Highcharts and Highstock share the same repo, so you'll find highcharts.src.js and highstock.src.js on the same level.</p>

<h4>Branch: "master"</h4>
<h4>Branch: "main"</h4>
<ul>
<li><a href="/highcharts.src.js">http://github.highcharts.com/highcharts.src.js</a></li>
<li><a href="/highstock.src.js">http://github.highcharts.com/highstock.src.js</a></li>
Expand Down
6 changes: 3 additions & 3 deletions test/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ describe('download.js', () => {
})
it('should resolve with an informational object, and a newly created file.', () => {
return downloadFile(
downloadURL + 'master/ts/masters/highcharts.src.ts',
downloadURL + 'main/ts/masters/highcharts.src.ts',
'./tmp/test/downloaded-file1.js'
).then(({ outputPath, statusCode, success, url }) => {
expect(outputPath).to.equal('./tmp/test/downloaded-file1.js')
expect(statusCode).to.equal(200)
expect(success).to.equal(true)
expect(url).to.equal(downloadURL + 'master/ts/masters/highcharts.src.ts')
expect(url).to.equal(downloadURL + 'main/ts/masters/highcharts.src.ts')
expect(fs.lstatSync('./tmp/test/downloaded-file1.js').size).to.be.greaterThan(0)
})
})
it('should only create a file if response status is 200', () => {
return downloadFile(
downloadURL + 'master/i-do-not-exist.js',
downloadURL + 'main/i-do-not-exist.js',
'./tmp/test/downloaded-file2.js'
).then(({ outputPath, statusCode, success, url }) => {
let exists = true
Expand Down
6 changes: 3 additions & 3 deletions test/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('interpreter.js', () => {
describe('getBranch', () => {
const getBranch = defaults.getBranch

it('should return "master" when first section is either a file, folder or type', async () => {
it('should return "main" when first section is either a file, folder or type', async () => {
[
'/modules/exporting.src.js',
'/highcharts.src.js',
'/css/highcharts.css',
'/js/highcharts.src.js',
'/gantt/highcharts.src.js'
].forEach(async (branch) => {
expect((await getBranch(branch))).to.equal('master')
expect((await getBranch(branch))).to.equal('main')
})
})
// it('should support multiple level branch names for bugfix and feature', () => {
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('interpreter.js', () => {
const getFile = defaults.getFile

it('should support product folders', () => {
expect(getFile('master', 'classic', '/gantt/highcharts.src.js'))
expect(getFile('main', 'classic', '/gantt/highcharts.src.js'))
.to.equal('highcharts.src.js')
})

Expand Down