From: Michael Tremer Date: Mon, 22 May 2023 19:17:12 +0000 (+0000) Subject: sources: List commits X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9826b58c0d809e3e19c39d4fcdbe3bf8a8dd27ff;p=pbs.git sources: List commits Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 21220fd8..0fb7ec55 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/buildservice/sources.py b/src/buildservice/sources.py index d026670e..011aea9e 100644 --- a/src/buildservice/sources.py +++ b/src/buildservice/sources.py @@ -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 index 00000000..f4fe0143 --- /dev/null +++ b/src/templates/sources/modules/commits.html @@ -0,0 +1,10 @@ +{% for commit in commits %} + +{% end %} diff --git a/src/templates/sources/show.html b/src/templates/sources/show.html index 1b95d506..47ba7669 100644 --- a/src/templates/sources/show.html +++ b/src/templates/sources/show.html @@ -48,4 +48,14 @@ + + {% set commits = source.get_commits(limit=10) %} + +
+
+

{{ _("Commits") }}

+ + {% module CommitsList(commits) %} +
+
{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index ce9168c9..792e7c6d 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -80,6 +80,7 @@ class Application(tornado.web.Application): # Sources "SourcesList" : sources.ListModule, + "CommitsList" : sources.CommitsListModule, # Users "UsersList" : users.ListModule, diff --git a/src/web/sources.py b/src/web/sources.py index 73c6eae3..a19d7411 100644 --- a/src/web/sources.py +++ b/src/web/sources.py @@ -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)