# 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("""
# 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