@@ -1447,6 +1447,179 @@ func TestPullRequestReviewCommentSubmit(t *testing.T) {
1447
1447
require .Equal (t , 3 , len (comments ), "expected to find three review comments" )
1448
1448
}
1449
1449
1450
+ func TestListIssues (t * testing.T ) {
1451
+ t .Parallel ()
1452
+
1453
+ mcpClient := setupMCPClient (t )
1454
+
1455
+ ctx := context .Background ()
1456
+
1457
+ // First, who am I
1458
+ getMeRequest := mcp.CallToolRequest {}
1459
+ getMeRequest .Params .Name = "get_me"
1460
+
1461
+ t .Log ("Getting current user..." )
1462
+ resp , err := mcpClient .CallTool (ctx , getMeRequest )
1463
+ require .NoError (t , err , "expected to call 'get_me' tool successfully" )
1464
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1465
+
1466
+ require .False (t , resp .IsError , "expected result not to be an error" )
1467
+ require .Len (t , resp .Content , 1 , "expected content to have one item" )
1468
+
1469
+ textContent , ok := resp .Content [0 ].(mcp.TextContent )
1470
+ require .True (t , ok , "expected content to be of type TextContent" )
1471
+
1472
+ var trimmedGetMeText struct {
1473
+ Login string `json:"login"`
1474
+ }
1475
+ err = json .Unmarshal ([]byte (textContent .Text ), & trimmedGetMeText )
1476
+ require .NoError (t , err , "expected to unmarshal text content successfully" )
1477
+
1478
+ currentOwner := trimmedGetMeText .Login
1479
+
1480
+ // Then create a repository with a README (via autoInit)
1481
+ repoName := fmt .Sprintf ("github-mcp-server-e2e-%s-%d" , t .Name (), time .Now ().UnixMilli ())
1482
+ createRepoRequest := mcp.CallToolRequest {}
1483
+ createRepoRequest .Params .Name = "create_repository"
1484
+ createRepoRequest .Params .Arguments = map [string ]any {
1485
+ "name" : repoName ,
1486
+ "private" : true ,
1487
+ "autoInit" : true ,
1488
+ }
1489
+
1490
+ t .Logf ("Creating repository %s/%s..." , currentOwner , repoName )
1491
+ _ , err = mcpClient .CallTool (ctx , createRepoRequest )
1492
+ require .NoError (t , err , "expected to call 'create_repository' tool successfully" )
1493
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1494
+
1495
+ // Cleanup the repository after the test
1496
+ t .Cleanup (func () {
1497
+ // MCP Server doesn't support deletions, but we can use the GitHub Client
1498
+ ghClient := getRESTClient (t )
1499
+ t .Logf ("Deleting repository %s/%s..." , currentOwner , repoName )
1500
+ ghClient .Repositories .Delete (context .Background (), currentOwner , repoName )
1501
+ // require.NoError(t, err, "expected to delete repository successfully")
1502
+ })
1503
+
1504
+ // Create a branch on which to create a new commit
1505
+ createBranchRequest := mcp.CallToolRequest {}
1506
+ createBranchRequest .Params .Name = "create_branch"
1507
+ createBranchRequest .Params .Arguments = map [string ]any {
1508
+ "owner" : currentOwner ,
1509
+ "repo" : repoName ,
1510
+ "branch" : "test-branch" ,
1511
+ "from_branch" : "main" ,
1512
+ }
1513
+
1514
+ t .Logf ("Creating branch in %s/%s..." , currentOwner , repoName )
1515
+ resp , err = mcpClient .CallTool (ctx , createBranchRequest )
1516
+ require .NoError (t , err , "expected to call 'create_branch' tool successfully" )
1517
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1518
+
1519
+ // Create a commit with a new file
1520
+ commitRequest := mcp.CallToolRequest {}
1521
+ commitRequest .Params .Name = "create_or_update_file"
1522
+ commitRequest .Params .Arguments = map [string ]any {
1523
+ "owner" : currentOwner ,
1524
+ "repo" : repoName ,
1525
+ "path" : "test-file.txt" ,
1526
+ "content" : fmt .Sprintf ("Created by e2e test %s\n with multiple lines" , t .Name ()),
1527
+ "message" : "Add test file" ,
1528
+ "branch" : "test-branch" ,
1529
+ }
1530
+
1531
+ t .Logf ("Creating commit with new file in %s/%s..." , currentOwner , repoName )
1532
+ resp , err = mcpClient .CallTool (ctx , commitRequest )
1533
+ require .NoError (t , err , "expected to call 'create_or_update_file' tool successfully" )
1534
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1535
+
1536
+ textContent , ok = resp .Content [0 ].(mcp.TextContent )
1537
+ require .True (t , ok , "expected content to be of type TextContent" )
1538
+
1539
+ var trimmedCommitText struct {
1540
+ Commit struct {
1541
+ SHA string `json:"sha"`
1542
+ } `json:"commit"`
1543
+ }
1544
+ err = json .Unmarshal ([]byte (textContent .Text ), & trimmedCommitText )
1545
+ require .NoError (t , err , "expected to unmarshal text content successfully" )
1546
+
1547
+ // Create a pull request
1548
+ prRequest := mcp.CallToolRequest {}
1549
+ prRequest .Params .Name = "create_pull_request"
1550
+ prRequest .Params .Arguments = map [string ]any {
1551
+ "owner" : currentOwner ,
1552
+ "repo" : repoName ,
1553
+ "title" : "Test PR" ,
1554
+ "body" : "This is a test PR" ,
1555
+ "head" : "test-branch" ,
1556
+ "base" : "main" ,
1557
+ }
1558
+
1559
+ t .Logf ("Creating pull request in %s/%s..." , currentOwner , repoName )
1560
+ resp , err = mcpClient .CallTool (ctx , prRequest )
1561
+ require .NoError (t , err , "expected to call 'create_pull_request' tool successfully" )
1562
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1563
+
1564
+ // Create a review for the pull request, but we can't approve it
1565
+ // because the current owner also owns the PR.
1566
+ createPendingPullRequestReviewRequest := mcp.CallToolRequest {}
1567
+ createPendingPullRequestReviewRequest .Params .Name = "create_pending_pull_request_review"
1568
+ createPendingPullRequestReviewRequest .Params .Arguments = map [string ]any {
1569
+ "owner" : currentOwner ,
1570
+ "repo" : repoName ,
1571
+ "pullNumber" : 1 ,
1572
+ }
1573
+
1574
+ t .Logf ("Creating pending review for pull request in %s/%s..." , currentOwner , repoName )
1575
+ resp , err = mcpClient .CallTool (ctx , createPendingPullRequestReviewRequest )
1576
+ require .NoError (t , err , "expected to call 'create_pending_pull_request_review' tool successfully" )
1577
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1578
+
1579
+ textContent , ok = resp .Content [0 ].(mcp.TextContent )
1580
+ require .True (t , ok , "expected content to be of type TextContent" )
1581
+ require .Equal (t , "pending pull request created" , textContent .Text )
1582
+
1583
+ t .Logf ("Creating an issue in %s/%s..." , currentOwner , repoName )
1584
+ createIssueRequest := mcp.CallToolRequest {}
1585
+ createIssueRequest .Params .Name = "create_issue"
1586
+ createIssueRequest .Params .Arguments = map [string ]any {
1587
+ "owner" : currentOwner ,
1588
+ "repo" : repoName ,
1589
+ "title" : "Test Issue" ,
1590
+ "body" : "This is a test issue" ,
1591
+ }
1592
+ resp , err = mcpClient .CallTool (ctx , createIssueRequest )
1593
+ require .NoError (t , err , "expected to call 'create_issue' tool successfully" )
1594
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1595
+
1596
+ // List issues in the repository
1597
+ listIssuesRequest := mcp.CallToolRequest {}
1598
+ listIssuesRequest .Params .Name = "list_issues"
1599
+ listIssuesRequest .Params .Arguments = map [string ]any {
1600
+ "owner" : currentOwner ,
1601
+ "repo" : repoName ,
1602
+ }
1603
+
1604
+ t .Logf ("Listing issues in %s/%s..." , currentOwner , repoName )
1605
+ resp , err = mcpClient .CallTool (ctx , listIssuesRequest )
1606
+ require .NoError (t , err , "expected to call 'list_issues' tool successfully" )
1607
+ require .False (t , resp .IsError , fmt .Sprintf ("expected result not to be an error: %+v" , resp ))
1608
+
1609
+ textContent , ok = resp .Content [0 ].(mcp.TextContent )
1610
+ require .True (t , ok , "expected content to be of type TextContent" )
1611
+
1612
+ var issues []struct {
1613
+ ID int `json:"id"`
1614
+ Number int `json:"number"`
1615
+ Title string `json:"title"`
1616
+ Body string `json:"body"`
1617
+ }
1618
+ err = json .Unmarshal ([]byte (textContent .Text ), & issues )
1619
+ require .NoError (t , err , "expected to unmarshal text content successfully" )
1620
+ require .Len (t , issues , 1 , "expected to find one issue" )
1621
+ }
1622
+
1450
1623
func TestPullRequestReviewDeletion (t * testing.T ) {
1451
1624
t .Parallel ()
1452
1625
0 commit comments