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);
|
||||
|
||||
Reference in new issue
Block a user