summary refs log tree commit diff stats
path: root/ganarchy/db.py
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2020-11-07 13:43:58 -0300
committerSoniEx2 <endermoneymod@gmail.com>2020-11-07 13:43:58 -0300
commitdb85f92e9b77c691f25f3109e5040e03e7b1319c (patch)
treead75331d81d11533e89b77dd8153f7eef1d20a27 /ganarchy/db.py
parentdcdcc839352613d67937eda6d5a4f13097b1793e (diff)
Add non-federating repos
Diffstat (limited to 'ganarchy/db.py')
-rw-r--r--ganarchy/db.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/ganarchy/db.py b/ganarchy/db.py
index 328b682..b7aa29b 100644
--- a/ganarchy/db.py
+++ b/ganarchy/db.py
@@ -163,7 +163,8 @@ class Database:
                 "url" TEXT,
                 "active" INT,
                 "branch" TEXT,
-                "project" TEXT
+                "project" TEXT,
+                "federate" INT
             )
         ''')
         c.execute('''
@@ -183,8 +184,8 @@ class Database:
         ):
             if repo.active:
                 c.execute(
-                    '''INSERT INTO "repos" VALUES (?, ?, ?, ?)''',
-                    (repo.uri, 1, repo.branch, repo.project_commit)
+                    '''INSERT INTO "repos" VALUES (?, ?, ?, ?, ?)''',
+                    (repo.uri, 1, repo.branch, repo.project_commit, int(repo.federate))
                 )
         self.conn.commit()
         c.close()
@@ -319,6 +320,38 @@ class Database:
         c.close()
         return history
 
+    def should_repo_federate(self, project_commit, uri, branch):
+        """Returns whether a repo should federate.
+
+        Args:
+            project_commit: The project commit.
+            uri: The repo uri.
+            branch: The branch.
+
+        Returns:
+            bool, optional: Whether the repo should federate, or None if it
+            doesn't exist.
+        """
+        c = self.conn.cursor()
+        federate = c.execute(
+            '''
+                SELECT "federate"
+                FROM "repos"
+                WHERE
+                    "url" = ?
+                    AND "branch" IS ?
+                    AND "project" IS ?
+            ''',
+            (uri, branch, project_commit)
+        ).fetchall()
+        try:
+            ((federate,),) = federate
+            federate = bool(federate)
+        except ValueError:
+            federate = None
+        c.close()
+        return federate
+
     def close(self):
         """Closes the database.
         """