Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use git2::Repository;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::env;
use std::fs;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
/// Represents a hyperlink found in a repository, along with its location.
pub struct LinkInfo {
/// The URL string. This should be a valid HTTP or HTTPS URL.
Expand All @@ -15,14 +16,14 @@ pub struct LinkInfo {
pub line_number: usize,
}

pub fn extract_links_from_repo_url(repo_url: &str) -> Result<Vec<LinkInfo>, git2::Error> {
pub fn extract_links_from_repo_url(repo_url: &str) -> Result<HashSet<LinkInfo>, git2::Error> {
let temp_dir = env::temp_dir().join("queensac_temp_repo");
let _temp_dir_guard = TempDirGuard::new(temp_dir.clone()).map_err(|e| {
git2::Error::from_str(&format!("Failed to create temporary directory: {}", e))
})?;
let repo = Repository::clone(repo_url, &temp_dir)?;

let mut all_links = Vec::new(); // TODO: HashSet 사용해서 중복 제거 최적화.
let mut all_links = HashSet::new();
let url_regex = Regex::new(r"https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)").unwrap();

if let Ok(head) = repo.head() {
Expand All @@ -46,7 +47,7 @@ pub fn extract_links_from_repo_url(repo_url: &str) -> Result<Vec<LinkInfo>, git2
.trim_end_matches(&[')', '>', '.', ',', ';'][..])
.to_string();

all_links.push(LinkInfo {
all_links.insert(LinkInfo {
url,
file_path: file_path.clone(),
line_number: line_num + 1, // 1-based line number
Expand Down