Skip to content

Commit 07351b4

Browse files
committed
add place to submit GitHub issues
1 parent ebc84a0 commit 07351b4

3 files changed

Lines changed: 117 additions & 2 deletions

File tree

src/routes/api/create-issue.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { RequestHandler } from '@sveltejs/kit'
2+
3+
export const post: RequestHandler = async ({ rawBody }) => {
4+
const body = JSON.parse(rawBody.toString())
5+
const { description, finale, os, script, name, email } = body
6+
const fullName = name?.full ?? ''
7+
if (
8+
typeof description !== 'string' ||
9+
typeof finale !== 'string' ||
10+
typeof os !== 'string' ||
11+
typeof script !== 'string' ||
12+
typeof fullName !== 'string' ||
13+
typeof email !== 'string'
14+
) {
15+
return {
16+
status: 400,
17+
body: {
18+
url: '',
19+
},
20+
}
21+
}
22+
const response = await fetch('https://api.github.com/repos/Nick-Mazuk/jw-lua-scripts/issues', {
23+
method: 'POST',
24+
headers: {
25+
Authorization: `Basic ${Buffer.from(
26+
`Nick-Mazuk:${import.meta.env.VITE_GITHUB_ACCESS_TOKEN}`
27+
).toString('base64url')}`,
28+
accept: 'application/vnd.github.v3+json',
29+
},
30+
body: JSON.stringify({
31+
title: `Bug report`,
32+
labels: ['bug'],
33+
body: `**Description**\n\n${description}\n\n**Metadata**\n\n- ${finale}\n- ${os}\n- Script: ${script}\n\n_Created through the website${
34+
fullName || email ? `by ${fullName} ${email}` : ''
35+
}_`,
36+
}),
37+
})
38+
const json = await response.json()
39+
40+
return {
41+
status: response.status === 201 ? 200 : response.status,
42+
body: {
43+
url: json.html_url,
44+
},
45+
}
46+
}

src/routes/help/issue.svelte

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
<script lang="ts">
22
import { page } from '$app/stores'
33
4+
import scriptData from '../../lib/lib/script-data.json'
5+
import type { ScriptData } from '../../lib/types/script-data'
6+
47
import FormEntity from '@nick-mazuk/ui-svelte/src/form/form-entity/form-entity.svelte'
58
import EmailInput from '@nick-mazuk/ui-svelte/src/form/inputs/email-input/email-input.svelte'
9+
import NameInput from '@nick-mazuk/ui-svelte/src/form/inputs/name-input/name-input.svelte'
610
import TextInput from '@nick-mazuk/ui-svelte/src/form/inputs/text-input/text-input.svelte'
11+
import Select from '@nick-mazuk/ui-svelte/src/form/inputs/select/select.svelte'
712
813
import Seo from '@nick-mazuk/ui-svelte/src/utilities/seo/seo.svelte'
914
import Spacer from '@nick-mazuk/ui-svelte/src/utilities/spacer/spacer.svelte'
1015
1116
import luaLogo from '$lib/assets/images/lua-logo.png'
17+
import type { HandleSubmit } from '@nick-mazuk/ui-svelte/src/form'
18+
import Note from '@nick-mazuk/ui-svelte/src/elements/note/note.svelte'
19+
20+
const scripts: ScriptData[] = scriptData
21+
let issueUrl = ''
22+
23+
const handleSubmit: HandleSubmit = async (data) => {
24+
const response = await fetch('/api/create-issue', {
25+
method: 'post',
26+
body: JSON.stringify(data),
27+
})
28+
const json = await response.json()
29+
30+
if (typeof json.url === 'string') issueUrl = json.url
31+
32+
return response.status === 200
33+
}
1234
</script>
1335

1436
<Seo
@@ -29,12 +51,57 @@
2951
<FormEntity
3052
title="Report an issue"
3153
primaryAction="Submit"
54+
handleSubmit="{handleSubmit}"
3255
description="Tell us about an issue you're having. Everything you submit will be publically available because this project is open source and we use GitHub to keep track of everything. This form will simply create an issue on GitHub without you needing a GitHub account."
56+
success="Submitted successfully"
57+
resetOnSubmit
3358
>
34-
<TextInput />
59+
<TextInput
60+
label="Describe your issue, steps to reproduce it, and expected behavor"
61+
name="description"
62+
placeholder="{`I encountered this.\n\nSteps to reproduce the behavior:\n1. Go to '...'\n2. Click on '....'\n3. Scroll down to '....'\n4. See error\n\nI expected this to happen.`}"
63+
type="textarea"
64+
defaultValue="IGNORE. This is a test for a new issue reporting system for the JW Lua scripts website. The page will allow users without GitHub accounts to create a GitHub issue like this one."
65+
maxCharacters="{1000}"
66+
/>
67+
<Select label="Finale version" name="finale" defaultValue="Finale v27">
68+
<option value="Finale v27">Finale v27</option>
69+
<option value="Finale v26">Finale v26</option>
70+
<option value="Finale v25">Finale v25</option>
71+
<option value="Finale 2014.5">Finale 2014.5</option>
72+
<option value="Finale 2014">Finale 2014</option>
73+
<option value="Finale below 2014">Finale below 2014</option>
74+
</Select>
75+
<Select label="Operating system" name="os" defaultValue="macOS 12">
76+
<option value="macOS 12">macOS 12: Monterey</option>
77+
<option value="macOS 11">macOS 11: Big Sur</option>
78+
<option value="macOS 10.15">macOS 10.15: Catalina</option>
79+
<option value="macOS 10.14">macOS 10.14: Mojave</option>
80+
<option value="macOS < 10.14">macOS below 10.14</option>
81+
<option value="Windows 11">Windows 11</option>
82+
<option value="Windows 10">Windows 10</option>
83+
<option value="Windows 8">Windows 8</option>
84+
<option value="Windows 7">Windows 7</option>
85+
</Select>
86+
<Select label="Script name" name="script" defaultValue="n/a">
87+
<option value="n/a">Not applicable</option>
88+
{#each scripts as script}
89+
<option value="{script.fileName}">{script.name}</option>
90+
{/each}
91+
</Select>
92+
<NameInput optional helpText="This will be public" />
3593
<EmailInput
36-
helpText="This will be public, we will only use it to contact you if we need more info or to let you know when it's resolved"
94+
helpText="This will be public, we will only use it to contact you if needed"
3795
optional
3896
/>
3997
</FormEntity>
98+
{#if issueUrl}
99+
<Spacer />
100+
<Note label="Success" variant="success">
101+
Your issue is created. You can view it at
102+
<a href="{issueUrl}" target="_blank" rel="noreferrer" class="border-b border-success">
103+
{issueUrl}
104+
</a>
105+
</Note>
106+
{/if}
40107
</main>

types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ interface ImportMetaEnv {
22
VITE_REDIS_ENDPOINT: string
33
VITE_REDIS_PORT: number
44
VITE_REDIS_PASSWORD: string
5+
6+
VITE_GITHUB_ACCESS_TOKEN: string
57
}

0 commit comments

Comments
 (0)