Skip to content
Merged
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
18 changes: 18 additions & 0 deletions lib/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ class Downloader {
});
}

normalise_gh_repo_path(repo_uri) {
// takes a github repo path and make sure it's in the right form to be
// able to download files from it. IE removes the .git off the end.
// returns a string.

let repo_str = repo_uri;
if (repo_str.endsWith('/')) {
repo_str = repo_str.substring(0, repo_str.length -1);
}

if (repo_str.endsWith('.git')) {
repo_str = repo_str.substring(0, repo_str.length - 4);
}

return repo_str;
}

download_from_github(firmware, options) {
// downloads the file from github and returns the path to the hex file
// as well as the temp directory it exists in to clean it up
Expand Down Expand Up @@ -137,6 +154,7 @@ class Downloader {
branch = '/master';
}

repo = this.normalise_gh_repo_path(repo);
base_uri = `https://raw.githubusercontent.com${repo}${branch}`;
manifest_uri = `${base_uri}/manifest.json?${(new Date().getTime())}`;
} else {
Expand Down
7 changes: 7 additions & 0 deletions test/downloader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ const github_actions = () => describe('4. Github related actions for the downloa
});
});
});

test('4.7 normalise_gh_repo_path() processes urls correctly', () => {
// detemrine if we put in the right repo paths we get the right reponses.
expect(dl.normalise_gh_repo_path('/test/test-package')).toBe('/test/test-package');
expect(dl.normalise_gh_repo_path('/test/test-package.git')).toBe('/test/test-package');
expect(dl.normalise_gh_repo_path('/test/test-package/')).toBe('/test/test-package');
});
});


Expand Down