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 18, 2023
1 parent d3814a6 commit 106b38e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
13 changes: 11 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 Down
13 changes: 11 additions & 2 deletions master/buildbot/data/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ 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 +107,14 @@ 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
22 changes: 22 additions & 0 deletions master/buildbot/db/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,28 @@ def thd(conn):
def _getDataFromRow(self, row):
return row.changeid

@defer.inlineCallbacks
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 changeids
res = yield self.db.pool.do(thd)
return res

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

0 comments on commit 106b38e

Please sign in to comment.