1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-25 09:15:49 +03:00

Detect GitHub branch name automatically from URL (#4081)

* Detect GitHub branch name automatically from URL

* Switched if statement to ternary operator

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>

---------

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
This commit is contained in:
Yaros 2024-07-03 21:59:27 +02:00 committed by GitHub
parent 2bd55e0604
commit 71784e5f43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -9,4 +9,15 @@ export default class PresetSource {
static isUrlGithubRepo(url) {
return url.trim().toLowerCase().startsWith("https://github.com/");
}
static containsBranchName(url) {
return url.includes("/tree/");
}
static getBranchName(url) {
const pattern = /https:\/\/github\.com\/[^\/]+\/[^\/]+\/tree\/([^\/]+)/;
const match = url.match(pattern);
return match ? match[1] : null;
}
}

View file

@ -147,6 +147,10 @@ export default class SourcePanel {
_onInputChange() {
this._checkIfGithub();
if (PresetSource.containsBranchName(this._domEditUrl.val())) {
this._domEditGitHubBranch.val(PresetSource.getBranchName(this._domEditUrl.val()));
this._domEditUrl.val(this._domEditUrl.val().split("/tree/")[0]);
}
this._setIsSaved(false);
}