]> git.ipfire.org Git - pbs.git/commitdiff
sources: List commits
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 May 2023 19:17:12 +0000 (19:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 May 2023 19:17:12 +0000 (19:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/sources.py
src/templates/sources/modules/commits.html [new file with mode: 0644]
src/templates/sources/show.html
src/web/__init__.py
src/web/sources.py

index 21220fd87074a755a1646a51f4a5ff1d2952fb21..0fb7ec5500eb532abbbec02dfe09b40f02ad81a8 100644 (file)
@@ -308,6 +308,7 @@ dist_templates_sources_DATA = \
 templates_sourcesdir = $(templatesdir)/sources
 
 dist_templates_sources_modules_DATA = \
+       src/templates/sources/modules/commits.html \
        src/templates/sources/modules/list.html
 
 templates_sources_modulesdir = $(templates_sourcesdir)/modules
index d026670ef70e9e5916ef5294fc9fa011a4cd356f..011aea9e6fef73628ee16df4ad67f6d943ae83d3 100644 (file)
@@ -100,17 +100,11 @@ class Sources(base.Object):
 
        # Commits
 
-       def _get_commits(self, query, *args):
-               res = self.db.query(query, *args)
+       def _get_commits(self, query, *args, **kwargs):
+               return self.db.fetch_many(Commit, query, *args, **kwargs)
 
-               for row in res:
-                       yield Commit(self.backend, row.id, data=row)
-
-       def _get_commit(self, query, *args):
-               res = self.db.get(query, *args)
-
-               if res:
-                       return Commit(self.backend, res.id, data=res)
+       def _get_commit(self, query, *args, **kwargs):
+               return self.db.fetch_one(Commit, query, *args, **kwargs)
 
        def get_commit_by_id(self, id):
                return self._get_commit("""
@@ -210,52 +204,97 @@ class Source(base.DataObject):
 
        # Commits
 
-       async def _import_commit(self, git, revision):
+       async def _create_commit(self, revision):
                """
                        Imports the commit with the given revision
                """
                # Fetch the author's name and email address
-               author = await git.show_attribute(revision, r"%an <%ae>")
+               author = await self.git.show_attribute(revision, r"%an <%ae>")
 
                # Fetch the committer's name and email address
-               committer = await git.show_attribute(revision, r"%cn <%ce>")
+               committer = await self.git.show_attribute(revision, r"%cn <%ce>")
 
                # Subject
-               subject = await git.show_attribute(revision, r"%s")
+               subject = await self.git.show_attribute(revision, r"%s")
 
                # Body
-               body = await git.show_attribute(revision, r"%b")
+               body = await self.git.show_attribute(revision, r"%b")
 
                # Date
                date = datetime.datetime.fromisoformat(
-                       await git.show_attribute(revision, r"%aI"),
+                       await self.git.show_attribute(revision, r"%aI"),
                )
 
+               # Create a new build group
+               group = self.backend.builds.groups.create()
+
                # Insert into the database
                commit = self.backend.sources._get_commit("""
                        INSERT INTO
-                               source_commits(
-                                       source_id,
-                                       revision,
-                                       author,
-                                       committer,
-                                       subject,
-                                       body,
-                                       date
-                               )
-                       VALUES(
-                               %s, %s, %s, %s, %s, %s, %s
+                               source_commits
+                       (
+                               source_id,
+                               revision,
+                               author,
+                               committer,
+                               subject,
+                               body,
+                               date,
+                               build_group_id
+                       )
+                       VALUES
+                       (
+                               %s, %s, %s, %s, %s, %s, %s, %s
                        )
                        RETURNING
                                *
-                       """, self.id, revision, author, committer, subject, body, date,
+                       """, self.id, revision, author, committer, subject, body, date, group,
+                       source=self,
                )
 
-               # Populate the cache
-               commit.source = self
+               # Find changed files
+               changed_files = await self.git.changed_files(revision, filter="*/*.nm")
+
+               # Create jobs for each file
+               for status, changed_file in changed_files:
+                       # Find the package name
+                       name = os.path.dirname(changed_file)
+
+                       # Check that the file part matches
+                       if not changed_file.endswith("/%s.nm" % name):
+                               raise ValueError("Invalid package name")
+
+                       # If a makefile has been added or modified, we will run "dist"
+                       if status == "A" or status == "M":
+                               action = "dist"
+
+                       # If a makefile has been removed, we deprecate all former builds
+                       elif status == "D":
+                               action = "deprecate"
+
+                       # Break on any other
+                       else:
+                               raise RuntimeError("Unhandled status %s for file %s" % (status, filename))
+
+                       # Create job
+                       commit._create_job(action, name)
 
                return commit
 
+       def get_commits(self, limit=None):
+               # XXX sort?
+               commits = self.backend.sources._get_commits("""
+                       SELECT
+                               *
+                       FROM
+                               source_commits
+                       WHERE
+                               source_id = %s
+                       """, self.id,
+               )
+
+               return list(commits)
+
        @property
        def commits(self):
                # XXX using the ID is an incorrect way to sort them
diff --git a/src/templates/sources/modules/commits.html b/src/templates/sources/modules/commits.html
new file mode 100644 (file)
index 0000000..f4fe014
--- /dev/null
@@ -0,0 +1,10 @@
+{% for commit in commits %}
+       <div class="block">
+               <nav class="panel">
+                       <a class="panel-block" href="#">
+                               <h5 class="title is-5">{{ commit }}</h5>
+
+                       </a>
+               </nav>
+       </div>
+{% end %}
index 1b95d506cae39fc75741d8616e9538f4fd8849f7..47ba7669e6b111870e69aceaebde6f30e9cb92c7 100644 (file)
                        </div>
                </div>
        </section>
+
+       {% set commits = source.get_commits(limit=10) %}
+
+       <section class="section">
+               <div class="container">
+                       <h4 class="title is-4">{{ _("Commits") }}</h4>
+
+                       {% module CommitsList(commits) %}
+               </div>
+       </section>
 {% end block %}
index ce9168c9c5bf47d8702c7576da45bf782dd03fac..792e7c6db63af90a707c159f30c0a0947357178e 100644 (file)
@@ -80,6 +80,7 @@ class Application(tornado.web.Application):
 
                                # Sources
                                "SourcesList"        : sources.ListModule,
+                               "CommitsList"        : sources.CommitsListModule,
 
                                # Users
                                "UsersList"          : users.ListModule,
index 73c6eae32701565e83140a4ae8e4963e5fbcb19b..a19d741155f9f860185312c5d196388a609b07b6 100644 (file)
@@ -60,3 +60,8 @@ class ShowHandler(base.BaseHandler):
 class ListModule(ui_modules.UIModule):
        def render(self, sources):
                return self.render_string("sources/modules/list.html", sources=sources)
+
+
+class CommitsListModule(ui_modules.UIModule):
+       def render(self, commits):
+               return self.render_string("sources/modules/commits.html", commits=commits)