@@ -188,18 +188,25 @@ public function getRepositoryTree(string $owner, string $repositoryName, string
188188 * @param string $message Commit message
189189 * @return array<mixed> Response from API
190190 */
191- public function createFile (string $ owner , string $ repositoryName , string $ filepath , string $ content , string $ message = 'Add file ' ): array
191+ public function createFile (string $ owner , string $ repositoryName , string $ filepath , string $ content , string $ message = 'Add file ' , string $ branch = '' ): array
192192 {
193193 $ url = "/repos/ {$ owner }/ {$ repositoryName }/contents/ {$ filepath }" ;
194194
195+ $ payload = [
196+ 'content ' => base64_encode ($ content ),
197+ 'message ' => $ message
198+ ];
199+
200+ // Add branch if specified
201+ if (!empty ($ branch )) {
202+ $ payload ['branch ' ] = $ branch ;
203+ }
204+
195205 $ response = $ this ->call (
196206 self ::METHOD_POST ,
197207 $ url ,
198208 ['Authorization ' => "token $ this ->accessToken " ],
199- [
200- 'content ' => base64_encode ($ content ),
201- 'message ' => $ message
202- ]
209+ $ payload
203210 );
204211
205212 $ responseHeaders = $ response ['headers ' ] ?? [];
@@ -347,19 +354,100 @@ public function deleteRepository(string $owner, string $repositoryName): bool
347354 return true ;
348355 }
349356
357+ /**
358+ * Create a pull request
359+ *
360+ * @param string $owner Owner of the repository
361+ * @param string $repositoryName Name of the repository
362+ * @param string $title PR title
363+ * @param string $head Source branch
364+ * @param string $base Target branch
365+ * @param string $body PR description (optional)
366+ * @return array<mixed> Created PR details
367+ */
368+ public function createPullRequest (string $ owner , string $ repositoryName , string $ title , string $ head , string $ base , string $ body = '' ): array
369+ {
370+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/pulls " ;
371+
372+ $ payload = [
373+ 'title ' => $ title ,
374+ 'head ' => $ head ,
375+ 'base ' => $ base ,
376+ ];
377+
378+ if (!empty ($ body )) {
379+ $ payload ['body ' ] = $ body ;
380+ }
381+
382+ $ response = $ this ->call (
383+ self ::METHOD_POST ,
384+ $ url ,
385+ ['Authorization ' => "token $ this ->accessToken " ],
386+ $ payload
387+ );
388+
389+ $ responseHeaders = $ response ['headers ' ] ?? [];
390+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
391+ if ($ responseHeadersStatusCode >= 400 ) {
392+ throw new Exception ("Failed to create pull request: HTTP {$ responseHeadersStatusCode }" );
393+ }
394+
395+ $ responseBody = $ response ['body ' ] ?? [];
396+
397+ return $ responseBody ;
398+ }
399+
350400 public function createComment (string $ owner , string $ repositoryName , int $ pullRequestNumber , string $ comment ): string
351401 {
352- throw new Exception ("Not implemented yet " );
402+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/issues/ {$ pullRequestNumber }/comments " ;
403+
404+ $ response = $ this ->call (self ::METHOD_POST , $ url , ['Authorization ' => "token $ this ->accessToken " ], ['body ' => $ comment ]);
405+
406+ $ responseHeaders = $ response ['headers ' ] ?? [];
407+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
408+ if ($ responseHeadersStatusCode >= 400 ) {
409+ throw new Exception ("Failed to create comment: HTTP {$ responseHeadersStatusCode }" );
410+ }
411+
412+ $ responseBody = $ response ['body ' ] ?? [];
413+
414+ if (!array_key_exists ('id ' , $ responseBody )) {
415+ throw new Exception ("Comment creation response is missing comment ID. " );
416+ }
417+
418+ return (string ) ($ responseBody ['id ' ] ?? '' );
353419 }
354420
355421 public function getComment (string $ owner , string $ repositoryName , string $ commentId ): string
356422 {
357- throw new Exception ("Not implemented yet " );
423+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/issues/comments/ {$ commentId }" ;
424+
425+ $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "token $ this ->accessToken " ]);
426+
427+ $ responseBody = $ response ['body ' ] ?? [];
428+
429+ return $ responseBody ['body ' ] ?? '' ;
358430 }
359431
360432 public function updateComment (string $ owner , string $ repositoryName , int $ commentId , string $ comment ): string
361433 {
362- throw new Exception ("Not implemented yet " );
434+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/issues/comments/ {$ commentId }" ;
435+
436+ $ response = $ this ->call (self ::METHOD_PATCH , $ url , ['Authorization ' => "token $ this ->accessToken " ], ['body ' => $ comment ]);
437+
438+ $ responseHeaders = $ response ['headers ' ] ?? [];
439+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
440+ if ($ responseHeadersStatusCode >= 400 ) {
441+ throw new Exception ("Failed to update comment: HTTP {$ responseHeadersStatusCode }" );
442+ }
443+
444+ $ responseBody = $ response ['body ' ] ?? [];
445+
446+ if (!array_key_exists ('id ' , $ responseBody )) {
447+ throw new Exception ("Comment update response is missing comment ID. " );
448+ }
449+
450+ return (string ) ($ responseBody ['id ' ] ?? '' );
363451 }
364452
365453 public function getUser (string $ username ): array
@@ -374,12 +462,35 @@ public function getOwnerName(string $installationId): string
374462
375463 public function getPullRequest (string $ owner , string $ repositoryName , int $ pullRequestNumber ): array
376464 {
377- throw new Exception ("Not implemented yet " );
465+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/pulls/ {$ pullRequestNumber }" ;
466+
467+ $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "token $ this ->accessToken " ]);
468+
469+ $ responseHeaders = $ response ['headers ' ] ?? [];
470+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
471+ if ($ responseHeadersStatusCode >= 400 ) {
472+ throw new Exception ("Failed to get pull request: HTTP {$ responseHeadersStatusCode }" );
473+ }
474+
475+ return $ response ['body ' ] ?? [];
378476 }
379477
380478 public function getPullRequestFromBranch (string $ owner , string $ repositoryName , string $ branch ): array
381479 {
382- throw new Exception ("Not implemented yet " );
480+
481+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/pulls?state=open&head= " . urlencode ($ branch );
482+
483+ $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "token $ this ->accessToken " ]);
484+
485+ $ responseHeaders = $ response ['headers ' ] ?? [];
486+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
487+ if ($ responseHeadersStatusCode >= 400 ) {
488+ throw new Exception ("Failed to list pull requests: HTTP {$ responseHeadersStatusCode }" );
489+ }
490+
491+ $ responseBody = $ response ['body ' ] ?? [];
492+
493+ return $ responseBody [0 ] ?? [];
383494 }
384495
385496 public function listBranches (string $ owner , string $ repositoryName ): array
0 commit comments