From 5e2808ee1f833dd7d2a79c03c7791278a3eaf80d Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Sun, 19 Nov 2017 23:22:12 +0100 Subject: [PATCH 01/14] Extend the database schema to save the repository for comments The respository name is currently saved in the 'path' column for comments. For subscriptions however it is stored in a separate column. --- code_comments/db.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/code_comments/db.py b/code_comments/db.py index 0fb56a2..e2f6356 100644 --- a/code_comments/db.py +++ b/code_comments/db.py @@ -4,9 +4,10 @@ from trac.db.schema import Table, Column, Index from trac.env import IEnvironmentSetupParticipant from trac.db.api import DatabaseManager +from trac.versioncontrol.api import RepositoryManager # Database version identifier for upgrades. -db_version = 3 +db_version = 4 db_version_key = 'code_comments_schema_version' # Database schema @@ -21,8 +22,11 @@ Column('author'), Column('time', type='int'), Column('type'), + Column('reponame'), Index(['path']), Index(['author']), + Index(['reponame', 'path']), + Index(['revision', 'reponame']), ], 'code_comments_subscriptions': Table('code_comments_subscriptions', key=('id', 'user', 'type', 'path', @@ -76,9 +80,34 @@ def upgrade_from_2_to_3(env): dbm.create_tables((schema['code_comments_subscriptions'],)) +def upgrade_from_3_to_4(env): + with env.db_transaction as db: + # Add the new column "reponame" and indexes. + db('ALTER TABLE code_comments ADD COLUMN reponame text') + db('CREATE INDEX code_comments_reponame_path_idx ON code_comments (reponame, path)') + db('CREATE INDEX code_comments_revision_reponame_idx ON code_comments (revision, reponame)') + + # Comments on attachments need to have the empty string as the reponame instead of NULL. + db("UPDATE code_comments SET reponame = '' WHERE type = 'attachment'") + + # Comments on changesets have the reponame in the 'path' column. + db("UPDATE code_comments SET reponame = path, path = '' WHERE type = 'changeset'") + + # Comments on files have the reponame as the first component of the 'path' column. + db(""" + UPDATE code_comments + SET + reponame = substr(path, 1, instr(path, '/') - 1), + path = substr(path, instr(path, '/') + 1) + WHERE + type = 'browser' + """) + + upgrade_map = { 2: upgrade_from_1_to_2, 3: upgrade_from_2_to_3, + 4: upgrade_from_3_to_4, } From 15bf0597e384597a9aa2ae7414c11d430322a129 Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Fri, 17 Nov 2017 01:00:37 +0100 Subject: [PATCH 02/14] Add reponame to data for JavaScript --- code_comments/web.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code_comments/web.py b/code_comments/web.py index 83342c7..ad45746 100644 --- a/code_comments/web.py +++ b/code_comments/web.py @@ -121,16 +121,18 @@ def templates_js_data(self): def changeset_js_data(self, req, data): return { 'page': 'changeset', + 'reponame': data['reponame'], 'revision': data['new_rev'], - 'path': data['reponame'], + 'path': '', 'selectorToInsertAfter': 'div.diff div.diff:last' } def browser_js_data(self, req, data): return { 'page': 'browser', + 'reponame': data['reponame'], 'revision': data['rev'], - 'path': (data['reponame'] or '') + '/' + data['path'], + 'path': data['path'], 'selectorToInsertAfter': 'table.code' } @@ -138,6 +140,7 @@ def attachment_js_data(self, req, data): path = req.path_info.replace('/attachment/', 'attachment:/') return { 'page': 'attachment', + 'reponame': '', 'revision': 0, 'path': path, 'selectorToInsertAfter': 'div#preview' From bde9868a336f8640e396cd18ef5039118a0e96f2 Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Mon, 28 Aug 2023 00:38:38 +0200 Subject: [PATCH 03/14] Use reponame when fetching comments for a page --- code_comments/htdocs/code-comments.js | 1 + 1 file changed, 1 insertion(+) diff --git a/code_comments/htdocs/code-comments.js b/code_comments/htdocs/code-comments.js index fe1cda6..4e43f2a 100644 --- a/code_comments/htdocs/code-comments.js +++ b/code_comments/htdocs/code-comments.js @@ -28,6 +28,7 @@ var underscore = _.noConflict(); }, defaultFetchParams: { path: CodeComments.path || undefined, + reponame: CodeComments.reponame, revision: CodeComments.revision, type: CodeComments.page, }, From bb1acf6371e6b73791f9ee9b59ee9d74f24d911d Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Mon, 28 Aug 2023 00:03:35 +0200 Subject: [PATCH 04/14] Send reponame when creating a comment --- code_comments/htdocs/code-comments.js | 1 + 1 file changed, 1 insertion(+) diff --git a/code_comments/htdocs/code-comments.js b/code_comments/htdocs/code-comments.js index 4e43f2a..e9177dd 100644 --- a/code_comments/htdocs/code-comments.js +++ b/code_comments/htdocs/code-comments.js @@ -218,6 +218,7 @@ var underscore = _.noConflict(); text: text, author: CodeComments.username, path: this.path, + reponame: CodeComments.reponame, revision: CodeComments.revision, line: line, type: CodeComments.page From 47d52a962f46ca06069dac194a8c9991a29ff4ea Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Mon, 20 Nov 2017 00:04:38 +0100 Subject: [PATCH 05/14] Use reponame when constructing links to comments --- code_comments/comment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code_comments/comment.py b/code_comments/comment.py index 8850db9..428e380 100644 --- a/code_comments/comment.py +++ b/code_comments/comment.py @@ -71,10 +71,10 @@ def validate(self): def href(self): if self.is_comment_to_file: - href = self.req.href.browser(self.path, rev=self.revision, + href = self.req.href.browser(self.reponame + '/' + self.path, rev=self.revision, codecomment=self.id) elif self.is_comment_to_changeset: - href = self.req.href.changeset(self.revision, codecomment=self.id) + href = self.req.href.changeset(self.revision + '/' + self.reponame, codecomment=self.id) elif self.is_comment_to_attachment: href = self.req.href('/attachment/ticket/%d/%s' % (self.attachment_ticket, From f4acbaaff09fe871c50830f54433c92a370610d4 Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Mon, 20 Nov 2017 00:28:02 +0100 Subject: [PATCH 06/14] Make subscription from comment use the reponame from the comment Until now it used the path to determine the repository. --- code_comments/subscription.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code_comments/subscription.py b/code_comments/subscription.py index cbe14dc..fe7a707 100644 --- a/code_comments/subscription.py +++ b/code_comments/subscription.py @@ -236,13 +236,13 @@ def from_comment(cls, env, comment, user=None, notify=True): # Munge changesets and browser if comment.type in ('changeset', 'browser'): - rm = RepositoryManager(env) - reponame, repos, path = rm.get_repository_by_path(comment.path) if comment.type == 'browser': - sub['path'] = path + sub['path'] = comment.path else: sub['path'] = '' - sub['repos'] = reponame or '(default)' + sub['repos'] = comment.reponame + rm = RepositoryManager(env) + repos = rm.get_repository(comment.reponame) try: _cs = repos.get_changeset(comment.revision) except NoSuchChangeset: From f35cf284d8b2e3ac34ec95974affc247435be5d1 Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Wed, 30 Aug 2023 23:10:52 +0200 Subject: [PATCH 07/14] Add new column 'repository' to the list of code comments --- code_comments/comments.py | 2 +- code_comments/templates/comments.html | 1 + code_comments/web.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/code_comments/comments.py b/code_comments/comments.py index b8282e9..40ce5e1 100644 --- a/code_comments/comments.py +++ b/code_comments/comments.py @@ -13,7 +13,7 @@ class Comments(object): def __init__(self, req, env): self.req, self.env = req, env - self.valid_sorting_methods = ('id', 'author', 'time', 'path', 'text') + self.valid_sorting_methods = ('id', 'author', 'time', 'reponame', 'path', 'text') def comment_from_row(self, row): return Comment(self.req, self.env, row) diff --git a/code_comments/templates/comments.html b/code_comments/templates/comments.html index 2870244..494bc9a 100644 --- a/code_comments/templates/comments.html +++ b/code_comments/templates/comments.html @@ -49,6 +49,7 @@

Code Comments

$comment.id $comment.author ${comment.formatted_date()} + $comment.reponame ${comment.path_link_tag()} $comment.html ${comment.get_ticket_links()} diff --git a/code_comments/web.py b/code_comments/web.py index ad45746..4689948 100644 --- a/code_comments/web.py +++ b/code_comments/web.py @@ -243,9 +243,9 @@ def href_with_page(page): def prepare_sortable_headers(self): displayed_sorting_methods = \ - ('id', 'author', 'time', 'path', 'text') + ('id', 'author', 'time', 'reponame', 'path', 'text') displayed_sorting_method_names = \ - ('ID', 'Author', 'Date', 'Path', 'Text') + ('ID', 'Author', 'Date', 'Repository', 'Path', 'Text') query_args = self.req.args if 'page' in query_args: del query_args['page'] From fdaff49857f31d28411375f5cf11de5486b5be0f Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Wed, 30 Aug 2023 22:57:15 +0200 Subject: [PATCH 08/14] Allow filtering the list of code comments by repository --- code_comments/comments.py | 5 +++++ code_comments/templates/comments.html | 6 ++++++ code_comments/web.py | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/code_comments/comments.py b/code_comments/comments.py index 40ce5e1..6f7c7a1 100644 --- a/code_comments/comments.py +++ b/code_comments/comments.py @@ -21,10 +21,15 @@ def comment_from_row(self, row): def get_filter_values(self): comments = self.all() return { + 'repos': self.get_all_repos(comments), 'paths': self.get_all_paths(comments), 'authors': self.get_all_comment_authors(comments), } + def get_all_repos(self, comments): + # Skip the empty string which is the repository for comments on attachments + return sorted(list(set([comment.reponame for comment in comments if comment.reponame != '']))) + def get_all_paths(self, comments): def get_directory(path): parts = os.path.split(path)[0].split('/') diff --git a/code_comments/templates/comments.html b/code_comments/templates/comments.html index 494bc9a..848a1d6 100644 --- a/code_comments/templates/comments.html +++ b/code_comments/templates/comments.html @@ -15,6 +15,12 @@

Code Comments

 Filter comments:
+