mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 01:35:28 +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:
parent
2bd55e0604
commit
71784e5f43
2 changed files with 15 additions and 0 deletions
|
@ -9,4 +9,15 @@ export default class PresetSource {
|
||||||
static isUrlGithubRepo(url) {
|
static isUrlGithubRepo(url) {
|
||||||
return url.trim().toLowerCase().startsWith("https://github.com/");
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,10 @@ export default class SourcePanel {
|
||||||
|
|
||||||
_onInputChange() {
|
_onInputChange() {
|
||||||
this._checkIfGithub();
|
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);
|
this._setIsSaved(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue