aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2021-05-30 18:10:00 +0200
committerTeddy Wing2021-05-30 18:10:00 +0200
commit850b2aadd402ab80c0d2c371fe7be3066271a1ab (patch)
treec3d5965a1887351d95401a792c2c333d33d35ec0
parentb7c396b9db42f60d091755eed547c295edd970ac (diff)
downloadreflectub-850b2aadd402ab80c0d2c371fe7be3066271a1ab.tar.bz2
Only update repository description if the description changed
Check the repository description that comes back from the GitHub API against our cached description in the database. Only write the new description if it changed so we can avoid writing to the file in that case.
-rw-r--r--src/database.rs8
-rw-r--r--src/main.rs14
2 files changed, 17 insertions, 5 deletions
diff --git a/src/database.rs b/src/database.rs
index 1dac44f..ac5ef3b 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -12,6 +12,14 @@ pub struct Repo {
updated_at: Option<String>,
}
+impl Repo {
+ pub fn description(&self) -> &str {
+ self.description
+ .as_deref()
+ .unwrap_or("")
+ }
+}
+
impl From<&github::Repo> for Repo {
fn from(repo: &github::Repo) -> Self {
Self {
diff --git a/src/main.rs b/src/main.rs
index 2a3e988..697ca7e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -62,9 +62,9 @@ async fn main() {
let db_repo = database::Repo::from(&repo);
match db.repo_get(id).await {
- Ok(_) => {
+ Ok(current_repo) => {
if db.repo_is_updated(&db_repo).await.unwrap() {
- update(&path, &repo).unwrap();
+ update(&path, &current_repo, &repo).unwrap();
db.repo_update(&db_repo).await.unwrap();
}
@@ -116,12 +116,16 @@ fn mirror<P: AsRef<Path>>(
fn update<P: AsRef<Path>>(
repo_path: P,
- repo: &github::Repo,
+ current_repo: &database::Repo,
+ updated_repo: &github::Repo,
) -> anyhow::Result<()> {
git::update(&repo_path)?;
- // TODO: Don't write if description is the same
- git::update_description(&repo_path, repo.description())?;
+ let remote_description = updated_repo.description();
+
+ if current_repo.description() != remote_description {
+ git::update_description(&repo_path, remote_description)?;
+ }
Ok(())
}