@@ -264,18 +264,25 @@ public function getRepositoryTree(string $owner, string $repositoryName, string
264264 * @param string $message Commit message
265265 * @return array<mixed> Response from API
266266 */
267- public function createFile (string $ owner , string $ repositoryName , string $ filepath , string $ content , string $ message = 'Add file ' ): array
267+ public function createFile (string $ owner , string $ repositoryName , string $ filepath , string $ content , string $ message = 'Add file ' , string $ branch = '' ): array
268268 {
269269 $ url = "/repos/ {$ owner }/ {$ repositoryName }/contents/ {$ filepath }" ;
270270
271+ $ payload = [
272+ 'content ' => base64_encode ($ content ),
273+ 'message ' => $ message
274+ ];
275+
276+ // Add branch if specified
277+ if (!empty ($ branch )) {
278+ $ payload ['branch ' ] = $ branch ;
279+ }
280+
271281 $ response = $ this ->call (
272282 self ::METHOD_POST ,
273283 $ url ,
274284 ['Authorization ' => "token $ this ->accessToken " ],
275- [
276- 'content ' => base64_encode ($ content ),
277- 'message ' => $ message
278- ]
285+ $ payload
279286 );
280287
281288 $ responseHeaders = $ response ['headers ' ] ?? [];
@@ -423,19 +430,100 @@ public function deleteRepository(string $owner, string $repositoryName): bool
423430 return true ;
424431 }
425432
433+ /**
434+ * Create a pull request
435+ *
436+ * @param string $owner Owner of the repository
437+ * @param string $repositoryName Name of the repository
438+ * @param string $title PR title
439+ * @param string $head Source branch
440+ * @param string $base Target branch
441+ * @param string $body PR description (optional)
442+ * @return array<mixed> Created PR details
443+ */
444+ public function createPullRequest (string $ owner , string $ repositoryName , string $ title , string $ head , string $ base , string $ body = '' ): array
445+ {
446+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/pulls " ;
447+
448+ $ payload = [
449+ 'title ' => $ title ,
450+ 'head ' => $ head ,
451+ 'base ' => $ base ,
452+ ];
453+
454+ if (!empty ($ body )) {
455+ $ payload ['body ' ] = $ body ;
456+ }
457+
458+ $ response = $ this ->call (
459+ self ::METHOD_POST ,
460+ $ url ,
461+ ['Authorization ' => "token $ this ->accessToken " ],
462+ $ payload
463+ );
464+
465+ $ responseHeaders = $ response ['headers ' ] ?? [];
466+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
467+ if ($ responseHeadersStatusCode >= 400 ) {
468+ throw new Exception ("Failed to create pull request: HTTP {$ responseHeadersStatusCode }" );
469+ }
470+
471+ $ responseBody = $ response ['body ' ] ?? [];
472+
473+ return $ responseBody ;
474+ }
475+
426476 public function createComment (string $ owner , string $ repositoryName , int $ pullRequestNumber , string $ comment ): string
427477 {
428- throw new Exception ("Not implemented yet " );
478+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/issues/ {$ pullRequestNumber }/comments " ;
479+
480+ $ response = $ this ->call (self ::METHOD_POST , $ url , ['Authorization ' => "token $ this ->accessToken " ], ['body ' => $ comment ]);
481+
482+ $ responseHeaders = $ response ['headers ' ] ?? [];
483+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
484+ if ($ responseHeadersStatusCode >= 400 ) {
485+ throw new Exception ("Failed to create comment: HTTP {$ responseHeadersStatusCode }" );
486+ }
487+
488+ $ responseBody = $ response ['body ' ] ?? [];
489+
490+ if (!array_key_exists ('id ' , $ responseBody )) {
491+ throw new Exception ("Comment creation response is missing comment ID. " );
492+ }
493+
494+ return (string ) ($ responseBody ['id ' ] ?? '' );
429495 }
430496
431497 public function getComment (string $ owner , string $ repositoryName , string $ commentId ): string
432498 {
433- throw new Exception ("Not implemented yet " );
499+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/issues/comments/ {$ commentId }" ;
500+
501+ $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "token $ this ->accessToken " ]);
502+
503+ $ responseBody = $ response ['body ' ] ?? [];
504+
505+ return $ responseBody ['body ' ] ?? '' ;
434506 }
435507
436508 public function updateComment (string $ owner , string $ repositoryName , int $ commentId , string $ comment ): string
437509 {
438- throw new Exception ("Not implemented yet " );
510+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/issues/comments/ {$ commentId }" ;
511+
512+ $ response = $ this ->call (self ::METHOD_PATCH , $ url , ['Authorization ' => "token $ this ->accessToken " ], ['body ' => $ comment ]);
513+
514+ $ responseHeaders = $ response ['headers ' ] ?? [];
515+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
516+ if ($ responseHeadersStatusCode >= 400 ) {
517+ throw new Exception ("Failed to update comment: HTTP {$ responseHeadersStatusCode }" );
518+ }
519+
520+ $ responseBody = $ response ['body ' ] ?? [];
521+
522+ if (!array_key_exists ('id ' , $ responseBody )) {
523+ throw new Exception ("Comment update response is missing comment ID. " );
524+ }
525+
526+ return (string ) ($ responseBody ['id ' ] ?? '' );
439527 }
440528
441529 public function getUser (string $ username ): array
@@ -450,12 +538,35 @@ public function getOwnerName(string $installationId): string
450538
451539 public function getPullRequest (string $ owner , string $ repositoryName , int $ pullRequestNumber ): array
452540 {
453- throw new Exception ("Not implemented yet " );
541+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/pulls/ {$ pullRequestNumber }" ;
542+
543+ $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "token $ this ->accessToken " ]);
544+
545+ $ responseHeaders = $ response ['headers ' ] ?? [];
546+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
547+ if ($ responseHeadersStatusCode >= 400 ) {
548+ throw new Exception ("Failed to get pull request: HTTP {$ responseHeadersStatusCode }" );
549+ }
550+
551+ return $ response ['body ' ] ?? [];
454552 }
455553
456554 public function getPullRequestFromBranch (string $ owner , string $ repositoryName , string $ branch ): array
457555 {
458- throw new Exception ("Not implemented yet " );
556+
557+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/pulls?state=open&head= " . urlencode ($ branch );
558+
559+ $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "token $ this ->accessToken " ]);
560+
561+ $ responseHeaders = $ response ['headers ' ] ?? [];
562+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
563+ if ($ responseHeadersStatusCode >= 400 ) {
564+ throw new Exception ("Failed to list pull requests: HTTP {$ responseHeadersStatusCode }" );
565+ }
566+
567+ $ responseBody = $ response ['body ' ] ?? [];
568+
569+ return $ responseBody [0 ] ?? [];
459570 }
460571
461572 /**
0 commit comments