Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clomonitor-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ tracing = { workspace = true }
which = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
wiremock = { workspace = true }
26 changes: 25 additions & 1 deletion clomonitor-core/src/linter/checks/datasource/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub(crate) fn build_url(path: &Path, owner: &str, repo: &str, branch: &str) -> S
owner,
repo,
branch,
path.to_string_lossy(),
path_to_url(path),
)
}

Expand Down Expand Up @@ -257,6 +257,17 @@ fn get_owner_and_repo(repo_url: &str) -> Result<(String, String)> {
Ok((c["org"].to_string(), c["repo"].to_string()))
}

/// Serialize a repository path using URL separators.
fn path_to_url(path: &Path) -> String {
path.components()
.filter_map(|component| match component {
std::path::Component::Normal(part) => Some(part.to_string_lossy()),
_ => None,
})
.collect::<Vec<_>>()
.join("/")
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -275,6 +286,19 @@ mod tests {
);
}

#[test]
fn build_url_works_with_nested_paths() {
assert_eq!(
build_url(
Path::new(".github").join("security-insights.yml").as_path(),
"owner",
"repo",
"main"
),
"https://github.com/owner/repo/blob/main/.github/security-insights.yml".to_string()
);
}

#[test]
fn default_branch_some() {
let r = MdRepositoryDefaultBranchRef {
Expand Down
Loading
Loading