Merge branch 'master' into dev

This commit is contained in:
Tan Jiang 2017-02-10 10:51:20 +08:00
commit 1d2970c3c5
3 changed files with 4 additions and 4 deletions

View File

@ -53,7 +53,7 @@ func ParseRepository(repository string) (project, rest string) {
rest = repository
return
}
index := strings.LastIndex(repository, "/")
index := strings.Index(repository, "/")
project = repository[0:index]
rest = repository[index+1:]
return

View File

@ -65,10 +65,10 @@ func TestParseRepository(t *testing.T) {
repository = "library/test/ubuntu"
project, rest = ParseRepository(repository)
if project != "library/test" {
if project != "library" {
t.Errorf("unexpected project: %s != %s", project, "library/test")
}
if rest != "ubuntu" {
if rest != "test/ubuntu" {
t.Errorf("unexpected rest: %s != %s", rest, "ubuntu")
}

View File

@ -151,7 +151,7 @@ func TriggerReplication(policyID int64, repository string,
func GetPoliciesByRepository(repository string) ([]*models.RepPolicy, error) {
repository = strings.TrimSpace(repository)
repository = strings.TrimRight(repository, "/")
projectName := repository[:strings.LastIndex(repository, "/")]
projectName, _ := utils.ParseRepository(repository)
project, err := dao.GetProjectByName(projectName)
if err != nil {