aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge/gitlab/config.go22
-rw-r--r--bridge/gitlab/config_test.go81
2 files changed, 87 insertions, 16 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go
index cac2d91e..efef5993 100644
--- a/bridge/gitlab/config.go
+++ b/bridge/gitlab/config.go
@@ -8,7 +8,6 @@ import (
"regexp"
"strconv"
"strings"
- "time"
"github.com/pkg/errors"
"github.com/xanzy/go-gitlab"
@@ -17,16 +16,6 @@ import (
"github.com/MichaelMure/git-bug/repository"
)
-const (
- target = "gitlab"
- gitlabV4Url = "https://gitlab.com/api/v4"
- keyProjectID = "project-id"
- keyTarget = "target"
- keyToken = "token"
-
- defaultTimeout = 60 * time.Second
-)
-
var (
ErrBadProjectURL = errors.New("bad project url")
)
@@ -108,10 +97,10 @@ func (*Gitlab) ValidateConfig(conf core.Configuration) error {
}
func promptToken() (string, error) {
- fmt.Println("You can generate a new token by visiting https://gitlab.com/settings/tokens.")
- fmt.Println("Choose 'Generate new token' and set the necessary access scope for your repository.")
+ fmt.Println("You can generate a new token by visiting https://gitlab.com/profile/personal_access_tokens.")
+ fmt.Println("Choose 'Create personal access token' and set the necessary access scope for your repository.")
fmt.Println()
- fmt.Println("'api' scope access : access scope: to be able to make api calls")
+ fmt.Println("'api' access scope: to be able to make api calls")
fmt.Println()
re, err := regexp.Compile(`^[a-zA-Z0-9\-]{20}`)
@@ -192,13 +181,14 @@ func promptURL(remotes map[string]string) (string, error) {
}
func getProjectPath(url string) (string, error) {
-
cleanUrl := strings.TrimSuffix(url, ".git")
+ cleanUrl = strings.Replace(cleanUrl, "git@", "https://", 1)
objectUrl, err := neturl.Parse(cleanUrl)
if err != nil {
- return "", nil
+ return "", err
}
+ fmt.Println(objectUrl.Path)
return objectUrl.Path[1:], nil
}
diff --git a/bridge/gitlab/config_test.go b/bridge/gitlab/config_test.go
new file mode 100644
index 00000000..248cdb66
--- /dev/null
+++ b/bridge/gitlab/config_test.go
@@ -0,0 +1,81 @@
+package gitlab
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestProjectPath(t *testing.T) {
+ type args struct {
+ url string
+ }
+ type want struct {
+ path string
+ err error
+ }
+ tests := []struct {
+ name string
+ args args
+ want want
+ }{
+ {
+ name: "default url",
+ args: args{
+ url: "https://gitlab.com/MichaelMure/git-bug",
+ },
+ want: want{
+ path: "MichaelMure/git-bug",
+ err: nil,
+ },
+ },
+ {
+ name: "multiple sub groups",
+ args: args{
+ url: "https://gitlab.com/MichaelMure/group/subgroup/git-bug",
+ },
+ want: want{
+ path: "MichaelMure/group/subgroup/git-bug",
+ err: nil,
+ },
+ },
+ {
+ name: "default url with git extension",
+ args: args{
+ url: "https://gitlab.com/MichaelMure/git-bug.git",
+ },
+ want: want{
+ path: "MichaelMure/git-bug",
+ err: nil,
+ },
+ },
+ {
+ name: "url with git protocol",
+ args: args{
+ url: "git://gitlab.com/MichaelMure/git-bug.git",
+ },
+ want: want{
+ path: "MichaelMure/git-bug",
+ err: nil,
+ },
+ },
+ {
+ name: "ssh url",
+ args: args{
+ url: "git@gitlab.com/MichaelMure/git-bug.git",
+ },
+ want: want{
+ path: "MichaelMure/git-bug",
+ err: nil,
+ },
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ path, err := getProjectPath(tt.args.url)
+ assert.Equal(t, tt.want.path, path)
+ assert.Equal(t, tt.want.err, err)
+ })
+ }
+}