Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e52386

Browse files
committed
Improve testing and mapping code in request and response
1 parent e0cde71 commit 2e52386

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
437437
- `state`: Alert state (string, optional)
438438
- `severity`: Alert severity (string, optional)
439439

440+
### Notifications
441+
442+
- **list_notifications** - List notifications for a GitHub user
443+
444+
- `page`: Page number (number, optional, default: 1)
445+
- `per_page`: Number of records per page (number, optional, default: 30)
446+
- `all`: Whether to fetch all notifications, including read ones (boolean, optional, default: false)
447+
440448
## Resources
441449

442450
### Repository Content

pkg/github/notifications.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ func ListNotifications(getClient GetClientFn, t translations.TranslationHelperFu
4141
return mcp.NewToolResultError(err.Error()), nil
4242
}
4343

44-
if request.Params.Arguments["all"] == true {
45-
all = true // Set to true if user explicitly asks for all notifications
46-
}
47-
4844
opts := &github.NotificationListOptions{
4945
ListOptions: github.ListOptions{
5046
Page: page,
@@ -71,18 +67,7 @@ func ListNotifications(getClient GetClientFn, t translations.TranslationHelperFu
7167
return mcp.NewToolResultError(fmt.Sprintf("failed to list notifications: %s", string(body))), nil
7268
}
7369

74-
// Extract the notification title in addition to reason, url, and timestamp.
75-
var extractedNotifications []map[string]interface{}
76-
for _, notification := range notifications {
77-
extractedNotifications = append(extractedNotifications, map[string]interface{}{
78-
"title": notification.GetSubject().GetTitle(),
79-
"reason": notification.GetReason(),
80-
"url": notification.GetURL(),
81-
"timestamp": notification.GetUpdatedAt(),
82-
})
83-
}
84-
85-
r, err := json.Marshal(extractedNotifications)
70+
r, err := json.Marshal(notifications)
8671
if err != nil {
8772
return nil, fmt.Errorf("failed to marshal notifications: %w", err)
8873
}

pkg/github/notifications_test.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ func Test_ListNotifications(t *testing.T) {
2828
// Setup mock notifications
2929
mockNotifications := []*github.Notification{
3030
{
31-
ID: github.String("1"),
32-
Reason: github.String("mention"),
31+
ID: github.Ptr("1"),
32+
Reason: github.Ptr("mention"),
3333
Subject: &github.NotificationSubject{
34-
Title: github.String("Test Notification 1"),
34+
Title: github.Ptr("Test Notification 1"),
3535
},
3636
UpdatedAt: &github.Timestamp{Time: time.Now()},
37-
URL: github.String("https://example.com/notifications/threads/1"),
37+
URL: github.Ptr("https://example.com/notifications/threads/1"),
3838
},
3939
{
40-
ID: github.String("2"),
41-
Reason: github.String("team_mention"),
40+
ID: github.Ptr("2"),
41+
Reason: github.Ptr("team_mention"),
4242
Subject: &github.NotificationSubject{
43-
Title: github.String("Test Notification 2"),
43+
Title: github.Ptr("Test Notification 2"),
4444
},
4545
UpdatedAt: &github.Timestamp{Time: time.Now()},
46-
URL: github.String("https://example.com/notifications/threads/1"),
46+
URL: github.Ptr("https://example.com/notifications/threads/1"),
4747
},
4848
}
4949

@@ -112,15 +112,9 @@ func Test_ListNotifications(t *testing.T) {
112112
require.NoError(t, err)
113113
assert.Equal(t, len(tc.expectedResponse), len(returnedNotifications))
114114
for i, notification := range returnedNotifications {
115-
// Ensure all required fields are mocked
116-
assert.NotNil(t, notification.Subject, "Subject should not be nil")
117-
assert.NotNil(t, notification.Subject.Title, "Title should not be nil")
118-
assert.NotNil(t, notification.Reason, "Reason should not be nil")
119-
assert.NotNil(t, notification.URL, "URL should not be nil")
120-
assert.NotNil(t, notification.UpdatedAt, "UpdatedAt should not be nil")
121-
// assert.Equal(t, *tc.expectedResponse[i].ID, *notification.ID)
115+
assert.Equal(t, *tc.expectedResponse[i].ID, *notification.ID)
122116
assert.Equal(t, *tc.expectedResponse[i].Reason, *notification.Reason)
123-
// assert.Equal(t, *tc.expectedResponse[i].Subject.Title, *notification.Subject.Title)
117+
assert.Equal(t, *tc.expectedResponse[i].Subject.Title, *notification.Subject.Title)
124118
}
125119
})
126120
}

0 commit comments

Comments
 (0)