Skip to content

Commit

Permalink
backend: Updating Github Service (#3085)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdslaugh authored Aug 8, 2024
1 parent 4bffb99 commit 8efb167
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
22 changes: 16 additions & 6 deletions backend/service/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type File struct {
type Entry struct {
Name string
Type string
SHA string
}

type Directory struct {
Expand Down Expand Up @@ -371,6 +372,9 @@ func (s *svc) CreateBranch(ctx context.Context, req *CreateBranchRequest) error
if _, err := io.Copy(fh, contents); err != nil {
return err
}
if err := wt.AddWithOptions(&git.AddOptions{Path: filename}); err != nil {
return err
}
}

opts := commitOptionsFromClaims(ctx, time.Now())
Expand Down Expand Up @@ -510,17 +514,21 @@ func (s *svc) GetDirectory(ctx context.Context, ref *RemoteRef, path string) (*D
entries = append(entries, &Entry{
Name: string(obj.Name),
Type: string(obj.Type),
SHA: string(obj.OID),
})
}

d := &Directory{
Path: path,
Entries: entries,
LastModifiedTime: q.Repository.Ref.Commit.History.Nodes[0].CommittedDate.Time,
LastModifiedSHA: string(q.Repository.Ref.Commit.History.Nodes[0].OID),
directory := &Directory{
Path: path,
Entries: entries,
}

if len(q.Repository.Ref.Commit.History.Nodes) > 0 {
directory.LastModifiedTime = q.Repository.Ref.Commit.History.Nodes[0].CommittedDate.Time
directory.LastModifiedSHA = string(q.Repository.Ref.Commit.History.Nodes[0].OID)
}

return d, nil
return directory, nil
}

/*
Expand All @@ -539,6 +547,7 @@ type Commit struct {
Files []*githubv3.CommitFile
Message string
Author *githubv3.User
SHA string
ParentRef string
}

Expand All @@ -550,6 +559,7 @@ func (s *svc) GetCommit(ctx context.Context, ref *RemoteRef) (*Commit, error) {

// Currently we are using the Author (Github) rather than commit Author (Git)
retCommit := &Commit{
SHA: commit.GetSHA(),
Files: commit.Files,
Message: commit.GetCommit().GetMessage(),
Author: commit.GetAuthor(),
Expand Down
10 changes: 8 additions & 2 deletions backend/service/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func (g *getdirectoryMock) Query(ctx context.Context, query interface{}, variabl
struct {
Name githubv4.String
Type githubv4.String
}{Name: githubv4.String(g.entries[0].Name), Type: githubv4.String(g.entries[0].Type)})
OID githubv4.GitObjectID
}{Name: githubv4.String(g.entries[0].Name), Type: githubv4.String(g.entries[0].Type), OID: githubv4.GitObjectID(g.entries[0].SHA)})
}

q.Repository.Ref.Commit.History.Nodes = append(
Expand Down Expand Up @@ -277,7 +278,7 @@ func TestGetFile(t *testing.T) {
}
}

var directoryEntries = []*Entry{{Name: "foo", Type: "blob"}}
var directoryEntries = []*Entry{{Name: "foo", Type: "blob", SHA: "abcdef12345"}}

var getDirectoryTests = []struct {
name string
Expand Down Expand Up @@ -582,6 +583,7 @@ var getCommitsTests = []struct {
authorLogin string
authorAvatarURL string
authorID int64
sha string
parentRef string
}{
{
Expand All @@ -596,6 +598,7 @@ var getCommitsTests = []struct {
message: "committing some changes (#1)",
authorAvatarURL: "https://foo.bar/baz.png",
authorID: 1234,
sha: "test",
parentRef: "test",
},
}
Expand Down Expand Up @@ -634,6 +637,9 @@ func TestGetCommit(t *testing.T) {
a.Equal(tt.authorAvatarURL, *commit.Author.AvatarURL)
a.Equal(tt.authorID, *commit.Author.ID)
}
if commit.SHA != "" {
a.Equal(tt.sha, commit.SHA)
}
if commit.ParentRef != "" {
a.Equal(tt.parentRef, commit.ParentRef)
}
Expand Down
1 change: 1 addition & 0 deletions backend/service/github/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type getDirectoryQuery struct {
Entries []struct {
Name githubv4.String
Type githubv4.String
OID githubv4.GitObjectID
} `graphql:"entries"`
} `graphql:"... on Tree"`
} `graphql:"object(expression:$refPath)"`
Expand Down

0 comments on commit 8efb167

Please sign in to comment.