bridge/gitlab: fix note error handling bug

Amine Hilaly created

bridge/gitlab: remove unused functions

Change summary

bridge/gitlab/config.go      | 37 -------------------------------------
bridge/gitlab/gitlab.go      |  3 ++-
bridge/gitlab/import.go      |  2 +-
bridge/gitlab/import_test.go |  6 +++---
4 files changed, 6 insertions(+), 42 deletions(-)

Detailed changes

bridge/gitlab/config.go 🔗

@@ -107,21 +107,6 @@ func (*Gitlab) ValidateConfig(conf core.Configuration) error {
 	return nil
 }
 
-func requestToken(client *gitlab.Client, userID int, name string, scopes ...string) (string, error) {
-	impToken, _, err := client.Users.CreateImpersonationToken(
-		userID,
-		&gitlab.CreateImpersonationTokenOptions{
-			Name:   &name,
-			Scopes: &scopes,
-		},
-	)
-	if err != nil {
-		return "", err
-	}
-
-	return impToken.Token, nil
-}
-
 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.")
@@ -231,28 +216,6 @@ func getValidGitlabRemoteURLs(remotes map[string]string) []string {
 	return urls
 }
 
-func validateUsername(username string) (bool, int, error) {
-	// no need for a token for this action
-	client := buildClient("")
-
-	users, _, err := client.Users.ListUsers(&gitlab.ListUsersOptions{Username: &username})
-	if err != nil {
-		return false, 0, err
-	}
-
-	if len(users) == 0 {
-		return false, 0, fmt.Errorf("username not found")
-	} else if len(users) > 1 {
-		return false, 0, fmt.Errorf("found multiple matches")
-	}
-
-	if users[0].Username == username {
-		return true, users[0].ID, nil
-	}
-
-	return false, 0, nil
-}
-
 func validateProjectURL(url, token string) (bool, int, error) {
 	client := buildClient(token)
 

bridge/gitlab/gitlab.go 🔗

@@ -1,8 +1,9 @@
 package gitlab
 
 import (
-	"github.com/MichaelMure/git-bug/bridge/core"
 	"github.com/xanzy/go-gitlab"
+
+	"github.com/MichaelMure/git-bug/bridge/core"
 )
 
 func init() {

bridge/gitlab/import.go 🔗

@@ -137,7 +137,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
 	}
 
 	hash, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, id)
-	if err != nil && err != cache.ErrNoMatchingOp {
+	if errResolve != cache.ErrNoMatchingOp {
 		return err
 	}
 

bridge/gitlab/import_test.go 🔗

@@ -6,15 +6,15 @@ import (
 	"testing"
 	"time"
 
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
 	"github.com/MichaelMure/git-bug/bridge/core"
 	"github.com/MichaelMure/git-bug/bug"
 	"github.com/MichaelMure/git-bug/cache"
 	"github.com/MichaelMure/git-bug/identity"
 	"github.com/MichaelMure/git-bug/repository"
 	"github.com/MichaelMure/git-bug/util/interrupt"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	//_ "github.com/motemen/go-loghttp/global"
 )
 
 func TestImport(t *testing.T) {