Skip to content

Commit 23a3257

Browse files
committed
add state_reason param
1 parent bbb411f commit 23a3257

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ The following sets of tools are available (all are on by default):
597597
- `owner`: Repository owner (string, required)
598598
- `repo`: Repository name (string, required)
599599
- `state`: New state (string, optional)
600+
- `state_reason`: Reason for the state change, ignored unless state is changed. (string, optional)
600601
- `title`: New title (string, optional)
601602
- `type`: New issue type (string, optional)
602603

pkg/github/__toolsnaps__/update_issue.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
],
4949
"type": "string"
5050
},
51+
"state_reason": {
52+
"description": "Reason for the state change, ignored unless state is changed.",
53+
"enum": [
54+
"completed",
55+
"not_planned",
56+
"duplicate",
57+
"reopened"
58+
],
59+
"type": "string"
60+
},
5161
"title": {
5262
"description": "New title",
5363
"type": "string"

pkg/github/issues.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
11281128
mcp.Description("New state"),
11291129
mcp.Enum("open", "closed"),
11301130
),
1131+
mcp.WithString("state_reason",
1132+
mcp.Description("Reason for the state change, ignored unless state is changed."),
1133+
mcp.Enum("completed", "not_planned", "duplicate", "reopened"),
1134+
),
11311135
mcp.WithArray("labels",
11321136
mcp.Description("New labels"),
11331137
mcp.Items(
@@ -1193,6 +1197,14 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
11931197
issueRequest.State = github.Ptr(state)
11941198
}
11951199

1200+
stateReason, err := OptionalParam[string](request, "state_reason")
1201+
if err != nil {
1202+
return mcp.NewToolResultError(err.Error()), nil
1203+
}
1204+
if stateReason != "" {
1205+
issueRequest.StateReason = github.Ptr(stateReason)
1206+
}
1207+
11961208
// Get labels
11971209
labels, err := OptionalStringArrayParam(request, "labels")
11981210
if err != nil {

pkg/github/issues_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ func Test_UpdateIssue(t *testing.T) {
10441044
assert.Contains(t, tool.InputSchema.Properties, "title")
10451045
assert.Contains(t, tool.InputSchema.Properties, "body")
10461046
assert.Contains(t, tool.InputSchema.Properties, "state")
1047+
assert.Contains(t, tool.InputSchema.Properties, "state_reason")
10471048
assert.Contains(t, tool.InputSchema.Properties, "labels")
10481049
assert.Contains(t, tool.InputSchema.Properties, "assignees")
10491050
assert.Contains(t, tool.InputSchema.Properties, "milestone")
@@ -1174,6 +1175,41 @@ func Test_UpdateIssue(t *testing.T) {
11741175
expectError: true,
11751176
expectedErrMsg: "failed to update issue",
11761177
},
1178+
{
1179+
name: "close issue as not planned",
1180+
mockedClient: mock.NewMockedHTTPClient(
1181+
mock.WithRequestMatchHandler(
1182+
mock.PatchReposIssuesByOwnerByRepoByIssueNumber,
1183+
expectRequestBody(t, map[string]any{
1184+
"state": "closed",
1185+
"state_reason": "not_planned",
1186+
}).andThen(
1187+
mockResponse(t, http.StatusOK, &github.Issue{
1188+
Number: github.Ptr(123),
1189+
Title: github.Ptr("Test Issue"),
1190+
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"),
1191+
State: github.Ptr("closed"),
1192+
StateReason: github.Ptr("not_planned"),
1193+
}),
1194+
),
1195+
),
1196+
),
1197+
requestArgs: map[string]interface{}{
1198+
"owner": "owner",
1199+
"repo": "repo",
1200+
"issue_number": float64(123),
1201+
"state": "closed",
1202+
"state_reason": "not_planned",
1203+
},
1204+
expectError: false,
1205+
expectedIssue: &github.Issue{
1206+
Number: github.Ptr(123),
1207+
Title: github.Ptr("Test Issue"),
1208+
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"),
1209+
State: github.Ptr("closed"),
1210+
StateReason: github.Ptr("not_planned"),
1211+
},
1212+
},
11771213
}
11781214

11791215
for _, tc := range tests {

0 commit comments

Comments
 (0)