Compare commits
2 commits
eb3b140a17
...
1908c5ce73
Author | SHA1 | Date | |
---|---|---|---|
Aode (lion) | 1908c5ce73 | ||
Aode (lion) | 2530c439a3 |
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -906,7 +906,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
|||
|
||||
[[package]]
|
||||
name = "release-checker"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"regex",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "release-checker"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -6,6 +6,16 @@ enum DockerError {
|
|||
NoTag,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct TagResult {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct TagsResponse {
|
||||
results: Vec<TagResult>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for DockerError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
@ -29,16 +39,6 @@ pub(crate) async fn check_dockerhub_image(
|
|||
.user_agent("release-checker (+https://git.asonix.dog/asonix/release-checker)")
|
||||
.build()?;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct TagResult {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct TagsResponse {
|
||||
results: Vec<TagResult>,
|
||||
}
|
||||
|
||||
let images_url = format!("https://registry.hub.docker.com/v2/repositories/{}/{}/tags?currently_tagged=true,ordering=last_updated,page_size=30,status=active", namespace, repository);
|
||||
let tags: TagsResponse = client.get(images_url).send().await?.json().await?;
|
||||
|
||||
|
|
57
src/gitea.rs
57
src/gitea.rs
|
@ -12,6 +12,12 @@ struct GiteaTag {
|
|||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
struct GiteaTagResponse {
|
||||
name: String,
|
||||
commit: Commit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
struct Commit {
|
||||
sha: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -52,22 +58,47 @@ pub(crate) async fn get_previous_revision(
|
|||
client: &Client,
|
||||
config: &GiteaConfig,
|
||||
) -> color_eyre::eyre::Result<Revision> {
|
||||
let tags_url = format!(
|
||||
"https://{}/api/v1/repos/{}/{}/tags?page=1&limit=4",
|
||||
config.domain, config.owner, config.repo
|
||||
);
|
||||
let tags_response = client.get(tags_url).send().await?;
|
||||
let mut commit_sha: Option<String> = None;
|
||||
let mut last_revision: Option<Revision> = None;
|
||||
|
||||
let tags: Vec<GiteaTagResponse> = tags_response.json().await?;
|
||||
// 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
|
||||
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,
|
||||
);
|
||||
let tags_response = client.get(tags_url).send().await?;
|
||||
|
||||
let revision = if let Some(tag) = tags.get(0) {
|
||||
tracing::info!("tag: {}", tag.name);
|
||||
tag.name.parse()?
|
||||
} else {
|
||||
Revision::default()
|
||||
};
|
||||
let tags: Vec<GiteaTagResponse> = tags_response.json().await?;
|
||||
|
||||
Ok(revision)
|
||||
if let Some(tag) = tags.get(0) {
|
||||
let local_commit_sha = commit_sha.clone().unwrap_or_else(|| tag.commit.sha.clone());
|
||||
|
||||
let full_len = tags.len();
|
||||
|
||||
let mut revisions: Vec<Revision> = tags
|
||||
.into_iter()
|
||||
.take_while(|tag| tag.commit.sha == local_commit_sha)
|
||||
.filter_map(|tag| tag.name.parse().ok())
|
||||
.collect();
|
||||
|
||||
let revisions_len = revisions.len();
|
||||
|
||||
if let Some(revision) = revisions.pop() {
|
||||
last_revision = Some(revision);
|
||||
|
||||
if revisions_len == full_len {
|
||||
commit_sha = Some(local_commit_sha);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Ok(last_revision.unwrap_or_default())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(client))]
|
||||
|
|
|
@ -51,6 +51,7 @@ async fn run() -> color_eyre::eyre::Result<()> {
|
|||
let client = build_client(&std::env::var("GITEA_TOKEN")?)?;
|
||||
|
||||
let previous_revision = get_previous_revision(&client, &config.gitea).await?;
|
||||
tracing::info!("Previous revision: {}", previous_revision);
|
||||
|
||||
let version_opt = match check_project(config.project, &previous_revision).await? {
|
||||
BuildDirective::ShouldIgnore => {
|
||||
|
@ -60,7 +61,6 @@ async fn run() -> color_eyre::eyre::Result<()> {
|
|||
BuildDirective::ShouldBuild(version_opt) => version_opt,
|
||||
};
|
||||
|
||||
tracing::info!("Previous revision: {}", previous_revision);
|
||||
let revision = previous_revision.next(version_opt);
|
||||
tracing::info!("New revision: {}", revision);
|
||||
|
||||
|
|
Loading…
Reference in a new issue