github: minor cleanups

Michael Muré created

Change summary

bridge/github/config.go          |  2 +-
bridge/github/export.go          |  4 ++--
bridge/github/export_test.go     |  2 +-
bridge/github/import.go          |  9 ++++++---
bridge/github/import_mediator.go | 30 +++++++++++++++---------------
5 files changed, 25 insertions(+), 22 deletions(-)

Detailed changes

bridge/github/config.go 🔗

@@ -251,7 +251,7 @@ func promptUserToGoToBrowser(url, userCode string) {
 	fmt.Println("Please visit the following Github URL in a browser and enter your user authentication code.")
 	fmt.Println()
 	fmt.Println("  URL:", url)
-	fmt.Println("  user authentiation code:", userCode)
+	fmt.Println("  user authentication code:", userCode)
 	fmt.Println()
 }
 

bridge/github/export.go 🔗

@@ -504,7 +504,7 @@ func (ge *githubExporter) cacheGithubLabels(ctx context.Context, gc *githubv4.Cl
 	return nil
 }
 
-func (ge *githubExporter) getLabelID(gc *githubv4.Client, label string) (string, error) {
+func (ge *githubExporter) getLabelID(label string) (string, error) {
 	label = strings.ToLower(label)
 	for cachedLabel, ID := range ge.cachedLabels {
 		if label == strings.ToLower(cachedLabel) {
@@ -598,7 +598,7 @@ func (ge *githubExporter) createGithubLabelV4(gc *githubv4.Client, label, labelC
 
 func (ge *githubExporter) getOrCreateGithubLabelID(ctx context.Context, gc *githubv4.Client, repositoryID string, label bug.Label) (string, error) {
 	// try to get label id from cache
-	labelID, err := ge.getLabelID(gc, string(label))
+	labelID, err := ge.getLabelID(string(label))
 	if err == nil {
 		return labelID, nil
 	}

bridge/github/export_test.go 🔗

@@ -268,7 +268,7 @@ func TestGithubPushPull(t *testing.T) {
 			require.True(t, ok)
 			require.Equal(t, issueOrigin, target)
 
-			//TODO: maybe more tests to ensure bug final state
+			// TODO: maybe more tests to ensure bug final state
 		})
 	}
 }

bridge/github/import.go 🔗

@@ -15,7 +15,7 @@ import (
 	"github.com/MichaelMure/git-bug/util/text"
 )
 
-const EMPTY_TITLE_PLACEHOLDER = "<empty string>"
+const EmptyTitlePlaceholder = "<empty string>"
 
 // githubImporter implement the Importer interface
 type githubImporter struct {
@@ -196,7 +196,7 @@ func (gi *githubImporter) ensureIssue(ctx context.Context, repo *cache.RepoCache
 	// return an error: empty title.
 	title := string(issue.Title)
 	if title == " \u200b" { // U+200B == zero width space
-		title = EMPTY_TITLE_PLACEHOLDER
+		title = EmptyTitlePlaceholder
 	}
 
 	var textInput string
@@ -380,7 +380,7 @@ func (gi *githubImporter) ensureTimelineItem(ctx context.Context, repo *cache.Re
 		// function to return an error: empty title.
 		title := string(item.RenamedTitleEvent.CurrentTitle)
 		if title == " \u200b" { // U+200B == zero width space
-			title = EMPTY_TITLE_PLACEHOLDER
+			title = EmptyTitlePlaceholder
 		}
 
 		op, err := b.SetTitleRaw(
@@ -568,6 +568,9 @@ func (gi *githubImporter) getGhost(ctx context.Context, repo *cache.RepoCache) (
 		return nil, err
 	}
 	user, err := gi.mediator.User(ctx, loginName)
+	if err != nil {
+		return nil, err
+	}
 	userName := ""
 	if user.Name != nil {
 		userName = string(*user.Name)

bridge/github/import_mediator.go 🔗

@@ -11,12 +11,12 @@ import (
 
 const (
 	// These values influence how fast the github graphql rate limit is exhausted.
-	NUM_ISSUES         = 40
-	NUM_ISSUE_EDITS    = 100
-	NUM_TIMELINE_ITEMS = 100
-	NUM_COMMENT_EDITS  = 100
+	NumIssues        = 40
+	NumIssueEdits    = 100
+	NumTimelineItems = 100
+	NumCommentEdits  = 100
 
-	CHAN_CAPACITY = 128
+	ChanCapacity = 128
 )
 
 // importMediator provides a convenient interface to retrieve issues from the Github GraphQL API.
@@ -90,7 +90,7 @@ func NewImportMediator(ctx context.Context, client *githubv4.Client, owner, proj
 		owner:        owner,
 		project:      project,
 		since:        since,
-		importEvents: make(chan ImportEvent, CHAN_CAPACITY),
+		importEvents: make(chan ImportEvent, ChanCapacity),
 		err:          nil,
 	}
 	go func() {
@@ -107,33 +107,33 @@ func newIssueVars(owner, project string, since time.Time) varmap {
 		"owner":             githubv4.String(owner),
 		"name":              githubv4.String(project),
 		"issueSince":        githubv4.DateTime{Time: since},
-		"issueFirst":        githubv4.Int(NUM_ISSUES),
-		"issueEditLast":     githubv4.Int(NUM_ISSUE_EDITS),
+		"issueFirst":        githubv4.Int(NumIssues),
+		"issueEditLast":     githubv4.Int(NumIssueEdits),
 		"issueEditBefore":   (*githubv4.String)(nil),
-		"timelineFirst":     githubv4.Int(NUM_TIMELINE_ITEMS),
+		"timelineFirst":     githubv4.Int(NumTimelineItems),
 		"timelineAfter":     (*githubv4.String)(nil),
-		"commentEditLast":   githubv4.Int(NUM_COMMENT_EDITS),
+		"commentEditLast":   githubv4.Int(NumCommentEdits),
 		"commentEditBefore": (*githubv4.String)(nil),
 	}
 }
 
 func newIssueEditVars() varmap {
 	return varmap{
-		"issueEditLast": githubv4.Int(NUM_ISSUE_EDITS),
+		"issueEditLast": githubv4.Int(NumIssueEdits),
 	}
 }
 
 func newTimelineVars() varmap {
 	return varmap{
-		"timelineFirst":     githubv4.Int(NUM_TIMELINE_ITEMS),
-		"commentEditLast":   githubv4.Int(NUM_COMMENT_EDITS),
+		"timelineFirst":     githubv4.Int(NumTimelineItems),
+		"commentEditLast":   githubv4.Int(NumCommentEdits),
 		"commentEditBefore": (*githubv4.String)(nil),
 	}
 }
 
 func newCommentEditVars() varmap {
 	return varmap{
-		"commentEditLast": githubv4.Int(NUM_COMMENT_EDITS),
+		"commentEditLast": githubv4.Int(NumCommentEdits),
 	}
 }
 
@@ -316,7 +316,7 @@ func (mm *importMediator) queryIssue(ctx context.Context, cursor githubv4.String
 	if cursor == "" {
 		vars["issueAfter"] = (*githubv4.String)(nil)
 	} else {
-		vars["issueAfter"] = githubv4.String(cursor)
+		vars["issueAfter"] = cursor
 	}
 	query := issueQuery{}
 	if err := mm.mQuery(ctx, &query, vars); err != nil {