mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
fix: import/bootstrap hardening, canonical registry URLs, GUI canonical add path
- plain clones count as present; import refuses non-empty targets - registry stores canonical https URLs; bootstrap matches provider by host - clone URLs and repo names validated; GitHub link-style pagination - bridge passes the canonical path to grove add; fix flaky instance test Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fdc5a8f5a6
commit
3cba9784a3
8 files changed
+273
-59
No files matched your search
@@ -70,7 +70,7 @@ impl Provider for Gitea {
|
||||
fn list_repos(&self) -> Result<Vec<RemoteRepo>> {
|
||||
Ok(self
|
||||
.http
|
||||
.pages("/user/repos", 50, "limit")?
|
||||
.pages("/user/repos", 50, "limit", false)?
|
||||
.iter()
|
||||
.map(repo)
|
||||
.collect())
|
||||
@@ -82,7 +82,7 @@ impl Provider for Gitea {
|
||||
} else {
|
||||
format!("/orgs/{owner}/repos")
|
||||
};
|
||||
let items = match self.http.pages(&path, 50, "limit") {
|
||||
let items = match self.http.pages(&path, 50, "limit", false) {
|
||||
Ok(v) => v,
|
||||
// Not an organisation (a user, or an org the token cannot see): say so, and take
|
||||
// what the token can see under that name, private repos it collaborates on included.
|
||||
@@ -90,7 +90,7 @@ impl Provider for Gitea {
|
||||
eprintln!(
|
||||
"grove: /orgs/{owner} not found; listing the repositories you can see owned by {owner}"
|
||||
);
|
||||
self.http.pages("/user/repos", 50, "limit")?
|
||||
self.http.pages("/user/repos", 50, "limit", false)?
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Provider for GitHub {
|
||||
fn list_repos(&self) -> Result<Vec<RemoteRepo>> {
|
||||
Ok(self
|
||||
.http
|
||||
.pages("/user/repos", 100, "per_page")?
|
||||
.pages("/user/repos", 100, "per_page", true)?
|
||||
.iter()
|
||||
.map(repo)
|
||||
.collect())
|
||||
@@ -89,7 +89,7 @@ impl Provider for GitHub {
|
||||
} else {
|
||||
format!("/orgs/{owner}/repos?type=all")
|
||||
};
|
||||
let items = match self.http.pages(&path, 100, "per_page") {
|
||||
let items = match self.http.pages(&path, 100, "per_page", true) {
|
||||
Ok(v) => v,
|
||||
// Not an organisation (a user, or an org the token cannot see): say so, and take
|
||||
// what the token can see under that name, private repos it collaborates on included.
|
||||
@@ -101,6 +101,7 @@ impl Provider for GitHub {
|
||||
"/user/repos?affiliation=owner,collaborator,organization_member",
|
||||
100,
|
||||
"per_page",
|
||||
true,
|
||||
)?
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
|
||||
@@ -85,9 +85,15 @@ impl Http {
|
||||
/// Every item of a paginated list endpoint (`path` may already carry a query string).
|
||||
///
|
||||
/// A short page is not the end (a server may cap the page size below what was asked). It
|
||||
/// ends on `X-Total-Count` being reached, on a `Link` header without `rel="next"`, or on an
|
||||
/// empty or repeated page.
|
||||
pub fn pages(&self, path: &str, per_page: usize, size_param: &str) -> Result<Vec<Value>> {
|
||||
/// ends on `X-Total-Count` being reached, on a `Link` header without `rel="next"` (also when
|
||||
/// absent, for `link_style` servers such as GitHub), or on an empty or repeated page.
|
||||
pub fn pages(
|
||||
&self,
|
||||
path: &str,
|
||||
per_page: usize,
|
||||
size_param: &str,
|
||||
link_style: bool,
|
||||
) -> Result<Vec<Value>> {
|
||||
let sep = if path.contains('?') { '&' } else { '?' };
|
||||
let mut out: Vec<Value> = Vec::new();
|
||||
let mut prev: Option<Vec<Value>> = None;
|
||||
@@ -103,12 +109,12 @@ impl Http {
|
||||
break;
|
||||
}
|
||||
out.extend(items.iter().cloned());
|
||||
if hints.total.is_some_and(|t| out.len() >= t)
|
||||
|| hints
|
||||
.link
|
||||
.as_deref()
|
||||
.is_some_and(|l| !l.contains("rel=\"next\""))
|
||||
{
|
||||
// GitHub style: no `Link: rel="next"` means this was the last page.
|
||||
let no_next = hints
|
||||
.link
|
||||
.as_deref()
|
||||
.map_or(link_style, |l| !l.contains("rel=\"next\""));
|
||||
if hints.total.is_some_and(|t| out.len() >= t) || no_next {
|
||||
break;
|
||||
}
|
||||
prev = Some(items);
|
||||
|
||||
@@ -410,29 +410,24 @@ fn github_owner_listing_scopes_the_query_and_sees_collaborator_repos_of_users()
|
||||
let collab = format!("[{REPO_C},{REPO_B}]");
|
||||
let (url, rx) = mock(vec![
|
||||
(200, Box::leak(org.into_boxed_str())),
|
||||
(200, "[]"),
|
||||
(200, Box::leak(mine.into_boxed_str())),
|
||||
(200, "[]"),
|
||||
(404, r#"{"message":"Not Found"}"#),
|
||||
(200, Box::leak(collab.into_boxed_str())),
|
||||
(200, "[]"),
|
||||
]);
|
||||
let g = GitHub::new(&url, "t".into());
|
||||
assert_eq!(g.list_owner_repos("Org", "me").unwrap().len(), 1);
|
||||
assert!(
|
||||
lines(&rx.recv().unwrap()).starts_with("GET /orgs/Org/repos?type=all&per_page=100&page=1 ")
|
||||
);
|
||||
rx.recv().unwrap();
|
||||
assert_eq!(g.list_owner_repos("me", "me").unwrap().len(), 1);
|
||||
assert!(
|
||||
lines(&rx.recv().unwrap())
|
||||
.starts_with("GET /user/repos?affiliation=owner&per_page=100&page=1 ")
|
||||
);
|
||||
rx.recv().unwrap();
|
||||
// Not an organisation (404): what the token sees under that name, private ones included.
|
||||
let r = g.list_owner_repos("x", "me").unwrap();
|
||||
assert_eq!(r.iter().map(|r| r.name.as_str()).collect::<Vec<_>>(), ["c"]);
|
||||
rx.recv().unwrap();
|
||||
rx.recv().unwrap(); // the 404 on /orgs/x
|
||||
assert!(lines(&rx.recv().unwrap()).starts_with(
|
||||
"GET /user/repos?affiliation=owner,collaborator,organization_member&per_page=100&page=1 "
|
||||
));
|
||||
@@ -448,7 +443,7 @@ fn a_short_page_is_not_the_end_of_a_listing() {
|
||||
(200, Box::leak(p2.into_boxed_str())),
|
||||
(200, "[]"),
|
||||
]);
|
||||
let g = GitHub::new(&url, "t".into());
|
||||
let g = Gitea::new(ProviderKind::Gitea, &url, "t".into());
|
||||
assert_eq!(g.list_repos().unwrap().len(), 3);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user