aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-05 20:06:28 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-05 20:06:28 +0100
commit5028dfe706856d11246a7338dfd47d4035d8fb25 (patch)
tree9e13cf7e390e345a42f0c3bfd4d30537e12bc52f /guix-data-service/model
parentce4c3c6ed3979e54a8d5db6514bf4ed87de8b707 (diff)
downloaddata-service-5028dfe706856d11246a7338dfd47d4035d8fb25.tar
data-service-5028dfe706856d11246a7338dfd47d4035d8fb25.tar.gz
Start to handle information about Git branches
Add some new pages /branches and /branch/... as well as a new git_branches table. Also extend the email processing to enter the branch information in to the database.
Diffstat (limited to 'guix-data-service/model')
-rw-r--r--guix-data-service/model/git-branch.scm57
1 files changed, 57 insertions, 0 deletions
diff --git a/guix-data-service/model/git-branch.scm b/guix-data-service/model/git-branch.scm
new file mode 100644
index 0000000..896e551
--- /dev/null
+++ b/guix-data-service/model/git-branch.scm
@@ -0,0 +1,57 @@
+(define-module (guix-data-service model git-branch)
+ #:use-module (squee)
+ #:export (insert-git-branch-entry
+ git-branches-for-commit
+ most-recent-100-commits-for-branch
+ all-branches-with-most-recent-commit))
+
+(define (insert-git-branch-entry conn
+ name commit
+ git-repository-id datetime)
+ (exec-query
+ conn
+ (string-append
+ "INSERT INTO git_branches (name, commit, git_repository_id, datetime) "
+ "VALUES ($1, $2, $3, $4) "
+ "ON CONFLICT DO NOTHING")
+ (list name
+ commit
+ git-repository-id
+ datetime)))
+
+(define (git-branches-for-commit conn commit)
+ (define query
+ "
+SELECT name, datetime FROM git_branches WHERE commit = $1
+ORDER BY datetime DESC")
+
+ (exec-query conn query (list commit)))
+
+(define (most-recent-100-commits-for-branch conn branch-name)
+ (define query
+ (string-append
+ "SELECT git_branches.commit, datetime, "
+ "(guix_revisions.id IS NOT NULL) as guix_revision_exists "
+ "FROM git_branches "
+ "LEFT OUTER JOIN guix_revisions ON git_branches.commit = guix_revisions.commit "
+ "WHERE name = $1 ORDER BY datetime DESC LIMIT 100;"))
+
+ (exec-query
+ conn
+ query
+ (list branch-name)))
+
+(define (all-branches-with-most-recent-commit conn)
+ (define query
+ (string-append
+ "SELECT DISTINCT ON (name) name, git_branches.commit, "
+ "datetime, (guix_revisions.id IS NOT NULL) guix_revision_exists "
+ "FROM git_branches "
+ "LEFT OUTER JOIN guix_revisions ON git_branches.commit = guix_revisions.commit "
+ "WHERE git_branches.commit IS NOT NULL "
+ "ORDER BY name, datetime DESC;"))
+
+ (exec-query
+ conn
+ query))
+