Compare commits
2 commits
ccdba182c9
...
c289a8c2c7
Author | SHA1 | Date | |
---|---|---|---|
Aode (lion) | c289a8c2c7 | ||
Aode (lion) | 77c0c92fbb |
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -906,7 +906,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
|||
|
||||
[[package]]
|
||||
name = "release-checker"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"regex",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "release-checker"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
58
src/gitea.rs
58
src/gitea.rs
|
@ -12,12 +12,6 @@ struct GiteaTag {
|
|||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
struct GiteaTagResponse {
|
||||
name: String,
|
||||
commit: Commit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
struct Commit {
|
||||
sha: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -58,53 +52,45 @@ pub(crate) async fn get_previous_revision(
|
|||
client: &Client,
|
||||
config: &GiteaConfig,
|
||||
) -> color_eyre::eyre::Result<Revision> {
|
||||
let mut commit_sha: Option<String> = None;
|
||||
let mut last_revision: Option<Revision> = None;
|
||||
const LIMIT: usize = 10;
|
||||
|
||||
// Tags for the same commit sha are in order from oldest to newest, while commit shas are in order from newest to oldest
|
||||
// Loop through pages finding the last tag for the first commit sha
|
||||
// Iterate through all pages
|
||||
for page_num in 1.. {
|
||||
let tags_url = format!(
|
||||
"https://{}/api/v1/repos/{}/{}/tags?page={}&limit=4",
|
||||
config.domain, config.owner, config.repo, page_num,
|
||||
"https://{}/api/v1/repos/{}/{}/tags?page={}&limit={}",
|
||||
config.domain, config.owner, config.repo, page_num, LIMIT
|
||||
);
|
||||
let tags_response = client.get(tags_url).send().await?;
|
||||
|
||||
let tags: Vec<GiteaTagResponse> = tags_response.json().await?;
|
||||
|
||||
if let Some(tag) = tags.get(0) {
|
||||
let local_commit_sha = commit_sha.clone().unwrap_or_else(|| tag.commit.sha.clone());
|
||||
let should_break = tags.len() < LIMIT;
|
||||
|
||||
let opt = tags
|
||||
.into_iter()
|
||||
.take_while(|tag| tag.commit.sha == local_commit_sha)
|
||||
.map(|tag| tag.name.parse().ok())
|
||||
.fold(None as Option<Revision>, |max, current| {
|
||||
if let Some(current) = current {
|
||||
if let Some(max) = max {
|
||||
if current > max {
|
||||
Some(current)
|
||||
} else {
|
||||
Some(max)
|
||||
}
|
||||
} else if matches!(current.version, Version::Semver { .. }) {
|
||||
last_revision = tags.into_iter().map(|tag| tag.name.parse().ok()).fold(
|
||||
last_revision,
|
||||
|max, current| {
|
||||
if let Some(current) = current {
|
||||
if let Some(max) = max {
|
||||
if current > max {
|
||||
Some(current)
|
||||
} else {
|
||||
None
|
||||
Some(max)
|
||||
}
|
||||
} else if matches!(current.version, Version::Semver { .. }) {
|
||||
Some(current)
|
||||
} else {
|
||||
max
|
||||
None
|
||||
}
|
||||
});
|
||||
} else {
|
||||
max
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(revision) = opt {
|
||||
last_revision = Some(revision);
|
||||
commit_sha = Some(local_commit_sha);
|
||||
continue;
|
||||
}
|
||||
if should_break {
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Ok(last_revision.unwrap_or_default())
|
||||
|
|
Loading…
Reference in a new issue