@@ -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
6368async 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