Skip to content

Commit 607495a

Browse files
committed
fix: return project item id usable for updates
1 parent 486e9fe commit 607495a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pkg/github/projects.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"strconv"
910
"time"
1011

1112
ghErrors "github.com/github/github-mcp-server/pkg/errors"
@@ -1084,7 +1085,8 @@ func addProjectItem(ctx context.Context, gqlClient *githubv4.Client, owner, owne
10841085
var mutation struct {
10851086
AddProjectV2ItemByID struct {
10861087
Item struct {
1087-
ID githubv4.ID
1088+
ID githubv4.ID
1089+
FullDatabaseID string `graphql:"fullDatabaseId"`
10881090
}
10891091
} `graphql:"addProjectV2ItemById(input: $input)"`
10901092
}
@@ -1110,6 +1112,12 @@ func addProjectItem(ctx context.Context, gqlClient *githubv4.Client, owner, owne
11101112
"id": mutation.AddProjectV2ItemByID.Item.ID,
11111113
"message": fmt.Sprintf("Successfully added %s %s/%s#%d to project %s/%d", itemType, itemOwner, itemRepo, itemNumber, owner, projectNumber),
11121114
}
1115+
if fullDatabaseID := mutation.AddProjectV2ItemByID.Item.FullDatabaseID; fullDatabaseID != "" {
1116+
result["full_database_id"] = fullDatabaseID
1117+
if itemID, err := strconv.ParseInt(fullDatabaseID, 10, 64); err == nil {
1118+
result["item_id"] = itemID
1119+
}
1120+
}
11131121

11141122
r, err := json.Marshal(result)
11151123
if err != nil {

pkg/github/projects_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ func Test_ProjectsWrite_AddProjectItem(t *testing.T) {
486486
struct {
487487
AddProjectV2ItemByID struct {
488488
Item struct {
489-
ID githubv4.ID
489+
ID githubv4.ID
490+
FullDatabaseID string `graphql:"fullDatabaseId"`
490491
}
491492
} `graphql:"addProjectV2ItemById(input: $input)"`
492493
}{},
@@ -498,7 +499,8 @@ func Test_ProjectsWrite_AddProjectItem(t *testing.T) {
498499
githubv4mock.DataResponse(map[string]any{
499500
"addProjectV2ItemById": map[string]any{
500501
"item": map[string]any{
501-
"id": "PVTI_item1",
502+
"id": "PVTI_item1",
503+
"fullDatabaseId": "1001",
502504
},
503505
},
504506
}),
@@ -530,6 +532,8 @@ func Test_ProjectsWrite_AddProjectItem(t *testing.T) {
530532
err = json.Unmarshal([]byte(textContent.Text), &response)
531533
require.NoError(t, err)
532534
assert.NotNil(t, response["id"])
535+
assert.Equal(t, float64(1001), response["item_id"])
536+
assert.Equal(t, "1001", response["full_database_id"])
533537
assert.Contains(t, response["message"], "Successfully added")
534538
})
535539

@@ -583,7 +587,8 @@ func Test_ProjectsWrite_AddProjectItem(t *testing.T) {
583587
struct {
584588
AddProjectV2ItemByID struct {
585589
Item struct {
586-
ID githubv4.ID
590+
ID githubv4.ID
591+
FullDatabaseID string `graphql:"fullDatabaseId"`
587592
}
588593
} `graphql:"addProjectV2ItemById(input: $input)"`
589594
}{},
@@ -595,7 +600,8 @@ func Test_ProjectsWrite_AddProjectItem(t *testing.T) {
595600
githubv4mock.DataResponse(map[string]any{
596601
"addProjectV2ItemById": map[string]any{
597602
"item": map[string]any{
598-
"id": "PVTI_item2",
603+
"id": "PVTI_item2",
604+
"fullDatabaseId": "1002",
599605
},
600606
},
601607
}),
@@ -627,6 +633,8 @@ func Test_ProjectsWrite_AddProjectItem(t *testing.T) {
627633
err = json.Unmarshal([]byte(textContent.Text), &response)
628634
require.NoError(t, err)
629635
assert.NotNil(t, response["id"])
636+
assert.Equal(t, float64(1002), response["item_id"])
637+
assert.Equal(t, "1002", response["full_database_id"])
630638
assert.Contains(t, response["message"], "Successfully added")
631639
})
632640

0 commit comments

Comments
 (0)