Skip to content

Commit 39036b9

Browse files
committed
Refactor review submission process to support GitHub integration
Updated the submitReview function to be asynchronous, allowing for a loading state during submission. Added a new function, submitReviewToGitHub, which facilitates the creation of a review file on GitHub with user instructions. Enhanced user feedback for local storage saves and GitHub submission errors.
1 parent 9e0e5bb commit 39036b9

File tree

1 file changed

+115
-5
lines changed

1 file changed

+115
-5
lines changed

docs/script.js

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ async function loadReviewsFromJSON() {
489489
}
490490

491491
// Submit review form
492-
function submitReview(event, methodName) {
492+
async function submitReview(event, methodName) {
493493
event.preventDefault();
494494

495495
const form = document.getElementById(`review-form-${methodName}`);
@@ -511,10 +511,28 @@ function submitReview(event, methodName) {
511511
reviews.push(review);
512512
saveReviewsToStorage(reviews);
513513

514-
// Show success message
515-
const successDiv = document.getElementById(`review-success-${methodName}`);
516-
if (successDiv) {
517-
successDiv.style.display = 'block';
514+
// Show loading state
515+
const submitBtn = form.querySelector('.submit-review-btn');
516+
const originalBtnText = submitBtn.textContent;
517+
submitBtn.disabled = true;
518+
submitBtn.textContent = 'Submitting...';
519+
520+
// Automatically submit to GitHub
521+
try {
522+
await submitReviewToGitHub(review);
523+
524+
// Show success message
525+
const successDiv = document.getElementById(`review-success-${methodName}`);
526+
if (successDiv) {
527+
successDiv.style.display = 'block';
528+
}
529+
} catch (error) {
530+
console.error('Error submitting to GitHub:', error);
531+
// Still show success for localStorage save, but warn about GitHub submission
532+
alert('Review saved locally. GitHub submission failed. Please use "Download Review as JSON" to submit manually.');
533+
} finally {
534+
submitBtn.disabled = false;
535+
submitBtn.textContent = originalBtnText;
518536
}
519537

520538
// Reset form
@@ -531,6 +549,98 @@ function submitReview(event, methodName) {
531549
return false;
532550
}
533551

552+
// Submit review to GitHub by creating a file via web interface
553+
async function submitReviewToGitHub(review) {
554+
// Create JSON content for the file
555+
const jsonContent = JSON.stringify(review, null, 2);
556+
const fileName = `review_${review.method}_${review.id}.json`;
557+
558+
// GitHub repository info
559+
const repoOwner = 'SingularityNET-Archive';
560+
const repoName = 'Graph-Python-scripts';
561+
562+
// Create a data URL for the JSON content (for copying)
563+
const dataBlob = new Blob([jsonContent], { type: 'application/json' });
564+
const dataUrl = URL.createObjectURL(dataBlob);
565+
566+
// Open GitHub's create file page in new tab
567+
const githubCreateFileUrl = `https://github.com/${repoOwner}/${repoName}/new/main/reviews/${encodeURIComponent(fileName)}`;
568+
569+
// Create a modal/popup with instructions and the JSON content
570+
const modal = document.createElement('div');
571+
modal.style.cssText = `
572+
position: fixed;
573+
top: 0;
574+
left: 0;
575+
width: 100%;
576+
height: 100%;
577+
background: rgba(0,0,0,0.7);
578+
z-index: 10000;
579+
display: flex;
580+
align-items: center;
581+
justify-content: center;
582+
`;
583+
584+
const modalContent = document.createElement('div');
585+
modalContent.style.cssText = `
586+
background: white;
587+
padding: 30px;
588+
border-radius: 8px;
589+
max-width: 600px;
590+
max-height: 80vh;
591+
overflow-y: auto;
592+
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
593+
`;
594+
595+
modalContent.innerHTML = `
596+
<h2 style="margin-top: 0;">Submit Review to GitHub</h2>
597+
<p>To submit your review and trigger issue creation:</p>
598+
<ol>
599+
<li>Click "Open GitHub" below to open the file creation page</li>
600+
<li>Copy the JSON content below</li>
601+
<li>Paste it into the GitHub editor</li>
602+
<li>Click "Commit new file" to submit</li>
603+
</ol>
604+
<div style="margin: 20px 0;">
605+
<button onclick="window.open('${githubCreateFileUrl}', '_blank')"
606+
style="padding: 10px 20px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer; margin-right: 10px;">
607+
Open GitHub
608+
</button>
609+
<button onclick="this.parentElement.nextElementSibling.select(); document.execCommand('copy'); alert('Copied!');"
610+
style="padding: 10px 20px; background: #0366d6; color: white; border: none; border-radius: 4px; cursor: pointer;">
611+
Copy JSON
612+
</button>
613+
<a href="${dataUrl}" download="${fileName}"
614+
style="padding: 10px 20px; background: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block;">
615+
Download JSON
616+
</a>
617+
</div>
618+
<textarea readonly
619+
style="width: 100%; height: 300px; font-family: monospace; font-size: 12px; padding: 10px; border: 1px solid #ddd; border-radius: 4px;">${escapeHtml(jsonContent)}</textarea>
620+
<div style="margin-top: 20px; text-align: right;">
621+
<button onclick="this.closest('[style*=fixed]').remove();"
622+
style="padding: 10px 20px; background: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer;">
623+
Close
624+
</button>
625+
</div>
626+
`;
627+
628+
modal.appendChild(modalContent);
629+
document.body.appendChild(modal);
630+
631+
// Close on background click
632+
modal.addEventListener('click', (e) => {
633+
if (e.target === modal) {
634+
modal.remove();
635+
}
636+
});
637+
638+
// Auto-open GitHub in new tab
639+
window.open(githubCreateFileUrl, '_blank');
640+
641+
return Promise.resolve();
642+
}
643+
534644
// Display reviews for a specific method
535645
function displayReviewsForMethod(methodName) {
536646
const reviewsList = document.getElementById(`reviews-list-${methodName}`);

0 commit comments

Comments
 (0)