From b324a7a96acbaf589fedca245e9e5659ee9cd8fa Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 4 Jun 2022 18:14:08 +0200 Subject: database::Repo: From<&github::Repo>: Use newest update date It turns out the GitHub `updated_at` field doesn't change when new commits are pushed to the repository, only when the repository config etc. changes. In order to update the mirrors when any update happens in the repository, we need to look at both of those date values to see if they've been updated. Take the most recent of `updated_at` or `pushed_at` and set it to `(database::Repo).updated_at`. This allows us to refresh the repo when either of those dates change, catching all GitHub repo updates. --- src/database.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/database.rs b/src/database.rs index ed5d327..7e7a065 100644 --- a/src/database.rs +++ b/src/database.rs @@ -44,12 +44,32 @@ impl Repo { impl From<&github::Repo> for Repo { fn from(repo: &github::Repo) -> Self { + use chrono::DateTime; + + let repo_updated_at = DateTime::parse_from_rfc3339(&repo.updated_at).ok(); + let repo_pushed_at = DateTime::parse_from_rfc3339(&repo.pushed_at).ok(); + + // Set `updated_at` to the most recent of `repo_updated_at` or + // `repo_pushed_at`. + let updated_at = + if repo_updated_at.is_none() && repo_pushed_at.is_none() { + repo.updated_at.clone() + + // `repo_updated_at` and `repo_pushed_at` are both Some. + } else if repo_pushed_at.unwrap() > repo_updated_at.unwrap() { + repo.pushed_at.clone() + + // Default to `repo.updated_at`. + } else { + repo.updated_at.clone() + }; + Self { id: repo.id, name: Some(repo.name.clone()), description: repo.description.clone(), default_branch: Some(repo.default_branch.clone()), - updated_at: Some(repo.updated_at.clone()), + updated_at: Some(updated_at), } } } -- cgit v1.2.3