|
178 | 178 | } |
179 | 179 | }); |
180 | 180 | }); |
181 | | -
|
182 | | - let createPullRequestHandler = $state(async (): Promise<void> => { |
183 | | - const title = `Pull request for ${$currentFile}`; |
184 | | - const description = `This pull request contains changes made by ${$me.username}.`; |
185 | | - const headBranch = $branchName; |
186 | | -
|
187 | | - const response = await fetch(`${apiAddress}/api/pulls`, { |
188 | | - method: 'POST', |
189 | | - credentials: 'include', |
190 | | - headers: { |
191 | | - 'Content-Type': 'application/json' |
192 | | - }, |
193 | | - body: JSON.stringify({ |
194 | | - head_branch: headBranch, |
195 | | - base_branch: 'master', |
196 | | - title: title, |
197 | | - description: description |
198 | | - }) |
199 | | - }); |
200 | | -
|
201 | | - // Handle the response |
202 | | - if (!response.ok) { |
203 | | - const errorMessage = `Failed to create pull request (Code ${response.status}: "${response.statusText}")`; |
204 | | - addToast({ |
205 | | - message: `Error: ${errorMessage}`, |
206 | | - type: ToastType.Error, |
207 | | - dismissible: true |
208 | | - }); |
209 | | - return; // Exit the function early on error |
210 | | - } |
211 | | -
|
212 | | - // Parse the JSON response to get the pull request URL |
213 | | - const jsonResponse = await response.json(); |
214 | | - const pullRequestUrl = jsonResponse.data?.pull_request_url; // Adjusted based on API response |
215 | | -
|
216 | | - if (pullRequestUrl) { |
217 | | - // If successful, show success toast with the URL |
218 | | - addToast({ |
219 | | - message: `Pull request created successfully. View it [here](${pullRequestUrl}).`, |
220 | | - type: ToastType.Success, |
221 | | - dismissible: true |
222 | | - }); |
223 | | - } else { |
224 | | - // Handle the case where the URL is not present (if needed) |
225 | | - addToast({ |
226 | | - message: 'Pull request created successfully, but the URL is not available.', |
227 | | - type: ToastType.Warning, |
228 | | - dismissible: true |
229 | | - }); |
230 | | - } |
231 | | - }); |
232 | 181 | </script> |
233 | 182 |
|
234 | 183 | <div style="--sidebar-width: {sidebarWidth}" class="container"> |
|
273 | 222 | /> |
274 | 223 | {#if mode === SelectedMode.Documents} |
275 | 224 | {#if showEditor && $currentFile !== ''} |
276 | | - <DocumentEditor |
277 | | - bind:saveChangesHandler |
278 | | - bind:previewWindow={previewWindow!} |
279 | | - bind:createPullRequestHandler |
280 | | - /> |
| 225 | + <DocumentEditor bind:saveChangesHandler bind:previewWindow={previewWindow!} /> |
281 | 226 | {:else} |
282 | 227 | <span class="nofile-placeholder"> |
283 | 228 | <p> |
|
0 commit comments