@@ -93,20 +93,61 @@ public function createRepository(string $owner, string $repositoryName, bool $pr
9393
9494 return $ response ['body ' ] ?? [];
9595 }
96+ /**
97+ * Create a pull request
98+ *
99+ * @param string $owner Owner of the repository
100+ * @param string $repositoryName Name of the repository
101+ * @param string $title PR title
102+ * @param string $head Source branch
103+ * @param string $base Target branch
104+ * @param string $body PR description (optional)
105+ * @return array<mixed> Created PR details
106+ */
107+ public function createPullRequest (string $ owner , string $ repositoryName , string $ title , string $ head , string $ base , string $ body = '' ): array
108+ {
109+ throw new Exception ('Not implemented ' );
110+ }
96111
97112 /**
98113 * Create a file in a repository
99114 *
100- * @param string $owner Owner of the repository
101- * @param string $repositoryName Name of the repository
102- * @param string $filepath Path where file should be created
103- * @param string $content Content of the file
104- * @param string $message Commit message
115+ * @param string $owner Owner of the repository
116+ * @param string $repositoryName Name of the repository
117+ * @param string $filepath Path where file should be created
118+ * @param string $content Content of the file
119+ * @param string $message Commit message
120+ * @param string $branch Branch to create file on (optional)
105121 * @return array<mixed> Response from API
106122 */
107- public function createFile (string $ owner , string $ repositoryName , string $ filepath , string $ content , string $ message = 'Add file ' ): array
123+ public function createFile (string $ owner , string $ repositoryName , string $ filepath , string $ content , string $ message = 'Add file ' , string $ branch = '' ): array
108124 {
109- throw new Exception ("Not implemented " );
125+ $ url = "/repos/ {$ owner }/ {$ repositoryName }/contents/ {$ filepath }" ;
126+
127+ $ payload = [
128+ 'message ' => $ message ,
129+ 'content ' => base64_encode ($ content ),
130+ ];
131+
132+ // GitHub supports branch parameter
133+ if (! empty ($ branch )) {
134+ $ payload ['branch ' ] = $ branch ;
135+ }
136+
137+ $ response = $ this ->call (
138+ self ::METHOD_PUT ,
139+ $ url ,
140+ ['Authorization ' => "Bearer $ this ->accessToken " ],
141+ $ payload
142+ );
143+
144+ $ responseHeaders = $ response ['headers ' ] ?? [];
145+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
146+ if ($ responseHeadersStatusCode >= 400 ) {
147+ throw new Exception ("Failed to create file {$ filepath }: HTTP {$ responseHeadersStatusCode }" );
148+ }
149+
150+ return $ response ['body ' ] ?? [];
110151 }
111152
112153 /**
0 commit comments