From 85df39e199fa146e22d9cf8ccd635277fe066d12 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 24 Jun 2021 21:18:07 +0200 Subject: main::update(): Change HEAD branch if default branch changed If the default branch on GitHub changed, change the local mirror's HEAD to match the new default. Need to store the default branch in the database now so we can find out whether it changed. --- src/database.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/database.rs') diff --git a/src/database.rs b/src/database.rs index 107a6d6..ed5d327 100644 --- a/src/database.rs +++ b/src/database.rs @@ -30,6 +30,7 @@ pub struct Repo { id: i64, name: Option, description: Option, + pub default_branch: Option, updated_at: Option, } @@ -47,6 +48,7 @@ impl From<&github::Repo> for Repo { 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()), } } @@ -95,6 +97,7 @@ impl Db { id INTEGER PRIMARY KEY, name TEXT NOT NULL, description TEXT, + default_branch TEXT, updated_at TEXT NOT NULL ); "#, @@ -128,6 +131,7 @@ impl Db { id, name, description, + default_branch, updated_at FROM repositories WHERE id = ? @@ -139,7 +143,8 @@ impl Db { id: row.get(0)?, name: Some(row.get(1)?), description: row.get(2)?, - updated_at: Some(row.get(3)?), + default_branch: row.get(3)?, + updated_at: Some(row.get(4)?), } ) }, @@ -158,14 +163,15 @@ impl Db { tx.execute( r#" INSERT INTO repositories - (id, name, description, updated_at) + (id, name, description, default_branch, updated_at) VALUES - (?, ?, ?, ?) + (?, ?, ?, ?, ?) "#, rusqlite::params![ repo.id, &repo.name, &repo.description, + &repo.default_branch, &repo.updated_at, ], )?; @@ -222,12 +228,14 @@ impl Db { SET name = ?, description = ?, + default_branch = ?, updated_at = ? WHERE id = ? "#, rusqlite::params![ &repo.name, &repo.description, + &repo.default_branch, &repo.updated_at, repo.id, ], -- cgit v1.2.3