@@ -522,3 +522,181 @@ func TestGranularCreatePullRequestReview(t *testing.T) {
522522 require .NoError (t , err )
523523 assert .False (t , result .IsError )
524524}
525+
526+ func TestGranularUpdatePullRequestDraftState (t * testing.T ) {
527+ tests := []struct {
528+ name string
529+ draft bool
530+ }{
531+ {name : "convert to draft" , draft : true },
532+ {name : "mark ready for review" , draft : false },
533+ }
534+
535+ for _ , tc := range tests {
536+ t .Run (tc .name , func (t * testing.T ) {
537+ var matchers []githubv4mock.Matcher
538+
539+ matchers = append (matchers , githubv4mock .NewQueryMatcher (
540+ struct {
541+ Repository struct {
542+ PullRequest struct {
543+ ID githubv4.ID
544+ } `graphql:"pullRequest(number: $number)"`
545+ } `graphql:"repository(owner: $owner, name: $name)"`
546+ }{},
547+ map [string ]any {
548+ "owner" : githubv4 .String ("owner" ),
549+ "name" : githubv4 .String ("repo" ),
550+ "number" : githubv4 .Int (1 ),
551+ },
552+ githubv4mock .DataResponse (map [string ]any {
553+ "repository" : map [string ]any {
554+ "pullRequest" : map [string ]any {"id" : "PR_123" },
555+ },
556+ }),
557+ ))
558+
559+ if tc .draft {
560+ matchers = append (matchers , githubv4mock .NewMutationMatcher (
561+ struct {
562+ ConvertPullRequestToDraft struct {
563+ PullRequest struct {
564+ ID githubv4.ID
565+ IsDraft githubv4.Boolean
566+ }
567+ } `graphql:"convertPullRequestToDraft(input: $input)"`
568+ }{},
569+ githubv4.ConvertPullRequestToDraftInput {PullRequestID : githubv4 .ID ("PR_123" )},
570+ nil ,
571+ githubv4mock .DataResponse (map [string ]any {
572+ "convertPullRequestToDraft" : map [string ]any {
573+ "pullRequest" : map [string ]any {"id" : "PR_123" , "isDraft" : true },
574+ },
575+ }),
576+ ))
577+ } else {
578+ matchers = append (matchers , githubv4mock .NewMutationMatcher (
579+ struct {
580+ MarkPullRequestReadyForReview struct {
581+ PullRequest struct {
582+ ID githubv4.ID
583+ IsDraft githubv4.Boolean
584+ }
585+ } `graphql:"markPullRequestReadyForReview(input: $input)"`
586+ }{},
587+ githubv4.MarkPullRequestReadyForReviewInput {PullRequestID : githubv4 .ID ("PR_123" )},
588+ nil ,
589+ githubv4mock .DataResponse (map [string ]any {
590+ "markPullRequestReadyForReview" : map [string ]any {
591+ "pullRequest" : map [string ]any {"id" : "PR_123" , "isDraft" : false },
592+ },
593+ }),
594+ ))
595+ }
596+
597+ gqlClient := githubv4 .NewClient (githubv4mock .NewMockedHTTPClient (matchers ... ))
598+ deps := BaseDeps {GQLClient : gqlClient }
599+ serverTool := GranularUpdatePullRequestDraftState (translations .NullTranslationHelper )
600+ handler := serverTool .Handler (deps )
601+
602+ request := createMCPRequest (map [string ]any {
603+ "owner" : "owner" ,
604+ "repo" : "repo" ,
605+ "pullNumber" : float64 (1 ),
606+ "draft" : tc .draft ,
607+ })
608+ result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
609+ require .NoError (t , err )
610+ assert .False (t , result .IsError )
611+ })
612+ }
613+ }
614+
615+ func TestGranularAddPullRequestReviewComment (t * testing.T ) {
616+ mockedClient := githubv4mock .NewMockedHTTPClient (
617+ githubv4mock .NewQueryMatcher (
618+ struct {
619+ Viewer struct {
620+ Login githubv4.String
621+ }
622+ }{},
623+ nil ,
624+ githubv4mock .DataResponse (map [string ]any {
625+ "viewer" : map [string ]any {"login" : "testuser" },
626+ }),
627+ ),
628+ githubv4mock .NewQueryMatcher (
629+ struct {
630+ Repository struct {
631+ PullRequest struct {
632+ Reviews struct {
633+ Nodes []struct {
634+ ID githubv4.ID
635+ State githubv4.PullRequestReviewState
636+ URL githubv4.URI
637+ }
638+ } `graphql:"reviews(first: 1, author: $author)"`
639+ } `graphql:"pullRequest(number: $prNum)"`
640+ } `graphql:"repository(owner: $owner, name: $name)"`
641+ }{},
642+ map [string ]any {
643+ "author" : githubv4 .String ("testuser" ),
644+ "owner" : githubv4 .String ("owner" ),
645+ "name" : githubv4 .String ("repo" ),
646+ "prNum" : githubv4 .Int (1 ),
647+ },
648+ githubv4mock .DataResponse (map [string ]any {
649+ "repository" : map [string ]any {
650+ "pullRequest" : map [string ]any {
651+ "reviews" : map [string ]any {
652+ "nodes" : []map [string ]any {
653+ {"id" : "PRR_123" , "state" : "PENDING" , "url" : "https://github.com/owner/repo/pull/1#pullrequestreview-123" },
654+ },
655+ },
656+ },
657+ },
658+ }),
659+ ),
660+ githubv4mock .NewMutationMatcher (
661+ struct {
662+ AddPullRequestReviewThread struct {
663+ Thread struct {
664+ ID githubv4.ID
665+ }
666+ } `graphql:"addPullRequestReviewThread(input: $input)"`
667+ }{},
668+ githubv4.AddPullRequestReviewThreadInput {
669+ Path : githubv4 .String ("src/main.go" ),
670+ Body : githubv4 .String ("This needs a fix" ),
671+ SubjectType : githubv4mock .Ptr (githubv4 .PullRequestReviewThreadSubjectTypeLine ),
672+ Line : githubv4mock .Ptr (githubv4 .Int (42 )),
673+ Side : githubv4mock .Ptr (githubv4 .DiffSideRight ),
674+ PullRequestReviewID : githubv4mock .Ptr (githubv4 .ID ("PRR_123" )),
675+ },
676+ nil ,
677+ githubv4mock .DataResponse (map [string ]any {
678+ "addPullRequestReviewThread" : map [string ]any {
679+ "thread" : map [string ]any {"id" : "PRRT_456" },
680+ },
681+ }),
682+ ),
683+ )
684+ gqlClient := githubv4 .NewClient (mockedClient )
685+ deps := BaseDeps {GQLClient : gqlClient }
686+ serverTool := GranularAddPullRequestReviewComment (translations .NullTranslationHelper )
687+ handler := serverTool .Handler (deps )
688+
689+ request := createMCPRequest (map [string ]any {
690+ "owner" : "owner" ,
691+ "repo" : "repo" ,
692+ "pullNumber" : float64 (1 ),
693+ "path" : "src/main.go" ,
694+ "body" : "This needs a fix" ,
695+ "subjectType" : "LINE" ,
696+ "line" : float64 (42 ),
697+ "side" : "RIGHT" ,
698+ })
699+ result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
700+ require .NoError (t , err )
701+ assert .False (t , result .IsError )
702+ }
0 commit comments