Skip to content

Commit 6122f7c

Browse files
committed
Split mock back out, use RepositoryCommit with Files/Stats
1 parent 06246a7 commit 6122f7c

File tree

2 files changed

+66
-37
lines changed

2 files changed

+66
-37
lines changed

pkg/github/repositories.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func getCommit(client *github.Client, t translations.TranslationHelperFunc) (too
7676
}
7777
}
7878

79-
8079
// listCommits creates a tool to get commits of a branch in a repository.
8180
func listCommits(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
8281
return mcp.NewTool("list_commits",

pkg/github/repositories_test.go

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,6 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18-
var mockCommits = []*github.RepositoryCommit{
19-
{
20-
SHA: github.Ptr("abc123def456"),
21-
Commit: &github.Commit{
22-
Message: github.Ptr("First commit"),
23-
Author: &github.CommitAuthor{
24-
Name: github.Ptr("Test User"),
25-
Email: github.Ptr("test@example.com"),
26-
Date: &github.Timestamp{Time: time.Now().Add(-48 * time.Hour)},
27-
},
28-
},
29-
Author: &github.User{
30-
Login: github.Ptr("testuser"),
31-
},
32-
HTMLURL: github.Ptr("https://github.com/owner/repo/commit/abc123def456"),
33-
},
34-
{
35-
SHA: github.Ptr("def456abc789"),
36-
Commit: &github.Commit{
37-
Message: github.Ptr("Second commit"),
38-
Author: &github.CommitAuthor{
39-
Name: github.Ptr("Another User"),
40-
Email: github.Ptr("another@example.com"),
41-
Date: &github.Timestamp{Time: time.Now().Add(-24 * time.Hour)},
42-
},
43-
},
44-
Author: &github.User{
45-
Login: github.Ptr("anotheruser"),
46-
},
47-
HTMLURL: github.Ptr("https://github.com/owner/repo/commit/def456abc789"),
48-
},
49-
}
50-
5118
func Test_GetFileContents(t *testing.T) {
5219
// Verify tool definition once
5320
mockClient := github.NewClient(nil)
@@ -520,7 +487,36 @@ func Test_GetCommit(t *testing.T) {
520487
assert.Contains(t, tool.InputSchema.Properties, "sha")
521488
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "sha"})
522489

523-
mockCommit := mockCommits[0]
490+
mockCommit := &github.RepositoryCommit{
491+
SHA: github.Ptr("abc123def456"),
492+
Commit: &github.Commit{
493+
Message: github.Ptr("First commit"),
494+
Author: &github.CommitAuthor{
495+
Name: github.Ptr("Test User"),
496+
Email: github.Ptr("test@example.com"),
497+
Date: &github.Timestamp{Time: time.Now().Add(-48 * time.Hour)},
498+
},
499+
},
500+
Author: &github.User{
501+
Login: github.Ptr("testuser"),
502+
},
503+
HTMLURL: github.Ptr("https://github.com/owner/repo/commit/abc123def456"),
504+
Stats: &github.CommitStats{
505+
Additions: github.Ptr(10),
506+
Deletions: github.Ptr(2),
507+
Total: github.Ptr(12),
508+
},
509+
Files: []*github.CommitFile{
510+
{
511+
Filename: github.Ptr("file1.go"),
512+
Status: github.Ptr("modified"),
513+
Additions: github.Ptr(10),
514+
Deletions: github.Ptr(2),
515+
Changes: github.Ptr(12),
516+
Patch: github.Ptr("@@ -1,2 +1,10 @@"),
517+
},
518+
},
519+
}
524520
// This one currently isn't defined in the mock package we're using.
525521
var mockEndpointPattern = mock.EndpointPattern{
526522
Pattern: "/repos/{owner}/{repo}/commits/{sha}",
@@ -600,7 +596,7 @@ func Test_GetCommit(t *testing.T) {
600596
var returnedCommit github.RepositoryCommit
601597
err = json.Unmarshal([]byte(textContent.Text), &returnedCommit)
602598
require.NoError(t, err)
603-
599+
604600
assert.Equal(t, *tc.expectedCommit.SHA, *returnedCommit.SHA)
605601
assert.Equal(t, *tc.expectedCommit.Commit.Message, *returnedCommit.Commit.Message)
606602
assert.Equal(t, *tc.expectedCommit.Author.Login, *returnedCommit.Author.Login)
@@ -622,7 +618,41 @@ func Test_ListCommits(t *testing.T) {
622618
assert.Contains(t, tool.InputSchema.Properties, "page")
623619
assert.Contains(t, tool.InputSchema.Properties, "perPage")
624620
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
625-
621+
622+
// Setup mock commits for success case
623+
mockCommits := []*github.RepositoryCommit{
624+
{
625+
SHA: github.Ptr("abc123def456"),
626+
Commit: &github.Commit{
627+
Message: github.Ptr("First commit"),
628+
Author: &github.CommitAuthor{
629+
Name: github.Ptr("Test User"),
630+
Email: github.Ptr("test@example.com"),
631+
Date: &github.Timestamp{Time: time.Now().Add(-48 * time.Hour)},
632+
},
633+
},
634+
Author: &github.User{
635+
Login: github.Ptr("testuser"),
636+
},
637+
HTMLURL: github.Ptr("https://github.com/owner/repo/commit/abc123def456"),
638+
},
639+
{
640+
SHA: github.Ptr("def456abc789"),
641+
Commit: &github.Commit{
642+
Message: github.Ptr("Second commit"),
643+
Author: &github.CommitAuthor{
644+
Name: github.Ptr("Another User"),
645+
Email: github.Ptr("another@example.com"),
646+
Date: &github.Timestamp{Time: time.Now().Add(-24 * time.Hour)},
647+
},
648+
},
649+
Author: &github.User{
650+
Login: github.Ptr("anotheruser"),
651+
},
652+
HTMLURL: github.Ptr("https://github.com/owner/repo/commit/def456abc789"),
653+
},
654+
}
655+
626656
tests := []struct {
627657
name string
628658
mockedClient *http.Client

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy