Skip to content

Commit

Permalink
Retrieve changes by branch
Browse files Browse the repository at this point in the history
Add the possibility to retrieve the last changes for each branch.
Only retrieve the changes that have an associated buildset.
  • Loading branch information
vladbogo committed Sep 6, 2023
1 parent d3814a6 commit ebd6da6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
14 changes: 12 additions & 2 deletions master/buildbot/data/buildsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@ class BuildsetsEndpoint(Db2DataMixin, base.Endpoint):
def get(self, resultSpec, kwargs):
complete = resultSpec.popBooleanFilter('complete')
resultSpec.fieldMapping = self.fieldMapping
d = self.master.db.buildsets.getBuildsets(
complete=complete, resultSpec=resultSpec)

branch = resultSpec.popStringFilter('branch')
if branch is not None:
count=None
if resultSpec.limit:
count = resultSpec.limit
d = self.master.db.buildsets.getRecentBuildsets(complete=complete,
branch=branch, count=count)
else:
d = self.master.db.buildsets.getBuildsets(
complete=complete, resultSpec=resultSpec)

@d.addCallback
def db2data(buildsets):
Expand All @@ -121,6 +130,7 @@ class Buildset(base.ResourceType):

class EntityType(types.Entity):
bsid = types.Integer()
branch = types.NoneOk(types.String())
external_idstring = types.NoneOk(types.String())
reason = types.String()
submitted_at = types.Integer()
Expand Down
9 changes: 7 additions & 2 deletions master/buildbot/data/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _fixChange(self, change, is_graphql):
{'name': k, 'source': v[1], 'value': json.dumps(v[0])}
for k, v in props.items()
]
change['builds'] = yield self.master.db.builds.getBuildsForChange(change['changeid'])
else:
sskey = ('sourcestamps', str(change['sourcestampid']))
change['sourcestamp'] = yield self.master.data.get(sskey)
Expand Down Expand Up @@ -104,8 +105,12 @@ def get(self, resultSpec, kwargs):
changes = []
else:
if resultSpec is not None:
resultSpec.fieldMapping = self.fieldMapping
changes = yield self.master.db.changes.getChanges(resultSpec=resultSpec)
branch = resultSpec.popStringFilter('branch')
if branch is not None:
changes = yield self.master.db.changes.getChangesForBranch(branch, resultSpec.order, resultSpec.limit)
else:
resultSpec.fieldMapping = self.fieldMapping
changes = yield self.master.db.changes.getChanges(resultSpec=resultSpec)
results = []
for ch in changes:
results.append((yield self._fixChange(ch, is_graphql='graphql' in kwargs)))
Expand Down
28 changes: 28 additions & 0 deletions master/buildbot/db/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,34 @@ def thd(conn):
def _getDataFromRow(self, row):
return row.changeid

def getChangesForBranch(self, branch, order, count):
def thd(conn):
changes_tbl = self.db.model.changes
bsss_tbl = self.db.model.buildset_sourcestamps

from_clause = changes_tbl.join(bsss_tbl,
changes_tbl.c.sourcestampid == bsss_tbl.c.sourcestampid)
if branch == 'all':
q = sa.select([changes_tbl.c.changeid.distinct()]).select_from(
from_clause)
else:
q = sa.select([changes_tbl.c.changeid.distinct()]).select_from(
from_clause).where(changes_tbl.c.branch == branch)
q = q.limit(count).order_by(changes_tbl.c.changeid.desc())
rp = conn.execute(q)
changeids = [self._getDataFromRow(row) for row in rp]
rp.close()
return list(changeids)

d = self.db.pool.do(thd)
# then turn those into changes, using the cache
@d.addCallback
def get_changes(changeids):
return defer.gatherResults([self.getChange(changeid)
for changeid in changeids])

return d

def getChanges(self, resultSpec=None):
def thd(conn):
# get the changeids from the 'changes' table
Expand Down

0 comments on commit ebd6da6

Please sign in to comment.