sagemath / sage_trac_plugin

Trac plugin used to support Sage development at trac.sagemath.org
5 stars 6 forks source link

Add links to github and gitlab branches in ticket #23

Closed tobiasdiez closed 3 years ago

tobiasdiez commented 3 years ago

Add links to the github and gitlab mirrors in the ticket description, since both have a visual appealing interface and are able to show the content of the branch even with merge conflicts. It should look as follows: image

(Again with the caveat that I don't know how to test the code...)

embray commented 3 years ago

This looks nice. I'll see if I can get my staging instance of trac.sagemath.org up-and-running again and test it.

embray commented 3 years ago

There used to be a repo...I thought it was on GitHub...where I documented a lot of this stuff. I wonder what happened to it. I can't find it anymore (and it needs to be updated a bit probably).

embray commented 3 years ago

I found it--for some reason it's under William Stein's account, I guess because he had some allowance for private repos. We should probably move it. Also I don't think there's any information that needs to be kept strictly private, though we can leave it private now.

embray commented 3 years ago

I had to make the following additional changes for it to work. The problem is the local variable branch was later being replaced from the branch name to a pygit Commit object. I changed it to use a new variable for that purpose:

diff --git a/sage_trac/ticket_box.py b/sage_trac/ticket_box.py
index 0f35c9b..ebaf572 100644
--- a/sage_trac/ticket_box.py
+++ b/sage_trac/ticket_box.py
@@ -135,11 +135,11 @@ class TicketBox(git_merger.GitMerger):
             if url is not None:
                 links.append(tag.a('Commits', href=url))
                 links.append(tag.span(', '))
-            github_url = f"https://github.com/sagemath/sagetrac-mirror/compare/develop...{branch}"
-            gitlab_url = f"https://gitlab.com/sagemath/dev/tracmirror/-/compare/develop...{branch}"
-            links.append(tag.a('GitHub', href=github_url))
+            github_url = "https://github.com/sagemath/sagetrac-mirror/compare/develop...{branch}"
+            gitlab_url = "https://gitlab.com/sagemath/dev/tracmirror/-/compare/develop...{branch}"
+            links.append(tag.a('GitHub', href=github_url.format(branch=branch)))
             links.append(tag.span(', '))
-            links.append(tag.a('GitLab', href=gitlab_url))
+            links.append(tag.a('GitLab', href=gitlab_url.format(branch=branch)))
             links.append(tag.span(')'))
             return FILTER_BRANCH.append(links)

@@ -158,10 +158,10 @@ class TicketBox(git_merger.GitMerger):
                 base_branch = None

         try:
-            is_sha, branch = self.generic_lookup(branch)
+            is_sha, branch_commit = self.generic_lookup(branch)
             if is_sha:
                 filters.append(
-                        FILTER_BRANCH_TEXT.replace(branch.hex[:7]+' '))
+                        FILTER_BRANCH_TEXT.replace(branch_commit.hex[:7]+' '))

             if base_branch:
                 _, base_branch_commit = self.generic_lookup(base_branch)
@@ -173,8 +173,8 @@ class TicketBox(git_merger.GitMerger):
             else:
                 return error("sha1 hash is too ambiguous")

-        ret = self.peek_merge(branch, base_branch=base_branch)
-        _, log_url = self.get_merge_url(req, branch, ret,
+        ret = self.peek_merge(branch_commit, base_branch=base_branch)
+        _, log_url = self.get_merge_url(req, branch_commit, ret,
                                         base=base_branch_commit)

         # For the merge-url just always pass through the git-merger frontend
@@ -183,7 +183,7 @@ class TicketBox(git_merger.GitMerger):
             params.append(('base', base_branch))

         if branch:
-            git_merger_url = req.abs_href('/git-merger/' + branch.hex, params)
+            git_merger_url = req.abs_href('/git-merger/' + branch_commit.hex, params)
         else:
             git_merger_url = None
tobiasdiez commented 3 years ago

Ok thanks!

tobiasdiez commented 3 years ago

Any news on bringing this live?

tobiasdiez commented 3 years ago

Bump!

embray commented 3 years ago

I added this manually along with a few additional minor changes in f19f3ba. Thanks!