Skip to content

Commit

Permalink
Detect GitHub branch name automatically from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
YarosMallorca committed Jul 2, 2024
1 parent 3abe626 commit a283332
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/tabs/presets/SourcesDialog/PresetSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ 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);
if (match) {
return match[1];
} else {
return null;
}
}
}
4 changes: 4 additions & 0 deletions src/tabs/presets/SourcesDialog/SourcePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit a283332

Please sign in to comment.