From 15082c09eb11fb07de602d109abad438239d67b5 Mon Sep 17 00:00:00 2001
From: Shawna Monero <66325812+smonero@users.noreply.github.com>
Date: Tue, 20 Jul 2021 17:25:03 -0700
Subject: [PATCH] backend: github service: add User object to response (#1626)

---
 backend/service/github/github.go      |  6 ++++--
 backend/service/github/github_test.go | 30 ++++++++++++++++-----------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/backend/service/github/github.go b/backend/service/github/github.go
index 3f703228..afb2391b 100644
--- a/backend/service/github/github.go
+++ b/backend/service/github/github.go
@@ -364,7 +364,7 @@ func (s *svc) CompareCommits(ctx context.Context, ref *RemoteRef, compareSHA str
 type Commit struct {
 	Files   []*githubv3.CommitFile
 	Message string
-	Author  *githubv3.CommitAuthor
+	Author  *githubv3.User
 }
 
 func (s *svc) GetCommit(ctx context.Context, ref *RemoteRef) (*Commit, error) {
@@ -372,10 +372,12 @@ func (s *svc) GetCommit(ctx context.Context, ref *RemoteRef) (*Commit, error) {
 	if err != nil {
 		return nil, err
 	}
+
+	// Currently we are using the Author (Github) rather than commit Author (Git)
 	return &Commit{
 		Files:   commit.Files,
 		Message: commit.GetCommit().GetMessage(),
-		Author:  commit.GetCommit().GetAuthor(),
+		Author:  commit.GetAuthor(),
 	}, nil
 }
 
diff --git a/backend/service/github/github_test.go b/backend/service/github/github_test.go
index d6dbc04f..5d467091 100644
--- a/backend/service/github/github_test.go
+++ b/backend/service/github/github_test.go
@@ -364,12 +364,14 @@ func TestCompareCommits(t *testing.T) {
 }
 
 var getCommitsTests = []struct {
-	name        string
-	errorText   string
-	mockRepo    *mockRepositories
-	file        string
-	message     string
-	authorLogin string
+	name            string
+	errorText       string
+	mockRepo        *mockRepositories
+	file            string
+	message         string
+	authorLogin     string
+	authorAvatarURL string
+	authorID        int64
 }{
 	{
 		name:      "v3 error",
@@ -377,11 +379,12 @@ var getCommitsTests = []struct {
 		errorText: "we've had a problem",
 	},
 	{
-		name:        "happy path",
-		mockRepo:    &mockRepositories{},
-		file:        "testfile.go",
-		message:     "committing some changes (#1)",
-		authorLogin: "foobar",
+		name:            "happy path",
+		mockRepo:        &mockRepositories{},
+		file:            "testfile.go",
+		message:         "committing some changes (#1)",
+		authorAvatarURL: "https://foo.bar/baz.png",
+		authorID:        1234,
 	},
 }
 
@@ -415,7 +418,10 @@ func TestGetCommit(t *testing.T) {
 			}
 			a.Equal(tt.file, *commit.Files[0].Filename)
 			a.Equal(tt.message, commit.Message)
-			a.Equal(tt.authorLogin, *commit.Author.Login)
+			if commit.Author != nil {
+				a.Equal(tt.authorAvatarURL, *commit.Author.AvatarURL)
+				a.Equal(tt.authorID, *commit.Author.ID)
+			}
 			a.Nil(err)
 		})
 	}
-- 
GitLab