Skip to content

Commit

Permalink
Support dot in repo remote name
Browse files Browse the repository at this point in the history
  • Loading branch information
galan committed Feb 7, 2022
1 parent 34b30a0 commit 8b7a024
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
25 changes: 15 additions & 10 deletions internal/model/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
46 changes: 46 additions & 0 deletions internal/model/repo_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
1 change: 0 additions & 1 deletion internal/say/say.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
var VerboseEnabled bool

func Repow() string {
//aurora.Red("ॐ").String()
return Yellow("✪").Bold().String()
}

Expand Down

0 comments on commit 8b7a024

Please sign in to comment.