feat: add type to issues by radar07 · Pull Request #484 · github/github-mcp-server · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

feat: add type to issues #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
mcp.WithNumber("milestone",
mcp.Description("Milestone number"),
),
mcp.WithString("type",
mcp.Description("Type of this issue"),
),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := requiredParam[string](request, "owner")
Expand Down Expand Up @@ -327,13 +330,20 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
milestoneNum = &milestone
}

// Get optional type
issueType, err := OptionalParam[string](request, "type")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

// Create the issue request
issueRequest := &github.IssueRequest{
Title: github.Ptr(title),
Body: github.Ptr(body),
Assignees: &assignees,
Labels: &labels,
Milestone: milestoneNum,
Type: &issueType,
}

client, err := getClient(ctx)
Expand Down Expand Up @@ -534,6 +544,9 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
mcp.WithNumber("milestone",
mcp.Description("New milestone number"),
),
mcp.WithString("type",
mcp.Description("New issue type"),
),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := requiredParam[string](request, "owner")
Expand Down Expand Up @@ -604,6 +617,15 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
issueRequest.Milestone = &milestoneNum
}

// Get issue type
issueType, err := OptionalParam[string](request, "type")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
if issueType != "" {
issueRequest.Type = github.Ptr(issueType)
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
Expand Down
25 changes: 22 additions & 3 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func Test_CreateIssue(t *testing.T) {
assert.Contains(t, tool.InputSchema.Properties, "assignees")
assert.Contains(t, tool.InputSchema.Properties, "labels")
assert.Contains(t, tool.InputSchema.Properties, "milestone")
assert.Contains(t, tool.InputSchema.Properties, "type")
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "title"})

// Setup mock issue for success case
Expand All @@ -408,6 +409,7 @@ func Test_CreateIssue(t *testing.T) {
Assignees: []*github.User{{Login: github.Ptr("user1")}, {Login: github.Ptr("user2")}},
Labels: []*github.Label{{Name: github.Ptr("bug")}, {Name: github.Ptr("help wanted")}},
Milestone: &github.Milestone{Number: github.Ptr(5)},
Type: &github.IssueType{Name: github.Ptr("Bug")},
}

tests := []struct {
Expand All @@ -429,6 +431,7 @@ func Test_CreateIssue(t *testing.T) {
"labels": []any{"bug", "help wanted"},
"assignees": []any{"user1", "user2"},
"milestone": float64(5),
"type": "Bug",
}).andThen(
mockResponse(t, http.StatusCreated, mockIssue),
),
Expand All @@ -442,6 +445,7 @@ func Test_CreateIssue(t *testing.T) {
"assignees": []any{"user1", "user2"},
"labels": []any{"bug", "help wanted"},
"milestone": float64(5),
"type": "Bug",
},
expectError: false,
expectedIssue: mockIssue,
Expand Down Expand Up @@ -537,6 +541,10 @@ func Test_CreateIssue(t *testing.T) {
assert.Equal(t, *tc.expectedIssue.Body, *returnedIssue.Body)
}

if tc.expectedIssue.Type != nil {
assert.Equal(t, *tc.expectedIssue.Type.Name, *returnedIssue.Type.Name)
}

// Check assignees if expected
if len(tc.expectedIssue.Assignees) > 0 {
assert.Equal(t, len(tc.expectedIssue.Assignees), len(returnedIssue.Assignees))
Expand Down Expand Up @@ -748,6 +756,7 @@ func Test_UpdateIssue(t *testing.T) {
assert.Contains(t, tool.InputSchema.Properties, "labels")
assert.Contains(t, tool.InputSchema.Properties, "assignees")
assert.Contains(t, tool.InputSchema.Properties, "milestone")
assert.Contains(t, tool.InputSchema.Properties, "type")
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "issue_number"})

// Setup mock issue for success case
Expand All @@ -760,6 +769,7 @@ func Test_UpdateIssue(t *testing.T) {
Assignees: []*github.User{{Login: github.Ptr("assignee1")}, {Login: github.Ptr("assignee2")}},
Labels: []*github.Label{{Name: github.Ptr("bug")}, {Name: github.Ptr("priority")}},
Milestone: &github.Milestone{Number: github.Ptr(5)},
Type: &github.IssueType{Name: github.Ptr("Bug")},
}

tests := []struct {
Expand All @@ -782,6 +792,7 @@ func Test_UpdateIssue(t *testing.T) {
"labels": []any{"bug", "priority"},
"assignees": []any{"assignee1", "assignee2"},
"milestone": float64(5),
"type": "Bug",
}).andThen(
mockResponse(t, http.StatusOK, mockIssue),
),
Expand All @@ -797,6 +808,7 @@ func Test_UpdateIssue(t *testing.T) {
"labels": []any{"bug", "priority"},
"assignees": []any{"assignee1", "assignee2"},
"milestone": float64(5),
"type": "Bug",
},
expectError: false,
expectedIssue: mockIssue,
Expand All @@ -808,24 +820,27 @@ func Test_UpdateIssue(t *testing.T) {
mock.PatchReposIssuesByOwnerByRepoByIssueNumber,
mockResponse(t, http.StatusOK, &github.Issue{
Number: github.Ptr(123),
Title: github.Ptr("Only Title Updated"),
Title: github.Ptr("Updated Issue Title"),
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"),
State: github.Ptr("open"),
Type: &github.IssueType{Name: github.Ptr("Feature")},
}),
),
),
requestArgs: map[string]interface{}{
"owner": "owner",
"repo": "repo",
"issue_number": float64(123),
"title": "Only Title Updated",
"title": "Updated Issue Title",
"type": "Feature",
},
expectError: false,
expectedIssue: &github.Issue{
Number: github.Ptr(123),
Title: github.Ptr("Only Title Updated"),
Title: github.Ptr("Updated Issue Title"),
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"),
State: github.Ptr("open"),
Type: &github.IssueType{Name: github.Ptr("Feature")},
},
},
{
Expand Down Expand Up @@ -914,6 +929,10 @@ func Test_UpdateIssue(t *testing.T) {
assert.Equal(t, *tc.expectedIssue.Body, *returnedIssue.Body)
}

if tc.expectedIssue.Type != nil {
assert.Equal(t, *tc.expectedIssue.Type.Name, *returnedIssue.Type.Name)
}

// Check assignees if expected
if len(tc.expectedIssue.Assignees) > 0 {
assert.Len(t, returnedIssue.Assignees, len(tc.expectedIssue.Assignees))
Expand Down

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.