Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ function copyText(className) {
});
}

function validateGithubUrl(url) {
// Add https:// if missing
if (!url.startsWith('https://')) {
url = 'https://' + url;
}

// Check if it's a valid GitHub URL
const githubPattern = /^https:\/\/github\.com\/[^\/]+\/[^\/]+/;
return githubPattern.test(url);
}

function handleSubmit(event, showLoading = false) {
event.preventDefault();
// Get the form either from event.target or by ID if event.target is null
Expand All @@ -37,6 +48,23 @@ function handleSubmit(event, showLoading = false) {
const submitButton = form.querySelector('button[type="submit"]');
if (!submitButton) return; // Guard clause in case button isn't found

// Get the input URL
const formData = new FormData(form);
const inputUrl = formData.get('input_text');

// Validate URL
if (!validateGithubUrl(inputUrl)) {
const errorMessage = document.getElementById('error-message') || (() => {
const div = document.createElement('div');
div.id = 'error-message';
div.className = 'text-red-500 text-sm mt-2';
form.appendChild(div);
return div;
})();
errorMessage.textContent = 'Please enter a valid GitHub repository URL (e.g., github.com/user/repo)';
return;
}

const originalContent = submitButton.innerHTML;
const currentStars = document.getElementById('github-stars')?.textContent;

Expand Down Expand Up @@ -112,4 +140,4 @@ function copyFullDigest() {

// Export functions if using modules
window.copyText = copyText;
window.handleSubmit = handleSubmit;
window.handleSubmit = handleSubmit;
8 changes: 4 additions & 4 deletions src/utils/parse_url.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

import uuid

from config import TMP_BASE_PATH

def parse_url(url: str) -> dict:
parsed = {

"user_name": None,
"repo_name": None,
"type": None,
Expand All @@ -17,11 +15,13 @@ def parse_url(url: str) -> dict:
}


# Normalize URL by adding https:// if missing
if not url.startswith("https://"):
url = "https://" + url

if not url.startswith("https://github.com/"):
raise ValueError("Invalid GitHub URL. Please provide a valid GitHub repository URL.")



# Remove anything after the first space
url = url.split(" ")[0]

Expand Down