mirror of
https://github.com/Graylog2/graylog-project-cli.git
synced 2026-03-13 08:02:57 +08:00
Add a module-override option to the checkout command
This can be used to override the revision for a module in the given manifest.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -27,6 +28,21 @@ func ParseGitHubURL(url string) (GitHubURL, error) {
|
||||
return gitHubURL, nil
|
||||
}
|
||||
|
||||
func ReplaceGitHubURL(url string, repoName string) (string, error) {
|
||||
name := strings.TrimSuffix(repoName, ".git")
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(url, "github://"):
|
||||
return fmt.Sprintf("github://%s.git", name), nil
|
||||
case strings.HasPrefix(url, "git@github"):
|
||||
return fmt.Sprintf("git@github.com:%s.git", name), nil
|
||||
case strings.HasPrefix(url, "https://github"):
|
||||
return fmt.Sprintf("https://github.com/%s.git", name), nil
|
||||
default:
|
||||
return "", errors.Errorf("unknown GitHub URL: %s", url)
|
||||
}
|
||||
}
|
||||
|
||||
type GitHubURL struct {
|
||||
Repository string
|
||||
}
|
||||
|
||||
@@ -65,3 +65,38 @@ func TestParseGitHubURL(t *testing.T) {
|
||||
t.Error("expected unknown URL to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceGitHubURL(t *testing.T) {
|
||||
url, _ := ReplaceGitHubURL("github://Graylog2/graylog2-server.git", "foo/graylog2-server")
|
||||
expected := "github://foo/graylog2-server.git"
|
||||
if url != expected {
|
||||
t.Errorf("expected <%s> but got <%s>", expected, url)
|
||||
}
|
||||
url, _ = ReplaceGitHubURL("github://Graylog2/graylog2-server.git", "foo/graylog2-server.git")
|
||||
expected = "github://foo/graylog2-server.git"
|
||||
if url != expected {
|
||||
t.Errorf("expected <%s> but got <%s>", expected, url)
|
||||
}
|
||||
|
||||
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server")
|
||||
expected = "https://github.com/foo/graylog2-server.git"
|
||||
if url != expected {
|
||||
t.Errorf("expected <%s> but got <%s>", expected, url)
|
||||
}
|
||||
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server.git")
|
||||
expected = "https://github.com/foo/graylog2-server.git"
|
||||
if url != expected {
|
||||
t.Errorf("expected <%s> but got <%s>", expected, url)
|
||||
}
|
||||
|
||||
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server")
|
||||
expected = "https://github.com/foo/graylog2-server.git"
|
||||
if url != expected {
|
||||
t.Errorf("expected <%s> but got <%s>", expected, url)
|
||||
}
|
||||
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server.git")
|
||||
expected = "https://github.com/foo/graylog2-server.git"
|
||||
if url != expected {
|
||||
t.Errorf("expected <%s> but got <%s>", expected, url)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user