diff options
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/gitlab/config.go | 19 | ||||
-rw-r--r-- | bridge/gitlab/config_test.go | 9 | ||||
-rw-r--r-- | bridge/gitlab/import.go | 14 |
3 files changed, 26 insertions, 16 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go index efef5993..a375bab2 100644 --- a/bridge/gitlab/config.go +++ b/bridge/gitlab/config.go @@ -3,7 +3,7 @@ package gitlab import ( "bufio" "fmt" - neturl "net/url" + "net/url" "os" "regexp" "strconv" @@ -41,13 +41,13 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) ( // remote suggestions remotes, err := repo.GetRemotes() if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting remotes") } // terminal prompt url, err = promptURL(remotes) if err != nil { - return nil, err + return nil, errors.Wrap(err, "url prompt") } } @@ -57,7 +57,7 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) ( } else { token, err = promptToken() if err != nil { - return nil, err + return nil, errors.Wrap(err, "token prompt") } } @@ -65,7 +65,7 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) ( // validate project url and get it ID ok, id, err := validateProjectURL(url, token) if err != nil { - return nil, err + return nil, errors.Wrap(err, "project validation") } if !ok { return nil, fmt.Errorf("invalid project id or wrong token scope") @@ -180,15 +180,14 @@ func promptURL(remotes map[string]string) (string, error) { } } -func getProjectPath(url string) (string, error) { - cleanUrl := strings.TrimSuffix(url, ".git") +func getProjectPath(projectUrl string) (string, error) { + cleanUrl := strings.TrimSuffix(projectUrl, ".git") cleanUrl = strings.Replace(cleanUrl, "git@", "https://", 1) - objectUrl, err := neturl.Parse(cleanUrl) + objectUrl, err := url.Parse(cleanUrl) if err != nil { - return "", err + return "", ErrBadProjectURL } - fmt.Println(objectUrl.Path) return objectUrl.Path[1:], nil } diff --git a/bridge/gitlab/config_test.go b/bridge/gitlab/config_test.go index 248cdb66..87469796 100644 --- a/bridge/gitlab/config_test.go +++ b/bridge/gitlab/config_test.go @@ -69,6 +69,15 @@ func TestProjectPath(t *testing.T) { err: nil, }, }, + { + name: "bad url", + args: args{ + url: "---,%gitlab.com/MichaelMure/git-bug.git", + }, + want: want{ + err: ErrBadProjectURL, + }, + }, } for _, tt := range tests { diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index b2db13d0..67d9aa25 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -95,7 +95,7 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue // if bug was never imported if err == bug.ErrBugNotExist { - cleanText, err := text.Cleanup(string(issue.Description)) + cleanText, err := text.Cleanup(issue.Description) if err != nil { return nil, err } @@ -261,10 +261,12 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n return err - default: - // non handled note types, this is not an error + case NOTE_UNKNOWN: //TODO: send warning via channel return nil + + default: + panic("unhandled note type") } return nil @@ -322,9 +324,6 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id return nil, err } - // importing a new identity - gi.importedIdentities++ - client := buildClient(gi.conf["token"]) user, _, err := client.Users.GetUser(id) @@ -332,6 +331,9 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id return nil, err } + // importing a new identity + gi.importedIdentities++ + return repo.NewIdentityRaw( user.Name, user.PublicEmail, |