Skip to content

Commit 774c43b

Browse files
committed
record and display URL
1 parent 3252d8e commit 774c43b

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/components/SuggestionForm.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { page } from '$app/state'
23
import { resize_textarea } from '$lib/client/utils'
34
import { faCheckCircle, faWarning } from '@fortawesome/free-solid-svg-icons'
45
import { tick } from 'svelte'
@@ -20,7 +21,7 @@
2021
try {
2122
const res = await fetch('/api/issue', {
2223
method: 'POST',
23-
body: JSON.stringify({ title, body }),
24+
body: JSON.stringify({ title, body, url: page.url.href }),
2425
})
2526
2627
const res_json = await res.json()

src/routes/api/issue/+server.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,26 @@ export const POST = async (event) => {
3636

3737
if ('error' in data) return json({ error: data.error }, { status: 400 })
3838

39-
const { title, body } = data
39+
const { title, body, url } = data
4040

4141
if (has_profanity(title, body)) {
4242
await flag_violation(ip, 'profanity')
4343
return json({ error: 'Profanity detected' }, { status: 400 })
4444
}
4545

46+
const full_body =
47+
body +
48+
'\n\n---\n' +
49+
`This issue has been created via the submission form on ${url}`
50+
4651
try {
4752
const octokit = await app.getInstallationOctokit(Number(GITHUB_INSTALLATION_ID))
4853

4954
const issue = await octokit.request('POST /repos/{owner}/{repo}/issues', {
5055
owner: GITHUB_OWNER,
5156
repo: GITHUB_REPO,
5257
title,
53-
body,
58+
body: full_body,
5459
})
5560

5661
return json({ url: issue.data.html_url })
@@ -62,21 +67,23 @@ export const POST = async (event) => {
6267

6368
async function parse_data(
6469
request: Request,
65-
): Promise<{ error: string } | { title: string; body: string }> {
70+
): Promise<{ error: string } | { title: string; body: string; url: string }> {
6671
let data
6772
try {
6873
data = await request.json()
6974
} catch (_) {
7075
return { error: 'Invalid request body' }
7176
}
7277

73-
const { title, body } = data
78+
const { title, body, url } = data
7479

7580
if (!title) return { error: 'Title required' }
7681
if (!body) return { error: 'Body required' }
82+
if (!url) return { error: 'URL required' }
7783

7884
if (typeof title !== 'string') return { error: 'Title must be a string' }
7985
if (typeof body !== 'string') return { error: 'Body must be a string' }
86+
if (typeof url !== 'string') return { error: 'URL must be a string' }
8087

8188
if (title.length > TITLE_MAX_LENGTH) {
8289
return { error: `Title must have at most ${TITLE_MAX_LENGTH} characters` }
@@ -85,5 +92,9 @@ async function parse_data(
8592
return { error: `Body must have at most ${BODY_MAX_LENGTH} characters` }
8693
}
8794

88-
return { title, body }
95+
if (!url.startsWith('https://') && !url.startsWith('http://')) {
96+
return { error: 'URL must be a valid URL' }
97+
}
98+
99+
return { title, body, url }
89100
}

0 commit comments

Comments
 (0)