From 8b7a0242149b39c6f667cde6502c8c091fdf46fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gal=C3=A1n=20y=20Martins?= Date: Mon, 7 Feb 2022 23:47:04 +0100 Subject: [PATCH] Support dot in repo remote name --- .vscode/settings.json | 3 ++- CHANGELOG.md | 4 +++- internal/cmd/serve.go | 2 +- internal/model/repo.go | 25 ++++++++++++-------- internal/model/repo_test.go | 46 +++++++++++++++++++++++++++++++++++++ internal/say/say.go | 1 - 6 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 internal/model/repo_test.go diff --git a/.vscode/settings.json b/.vscode/settings.json index b9f9c8c..5cc0e2d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,8 @@ "titleBar.activeBackground": "#a73f08", "titleBar.activeForeground": "#e7e7e7", "titleBar.inactiveBackground": "#a73f0899", - "titleBar.inactiveForeground": "#e7e7e799" + "titleBar.inactiveForeground": "#e7e7e799", + "sash.hoverBorder": "#d8510a" }, "peacock.color": "#a73f08" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ae14f..a1ae92b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +* Repository detection for names with dot in `cleanup` + ## [0.2.1] - 2021-08-18 ### Added - * Option for own slack prefix/emoji in notifications via `REPOW_SLACK_PREFIX` * Option for retries when downloading the repo.yaml file `REPOW_GITLAB_DOWNLOAD_RETRIES`/`GITLAB_DOWNLOAD_RETRIES` diff --git a/internal/cmd/serve.go b/internal/cmd/serve.go index 5deefa2..b642c26 100644 --- a/internal/cmd/serve.go +++ b/internal/cmd/serve.go @@ -124,7 +124,7 @@ func processWebhook(w http.ResponseWriter, r *http.Request, hoster h.Hoster, nam return } - say.Verbose("Repoyaml: %s", repoYaml) + say.Verbose("Repoyaml: %v", repoYaml) hoster.Apply(repoRemote.RepoMeta) } diff --git a/internal/model/repo.go b/internal/model/repo.go index b560c1f..5507320 100644 --- a/internal/model/repo.go +++ b/internal/model/repo.go @@ -86,18 +86,23 @@ func DetermineRemotePath(pathRepository string, hosterHost string) string { var result string for _, line := range lines { - //origin https://oauth2:ccc@gitlab.com/group/services/url-shortener.git (fetch) - //origin git@gitlab.com:group/infrastructure/project.git (fetch) - //origin https://github.com/galan/maven-parent.git (fetch) - //origin git@gitlab.com:group/infrastructure/project.git (fetch) - //TODO distinguish remote url notations, improve this approach - re, _ := regexp.Compile(`^origin[\t ]+((https|ssh):\/\/.*@?|git@)` + hosterHost + `[\/:]([a-zA-Z0-9_\/-]+)([.]git)?[\t ]+.fetch.$`) - matches := re.MatchString(line) - say.Verbose("Checking remote: %s, matches: %v", line, matches) - if matches { - result = re.FindStringSubmatch(line)[3] + result = ParseRemotePath(line, hosterHost) + if len(result) > 0 { break } } return result } + +//TODO distinguish remote url notations, improve this approach +func ParseRemotePath(path string, hosterHost string) string { + var result string + re, _ := regexp.Compile(`^origin[\t ]+((https|ssh):\/\/.*@?|git@)` + hosterHost + `[\/:]([a-zA-Z0-9_\/.-]+)[\t ]+.fetch.$`) + matches := re.MatchString(path) + say.Verbose("Checking remote: %s, matches: %v", path, matches) + if matches { + result = re.FindStringSubmatch(path)[3] + result = strings.TrimSuffix(result, ".git") // greedy regex has issues in golang, workaround + } + return result +} diff --git a/internal/model/repo_test.go b/internal/model/repo_test.go new file mode 100644 index 0000000..6a50576 --- /dev/null +++ b/internal/model/repo_test.go @@ -0,0 +1,46 @@ +package model + +import ( + "repo/internal/say" + "testing" +) + +const dummyHost string = "blabla.com" + +type matchCase struct { + input string + expected string +} + +var matchCases = []matchCase{ + { + input: "origin https://oauth2:ccc@" + dummyHost + "/group/services/some-service.git (fetch)", + expected: "group/services/some-service", + }, + { + input: "origin git@" + dummyHost + ":group/libraries/some-service.core.git (fetch)", + expected: "group/libraries/some-service.core", + }, + { + input: "origin git@" + dummyHost + ":group/infrastructure/project.git (fetch)", + expected: "group/infrastructure/project", + }, + { + input: "origin https://" + dummyHost + "/galan/maven-parent.git (fetch)", + expected: "galan/maven-parent", + }, + { + input: "origin git@" + dummyHost + ":group/infrastructure/project.git (fetch)", + expected: "group/infrastructure/project", + }, +} + +func TestMatches(t *testing.T) { + say.VerboseEnabled = true + for _, test := range matchCases { + got := ParseRemotePath(test.input, dummyHost) + if got != test.expected { + t.Errorf("got %s, wanted %s", got, test.expected) + } + } +} diff --git a/internal/say/say.go b/internal/say/say.go index 1ae8b19..32697bd 100644 --- a/internal/say/say.go +++ b/internal/say/say.go @@ -14,7 +14,6 @@ import ( var VerboseEnabled bool func Repow() string { - //aurora.Red("ॐ").String() return Yellow("✪").Bold().String() }