Skip to content

Commit

Permalink
Update webform.html
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaLovesKPOP authored Oct 6, 2024
1 parent 1d0f152 commit fade650
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions webform.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,46 @@ <h1>Submit an Issue</h1>

fetchLastUpdatedTime();

document.getElementById('issueForm').addEventListener('submit', async function(event) {
const form = document.getElementById('issueForm');
const titleInput = document.getElementById('title');
const bodyInput = document.getElementById('body');

form.addEventListener('submit', async (event) => {
event.preventDefault();
const name = document.getElementById('name').value;
const title = document.getElementById('title').value;
const body = document.getElementById('body').value;
const time = document.getElementById('lastUpdatedTime').textContent;
const title = titleInput.value;
const body = bodyInput.value;

try {
const url = `https://api.github.com/repos/MicaLovesKPOP/CrashdayBugTracking/dispatches`;
const headers = {
'Content-Type': 'application/json'
};
const data = {
'event_type': 'create-issue',
'client_payload': {
'title': title,
'body': body
}
};

try {
const response = await fetch(`https://api.github.com/repos/MicaLovesKPOP/CrashdayBugTracking/issues`, {
method: 'POST',
headers: {
'Accept': 'application/vnd.github.v3+json',
'Content-Type': 'application/json',
'Authorization': `Bearer github_pat_11AGAVDBI08q9sEhSguOGw_wLRh3TAiyXbVpVGAEqDeBs69NDLmobDCTjtDzgNDHMk5VUFREJnQ1K7ru`
},
body: JSON.stringify({
title: title,
body: `**Submitted by:** ${name}\n\n**Last Updated Time:** ${time}\n\n${body}`
})
});
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});

if (response.ok) {
alert('Issue created successfully!');
} else {
console.error(`Failed to create issue: ${response.status} ${response.statusText}`);
console.error(`Response data: ${await response.text()}`);
console.error(`API Token: ${'github_pat_11AGAVDBI08q9sEhSguOGw_wLRh3TAiyXbVpVGAEqDeBs69NDLmobDCTjtDzgNDHMk5VUFREJnQ1K7ru'}`);
alert(`Failed to create issue: ${response.status} ${response.statusText}`);
if (response.ok) {
console.log('Issue created successfully!');
alert('Issue created successfully!');
} else {
console.error(`Failed to create issue: ${response.status} ${response.statusText}`);
console.error(`Response data: ${await response.text()}`);
alert(`Failed to create issue: ${response.status} ${response.statusText}`);
}
} catch (error) {
console.error(`Error creating issue: ${error.message}`);
alert(`Error creating issue: ${error.message}`);
}
} catch (error) {
console.error(`Error creating issue: ${error.message}`);
console.error(`API Token: ${'github_pat_11AGAVDBI08q9sEhSguOGw_wLRh3TAiyXbVpVGAEqDeBs69NDLmobDCTjtDzgNDHMk5VUFREJnQ1K7ru'}`);
alert(`Error creating issue: ${error.message}`);
}
});
</script>
</body>
Expand Down

0 comments on commit fade650

Please sign in to comment.