Skip to content

Commit

Permalink
fix: Handle exceptions when PR isn't a template
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciolauffer committed Nov 22, 2023
1 parent 2b4d283 commit f56055a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/create_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import {parse, toMd} from 'md-2-json';
}
*/
async function main() {
const body = process.env.Body;
const jsonBody = parse(body);
const templateName = jsonBody.Title.raw.replace(/\s/g, '');
const rawName = jsonBody.Title.raw.replace(/\n/g, '');
const files = await readdir('./upload/', {withFileTypes: true, encoding: 'utf-8'});
const regex = /\.xml$/;
if (files.length !== 2 || (!regex.test(files[0].name) && !regex.test(files[1].name))) {
throw new Error('File isn\'t uploaded into the upload directory or file is not XML');
}

try {
const body = process.env.Body;
const jsonBody = parse(body);
const templateName = jsonBody.Title.raw.replace(/\s/g, '');
const rawName = jsonBody.Title.raw.replace(/\n/g, '');
const filename = files.find((file) => file.name.includes('xml'))?.name;
const targetFileName = filename.replace(/\s/g, '');
const path = `./src/templates/${templateName}`;
Expand Down

0 comments on commit f56055a

Please sign in to comment.