Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaLovesKPOP authored Oct 6, 2024
1 parent 6ad7953 commit 8993836
Showing 1 changed file with 85 additions and 37 deletions.
122 changes: 85 additions & 37 deletions blob/main/script.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
const form = document.getElementById('bug-report-form');
const token = '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'; // replace with your personal access token
const token = 'YOUR_NEW_TOKEN_HERE'; // replace with your new token
const projectNumber = 2; // replace with your project number
const repoOwner = 'MicaLovesKPOP'; // replace with your GitHub username
const repoName = 'crashdayhub'; // replace with your repository name

const debug = console.debug;
const info = console.info;
const warn = console.warn;
const error = console.error;

const logRequest = (method, url, headers, body) => {
debug(`Request: ${method} ${url}`);
debug(`Headers: ${JSON.stringify(headers)}`);
debug(`Body: ${JSON.stringify(body)}`);
};

const logResponse = (response) => {
debug(`Response: ${response.status} ${response.statusText}`);
debug(`Headers: ${JSON.stringify(response.headers)}`);
debug(`Body: ${response.body}`);
};

const logError = (error) => {
error(`Error: ${error.message}`);
error(`Stack: ${error.stack}`);
};

form.addEventListener('submit', async (event) => {
event.preventDefault();

const formData = new FormData(form);
const title = formData.get('title');
const description = formData.get('description');
const reproductionSteps = formData.get('reproduction-steps');
const expectedBehavior = formData.get('expected-behavior');
const actualBehavior = formData.get('actual-behavior');
const systemInfo = formData.get('system-info');

const apiEndpoint = `https://api.github.com/repos/${repoOwner}/${repoName}/issues`;
const headers = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
};

const issueBody = {
title,
body: `
try {
const formData = new FormData(form);
const title = formData.get('title');
const description = formData.get('description');
const reproductionSteps = formData.get('reproduction-steps');
const expectedBehavior = formData.get('expected-behavior');
const actualBehavior = formData.get('actual-behavior');
const systemInfo = formData.get('system-info');

info('Form data:', {
title,
description,
reproductionSteps,
expectedBehavior,
actualBehavior,
systemInfo
});

const apiEndpoint = `https://api.github.com/repos/${repoOwner}/${repoName}/issues`;
info('API endpoint:', apiEndpoint);

const headers = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
};
info('Headers:', headers);

const issueBody = {
title,
body: `
**Description:**
${description}
Expand All @@ -40,24 +75,37 @@ ${actualBehavior}
**System Information:**
${systemInfo}
`,
labels: ['bug'],
repository_project: {
project_id: projectNumber
labels: ['bug'],
repository_project: {
id: projectNumber
}
};
info('Issue body:', issueBody);

try {
logRequest('POST', apiEndpoint, headers, issueBody);
const response = await fetch(apiEndpoint, {
method: 'POST',
headers,
body: JSON.stringify(issueBody)
});
logResponse(response);

if (response.ok) {
info('Issue created successfully!');
alert('Bug report submitted successfully!');
form.reset();
} else {
warn(`Error creating issue: ${response.statusText}`);
logError(new Error(`Error creating issue: ${response.statusText}`));
alert(`Error submitting bug report: ${response.statusText}`);
}
} catch (error) {
logError(error);
alert(`Error submitting bug report: ${error.message}`);
}
};

const response = await fetch(apiEndpoint, {
method: 'POST',
headers,
body: JSON.stringify(issueBody)
});

if (response.ok) {
console.log('Issue created successfully!');
alert('Bug report submitted successfully!');
form.reset();
} else {
console.error('Error creating issue:', response.statusText);
alert('Error submitting bug report. Please try again.');
} catch (error) {
logError(error);
alert(`Error submitting bug report: ${error.message}`);
}
});

0 comments on commit 8993836

Please sign in to comment.