Skip to content

Commit

Permalink
add project and repository to Change objects and SourceStamps, displa…
Browse files Browse the repository at this point in the history
…y them
  • Loading branch information
Dustin J. Mitchell committed Mar 10, 2010
1 parent 214c120 commit 1679a52
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 23 deletions.
8 changes: 6 additions & 2 deletions buildbot/broken_test/unit/test_sourcestamp.py
Expand Up @@ -52,7 +52,9 @@ def testAsDictChanges(self):
'revision': 'rev2',
'revlink': '',
'when': 23,
'who': 'nobody'
'who': 'nobody',
'project' : '',
'repository' : '',
},
{
'branch': 'br3',
Expand All @@ -64,7 +66,9 @@ def testAsDictChanges(self):
'revision': 'rev3',
'revlink': '',
'when': 42,
'who': 'nob'
'who': 'nob',
'project' : '',
'repository' : '',
}
],
})
Expand Down
15 changes: 13 additions & 2 deletions buildbot/changes/changes.py
Expand Up @@ -44,7 +44,7 @@ class Change:

def __init__(self, who, files, comments, isdir=0, links=None,
revision=None, when=None, branch=None, category=None,
revlink='', properties={}):
revlink='', properties={}, repository='', project=''):
self.who = who
self.comments = comments
self.isdir = isdir
Expand All @@ -61,6 +61,8 @@ def __init__(self, who, files, comments, isdir=0, links=None,
self.revlink = revlink
self.properties = Properties()
self.properties.update(properties, "Change")
self.repository = repository
self.project = project

# keep a sorted list of the files, for easier display
self.files = files[:]
Expand All @@ -77,6 +79,10 @@ def __setstate__(self, dict):
def asText(self):
data = ""
data += self.getFileContents()
if self.repository:
data += "On: %s\n" % self.repository
if self.project:
data += "For: %s\n" % self.project
data += "At: %s\n" % self.getTime()
data += "Changed By: %s\n" % self.who
data += "Comments: %s" % self.comments
Expand Down Expand Up @@ -104,7 +110,10 @@ def html_dict(self):
'branch' : self.branch,
'comments' : self.comments,
'properties': self.properties.asList(),
'number' : self.number }
'number' : self.number,
'repository' : self.repository,
'project' : self.project,
}

return kwargs

Expand All @@ -121,6 +130,8 @@ def asDict(self):
result['files'] = self.files
result['revlink'] = self.revlink
result['properties'] = self.properties.asList()
result['repository'] = self.repository
result['project'] = self.project
return result

def getShortAuthor(self):
Expand Down
34 changes: 19 additions & 15 deletions buildbot/db/connector.py
Expand Up @@ -301,14 +301,16 @@ def _txn_addChangeToDatabase(self, t, change):
" (changeid, author,"
" comments, is_dir,"
" branch, revision, revlink,"
" when_timestamp, category)"
" VALUES (?,?, ?,?, ?,?,?, ?,?)")
" when_timestamp, category,"
" repository, project)"
" VALUES (?,?, ?,?, ?,?,?, ?,?, ?,?)")
# TODO: map None to.. empty string?

values = (change.number, change.who,
change.comments, change.isdir,
change.branch, change.revision, change.revlink,
change.when, change.category)
change.when, change.category, change.repository,
change.project)
t.execute(q, values)

for link in change.links:
Expand Down Expand Up @@ -369,15 +371,16 @@ def getChangeNumberedNow(self, changeid, t=None):
def _txn_getChangeNumberedNow(self, t, changeid):
q = self.quoteq("SELECT author, comments,"
" is_dir, branch, revision, revlink,"
" when_timestamp, category"
" when_timestamp, category,"
" repository, project"
" FROM changes WHERE changeid = ?")
t.execute(q, (changeid,))
rows = t.fetchall()
if not rows:
return None
(who, comments,
isdir, branch, revision, revlink,
when, category) = rows[0]
when, category, repository, project) = rows[0]
branch = str_or_none(branch)
revision = str_or_none(revision)
q = self.quoteq("SELECT link FROM change_links WHERE changeid=?")
Expand All @@ -399,7 +402,7 @@ def _txn_getChangeNumberedNow(self, t, changeid):
c = Change(who=who, files=files, comments=comments, isdir=isdir,
links=links, revision=revision, when=when,
branch=branch, category=category, revlink=revlink,
properties=properties)
properties=properties, repository=repository, project=project)
c.number = changeid
return c

Expand All @@ -412,7 +415,8 @@ def getChangeByNumber(self, changeid):
return defer.succeed(c)
d1 = self.runQuery(self.quoteq("SELECT author, comments,"
" is_dir, branch, revision, revlink,"
" when_timestamp, category"
" when_timestamp, category,"
" repository, project"
" FROM changes WHERE changeid = ?"),
(changeid,))
d2 = self.runQuery(self.quoteq("SELECT link FROM change_links"
Expand All @@ -435,7 +439,7 @@ def _getChangeByNumber_query_done(self, res, changeid):
return None
(who, comments,
isdir, branch, revision, revlink,
when, category) = rows[0]
when, category, repository, project) = rows[0]
branch = str_or_none(branch)
revision = str_or_none(revision)
links = [row[0] for row in link_rows]
Expand All @@ -447,7 +451,7 @@ def _getChangeByNumber_query_done(self, res, changeid):
c = Change(who=who, files=files, comments=comments, isdir=isdir,
links=links, revision=revision, when=when,
branch=branch, category=category, revlink=revlink,
properties=properties)
properties=properties, repository=repository, project=project)
c.number = changeid
self._change_cache.add(changeid, c)
return c
Expand Down Expand Up @@ -492,13 +496,13 @@ def getSourceStampNumberedNow(self, ssid, t=None):

def _txn_getSourceStampNumbered(self, t, ssid):
assert isinstance(ssid, (int, long))
t.execute(self.quoteq("SELECT branch,revision,patchid"
t.execute(self.quoteq("SELECT branch,revision,patchid,project,repository"
" FROM sourcestamps WHERE id=?"),
(ssid,))
r = t.fetchall()
if not r:
return None
(branch_u, revision_u, patchid) = r[0]
(branch_u, revision_u, patchid, project, repository) = r[0]
branch = str_or_none(branch_u)
revision = str_or_none(revision_u)

Expand All @@ -525,7 +529,7 @@ def _txn_getSourceStampNumbered(self, t, ssid):
if r:
changes = [self.getChangeNumberedNow(changeid, t)
for (changeid,) in r]
ss = SourceStamp(branch, revision, patch, changes)
ss = SourceStamp(branch, revision, patch, changes, project=project, repository=repository)
ss.ssid = ssid
return ss

Expand Down Expand Up @@ -619,9 +623,9 @@ def get_sourcestampid(self, ss, t):
t.execute("SELECT id FROM sourcestamps ORDER BY id DESC LIMIT 1")
ss.ssid = _one_or_else(t.fetchall(), 0) + 1
t.execute(self.quoteq("INSERT INTO sourcestamps"
" (id, branch, revision, patchid)"
" VALUES (?,?,?,?)"),
(ss.ssid, ss.branch, ss.revision, patchid))
" (id, branch, revision, patchid, project, repository)"
" VALUES (?,?,?,?,?,?)"),
(ss.ssid, ss.branch, ss.revision, patchid, ss.project, ss.repository))
q2 = self.quoteq("INSERT INTO sourcestamp_changes"
" (sourcestampid, changeid) VALUES (?,?)")
for c in ss.changes:
Expand Down
6 changes: 6 additions & 0 deletions buildbot/interfaces.py
Expand Up @@ -106,6 +106,12 @@ class ISourceStamp(Interface):
in the given changes
@type changes: tuple of L{buildbot.changes.changes.Change} instances,
all of which are on the same branch
@cvar project: project this source code represents
@type project: string
@cvar repository: repository from which source was drawn
@type repository: string
"""

def canBeMergedWith(self, other):
Expand Down
13 changes: 10 additions & 3 deletions buildbot/sourcestamp.py
Expand Up @@ -24,7 +24,7 @@ class SourceStamp(util.ComparableMixin, styles.Versioned):
and all must be on the same branch.
"""

persistenceVersion = 1
persistenceVersion = 2

# all four of these are publically visible attributes
branch = None
Expand All @@ -33,12 +33,12 @@ class SourceStamp(util.ComparableMixin, styles.Versioned):
changes = ()
ssid = None # filled in by db.get_sourcestampid()

compare_attrs = ('branch', 'revision', 'patch', 'changes')
compare_attrs = ('branch', 'revision', 'patch', 'changes', 'project', 'repository')

implements(interfaces.ISourceStamp)

def __init__(self, branch=None, revision=None, patch=None,
changes=None):
changes=None, project='', repository=''):
if branch is not None:
assert isinstance(branch, str), type(branch)
if revision is not None:
Expand All @@ -56,6 +56,8 @@ def __init__(self, branch=None, revision=None, patch=None,
self.branch = branch
self.revision = revision
self.patch = patch
self.project = project
self.repository = repository
if changes:
self.changes = tuple(changes)
# set branch and revision to most recent change
Expand Down Expand Up @@ -152,4 +154,9 @@ def upgradeToVersion1(self):
if self.patch is not None and not isinstance(self.patch, str):
self.patch = str(self.patch)

def upgradeToVersion2(self):
# version 1 did not have project or repository; just set them to a default ''
self.project = ''
self.repository = ''

# vim: set ts=4 sts=4 sw=4 et:
14 changes: 13 additions & 1 deletion buildbot/status/web/templates/change_macros.html
@@ -1,4 +1,4 @@
{% macro change(who, at, branch, rev, files, comments, properties, revlink, number) %}
{% macro change(who, at, branch, rev, files, comments, properties, revlink, number, repository, project) %}

<h3>Change {{ number }}</h3>

Expand All @@ -11,6 +11,18 @@ <h3>Change {{ number }}</h3>
<td class="left">Changed at</td><td><b>{{ at }}</b></td>
</tr>

{% if repository %}
<tr class="{{ row_class.next() }}">
<td class="left">Repository</td><td><b>{{ repository|e }}</b></td>
</tr>
{% endif %}

{% if project %}
<tr class="{{ row_class.next() }}">
<td class="left">Project</td><td><b>{{ project|e }}</b></td>
</tr>
{% endif %}

{% if branch %}
<tr class="{{ row_class.next() }}">
<td class="left">Branch</td><td><b>{{ branch|e }}</b></td>
Expand Down

0 comments on commit 1679a52

Please sign in to comment.