Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Convert to githubsimple project

  • Loading branch information...
commit c15b551485c98a8138f7e3bfd5978f6bbe03d8dd 1 parent ef00412
Pauli Virtanen authored
4  .gitignore
... ...
@@ -1,3 +1,7 @@
  1
+*.pyc
  2
+*.pyo
  3
+*~
  4
+*.swp
1 5
 *.egg-info
2 6
 build
3 7
 dist
83  README
... ...
@@ -1,83 +0,0 @@
1  
-I have officially taken this project over, so all forks of this project should happen here not upstream.
2  
-
3  
-======================================================================================================
4  
-
5  
-Please file bug reports here:
6  
-http://davglass.lighthouseapp.com/projects/21212/home
7  
-
8  
-======================================================================================================
9  
-
10  
-This trac plugin is designed to accept a GitHub Post-Receive url.
11  
-
12  
-It also allows you to replace the builtin Trac browser with redirects to the GitHub source browser.
13  
-
14  
-More information about the Post-Receive Hook can be found here:
15  
-http://github.com/guides/post-receive-hooks
16  
-
17  
-To install this Trac Plugin:
18  
-
19  
-    1. Clone the repository:
20  
-        git clone git://github.com/davglass/github-trac.git
21  
-
22  
-    2. Install SimpleJSON:
23  
-        easy_install simplejson
24  
-
25  
-    3. Install the Plugin:
26  
-        cd github
27  
-        sudo python setup.py install
28  
-
29  
-    4. Configure Trac by editing your trac.ini
30  
-        
31  
-        [components]
32  
-        github.* = enabled
33  
-
34  
-        [github]
35  
-        apitoken = YOUR GITHUB API TOKEN
36  
-        closestatus = closed (This is optional, defaults to closed
37  
-        browser = http://github.com/davglass/tree/master
38  
-
39  
-        #Optional - perform a fetch on the local git repository
40  
-        autofetch = true
41  
-        
42  
-    5. Go to the Admin page for your project on GitHub. Then select the services tab.
43  
-        Under the: Post-Receive URLs
44  
-        Place a link to your Trac repository, in a format like this:
45  
-        
46  
-        http://yourdomian.com/projects/projectname/github/APITOKEN
47  
-
48  
-        You can get your GitHub API token from your accounts page.
49  
-        This is for your security, only those that know the API Token will able to post to this url
50  
-
51  
-    6. All done.
52  
-
53  
-
54  
-======================================================================================================
55  
-
56  
-The commit hook is designed to close or mark tickets that are attached to a commit message.
57  
-
58  
-
59  
-It searches commit messages for text in the form of:
60  
-    command #1
61  
-    command #1, #2
62  
-    command #1 & #2 
63  
-    command #1 and #2
64  
-
65  
-Instead of the short-hand syntax "#1", "ticket:1" can be used as well, e.g.:
66  
-    command ticket:1
67  
-    command ticket:1, ticket:2
68  
-    command ticket:1 & ticket:2 
69  
-    command ticket:1 and ticket:2
70  
-
71  
-======================================================================================================
72  
-
73  
-The Code Browser
74  
-
75  
-The code browser portion of the plugin is designed to replace the code browser built into Trac with a
76  
-redirect to the GitHub source browser.
77  
-
78  
-In order for this to work properly, you still need to have Trac set to show a git repository. Turning this off
79  
-will not show source control links in other places (timeline). This git repository needs to be a synced clone of
80  
-your GitHub repository. Trac requires the GitPlugin in order to show a Git Repository: http://trac-hacks.org/wiki/GitPlugin
81  
-
82  
-
83  
-This plugin will attempt to intercept the /browser and /changeset url's and redirect you to the proper GitHub url.
62  README.rst
Source Rendered
... ...
@@ -0,0 +1,62 @@
  1
+=================
  2
+githubsimple-trac
  3
+=================
  4
+
  5
+This is a simplified version of the Trac/Github integration plugin
  6
+http://github.com/davglass/github-trac
  7
+
  8
+Many features and most dependencies are stripped, leaving only the browser/ and changeset/
  9
+redirects.
  10
+
  11
+
  12
+Installation
  13
+============
  14
+
  15
+This plugin allows you to replace the builtin Trac browser with redirects to the GitHub source browser.
  16
+
  17
+To install this Trac Plugin:
  18
+
  19
+    1. Clone the repository::
  20
+
  21
+        git clone git://github.com/pv/githubsimple-trac.git
  22
+
  23
+    2. Install the Plugin::
  24
+
  25
+        cd githubsimple-trac
  26
+        sudo python setup.py install   # ... or something similar
  27
+
  28
+    3. Configure Trac by editing your ``trac.ini``::
  29
+        
  30
+        [components]
  31
+        githubsimple.* = enabled
  32
+
  33
+        [githubsimple]
  34
+        browser = http://github.com/davglass/tree/master
  35
+        
  36
+    4. All done.
  37
+
  38
+
  39
+The Code Browser
  40
+================
  41
+
  42
+The code browser portion of the plugin is designed to replace the code browser
  43
+built into Trac with a simple redirect to the GitHub source browser.
  44
+
  45
+Note that this will not make the commits appear in the timeline etc. You need
  46
+the GitPlugin to do that: http://trac-hacks.org/wiki/GitPlugin
  47
+
  48
+Also, if you want that, consider using the full github-trac plugin.
  49
+
  50
+
  51
+Changesets
  52
+==========
  53
+
  54
+This plugin intercepts the /changeset url, which allows using::
  55
+
  56
+    changeset:98d9ffe2
  57
+
  58
+syntax to refer to Git commits.
  59
+
  60
+It tries to automatically detect if the commit is a valid SVN revision number,
  61
+and in that case points it to Trac's builtin source browser instead of Github.
  62
+(May be useful for projects converted from SVN...)
3  dev.sh
... ...
@@ -1,3 +0,0 @@
1  
-#!/bin/bash
2  
-sudo python setup.py install && sudo /etc/init.d/apache2 force-reload
3  
-
1  github/__init__.py
... ...
@@ -1 +0,0 @@
1  
-from github import GithubPlugin
122  github/github.py
... ...
@@ -1,122 +0,0 @@
1  
-from trac.core import *
2  
-from trac.config import Option, IntOption, ListOption, BoolOption
3  
-from trac.web.api import IRequestFilter, IRequestHandler, Href
4  
-from trac.util.translation import _
5  
-from hook import CommitHook
6  
-
7  
-import simplejson
8  
-
9  
-from git import Git
10  
-
11  
-class GithubPlugin(Component):
12  
-    implements(IRequestHandler, IRequestFilter)
13  
-    
14  
-    
15  
-    key = Option('github', 'apitoken', '', doc="""Your GitHub API Token found here: https://github.com/account, """)
16  
-    closestatus = Option('github', 'closestatus', '', doc="""This is the status used to close a ticket. It defaults to closed.""")
17  
-    browser = Option('github', 'browser', '', doc="""Place your GitHub Source Browser URL here to have the /browser entry point redirect to GitHub.""")
18  
-    autofetch = Option('github', 'autofetch', '', doc="""Should we auto fetch the repo when we get a commit hook from GitHub.""")
19  
-    repo = Option('trac', 'repository_dir' '', doc="""This is your repository dir""")
20  
-
21  
-    def __init__(self):
22  
-        self.hook = CommitHook(self.env)
23  
-        self.env.log.debug("API Token: %s" % self.key)
24  
-        self.env.log.debug("Browser: %s" % self.browser)
25  
-        self.processHook = False
26  
-
27  
-    
28  
-    # IRequestHandler methods
29  
-    def match_request(self, req):
30  
-        self.env.log.debug("Match Request")
31  
-        serve = req.path_info.rstrip('/') == ('/github/%s' % self.key) and req.method == 'POST'
32  
-        if serve:
33  
-            self.processHook = True
34  
-            #This is hacky but it's the only way I found to let Trac post to this request
35  
-            #   without a valid form_token
36  
-            req.form_token = None
37  
-
38  
-        self.env.log.debug("Handle Request: %s" % serve)
39  
-        return serve
40  
-    
41  
-    def process_request(self, req):
42  
-        if self.processHook:
43  
-            self.processCommitHook(req)
44  
-
45  
-    # This has to be done via the pre_process_request handler
46  
-    # Seems that the /browser request doesn't get routed to match_request :(
47  
-    def pre_process_request(self, req, handler):
48  
-        if self.browser:
49  
-            serve = req.path_info.startswith('/browser')
50  
-            self.env.log.debug("Handle Pre-Request /browser: %s" % serve)
51  
-            if serve:
52  
-                self.processBrowserURL(req)
53  
-
54  
-            serve2 = req.path_info.startswith('/changeset')
55  
-            self.env.log.debug("Handle Pre-Request /changeset: %s" % serve2)
56  
-            if serve2:
57  
-                self.processChangesetURL(req)
58  
-
59  
-        return handler
60  
-
61  
-
62  
-    def post_process_request(self, req, template, data, content_type):
63  
-        return (template, data, content_type)
64  
-
65  
-
66  
-    def processChangesetURL(self, req):
67  
-        self.env.log.debug("processChangesetURL")
68  
-        browser = self.browser.replace('/tree/master', '/commit/')
69  
-        
70  
-        url = req.path_info.replace('/changeset/', '')
71  
-        if not url:
72  
-            browser = self.browser
73  
-            url = ''
74  
-
75  
-        redirect = '%s%s' % (browser, url)
76  
-        self.env.log.debug("Redirect URL: %s" % redirect)
77  
-        out = 'Going to GitHub: %s' % redirect
78  
-
79  
-        req.redirect(redirect)
80  
-
81  
-
82  
-    def processBrowserURL(self, req):
83  
-        self.env.log.debug("processBrowserURL")
84  
-        browser = self.browser.replace('/master', '/')
85  
-        rev = req.args.get('rev')
86  
-        
87  
-        url = req.path_info.replace('/browser', '')
88  
-        if not rev:
89  
-            rev = ''
90  
-
91  
-        redirect = '%s%s%s' % (browser, rev, url)
92  
-        self.env.log.debug("Redirect URL: %s" % redirect)
93  
-        out = 'Going to GitHub: %s' % redirect
94  
-
95  
-        req.redirect(redirect)
96  
-
97  
-        
98  
-
99  
-    def processCommitHook(self, req):
100  
-        self.env.log.debug("processCommitHook")
101  
-        status = self.closestatus
102  
-        if not status:
103  
-            status = 'closed'
104  
-
105  
-        data = req.args.get('payload')
106  
-         
107  
-        if data:
108  
-            jsondata = simplejson.loads(data)
109  
-
110  
-            for i in jsondata['commits']:
111  
-                self.hook.process(i, status)
112  
-
113  
-
114  
-        if self.autofetch:
115  
-            repo = Git(self.repo)
116  
-
117  
-            try:
118  
-              repo.execute(['git', 'fetch'])
119  
-            except:
120  
-              self.env.log.debug("git fetch failed!")
121  
-
122  
-
153  github/hook.py
... ...
@@ -1,153 +0,0 @@
1  
-# trac-post-commit-hook
2  
-# ----------------------------------------------------------------------------
3  
-# Copyright (c) 2004 Stephen Hansen 
4  
-#
5  
-# Permission is hereby granted, free of charge, to any person obtaining a copy
6  
-# of this software and associated documentation files (the "Software"), to
7  
-# deal in the Software without restriction, including without limitation the
8  
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  
-# sell copies of the Software, and to permit persons to whom the Software is
10  
-# furnished to do so, subject to the following conditions:
11  
-#
12  
-#   The above copyright notice and this permission notice shall be included in
13  
-#   all copies or substantial portions of the Software. 
14  
-#
15  
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  
-# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  
-# IN THE SOFTWARE.
22  
-# ----------------------------------------------------------------------------
23  
-#
24  
-# It searches commit messages for text in the form of:
25  
-#   command #1
26  
-#   command #1, #2
27  
-#   command #1 & #2 
28  
-#   command #1 and #2
29  
-#
30  
-# Instead of the short-hand syntax "#1", "ticket:1" can be used as well, e.g.:
31  
-#   command ticket:1
32  
-#   command ticket:1, ticket:2
33  
-#   command ticket:1 & ticket:2 
34  
-#   command ticket:1 and ticket:2
35  
-#
36  
-# In addition, the ':' character can be omitted and issue or bug can be used
37  
-# instead of ticket.
38  
-#
39  
-# You can have more then one command in a message. The following commands
40  
-# are supported. There is more then one spelling for each command, to make
41  
-# this as user-friendly as possible.
42  
-#
43  
-#   close, closed, closes, fix, fixed, fixes
44  
-#     The specified issue numbers are closed with the contents of this
45  
-#     commit message being added to it. 
46  
-#   references, refs, ref, addresses, re, see 
47  
-#     The specified issue numbers are left in their current status, but 
48  
-#     the contents of this commit message are added to their notes. 
49  
-#
50  
-# A fairly complicated example of what you can do is with a commit message
51  
-# of:
52  
-#
53  
-#    Changed blah and foo to do this or that. Fixes #10 and #12, and refs #12.
54  
-#
55  
-# This will close #10 and #12, and add a note to #12.
56  
-
57  
-import re
58  
-import os
59  
-import sys
60  
-from datetime import datetime
61  
-
62  
-from trac.env import open_environment
63  
-from trac.ticket.notification import TicketNotifyEmail
64  
-from trac.ticket import Ticket
65  
-from trac.ticket.web_ui import TicketModule
66  
-# TODO: move grouped_changelog_entries to model.py
67  
-from trac.util.text import to_unicode
68  
-from trac.util.datefmt import utc
69  
-from trac.versioncontrol.api import NoSuchChangeset
70  
-from trac.config import Option, IntOption, ListOption, BoolOption
71  
-
72  
-ticket_prefix = '(?:#|(?:ticket|issue|bug)[: ]?)'
73  
-ticket_reference = ticket_prefix + '[0-9]+'
74  
-ticket_command =  (r'(?P<action>[A-Za-z]*).?'
75  
-                   '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)' %
76  
-                   (ticket_reference, ticket_reference))
77  
-     
78  
-command_re = re.compile(ticket_command)
79  
-ticket_re = re.compile(ticket_prefix + '([0-9]+)')
80  
-
81  
-class CommitHook:
82  
-    _supported_cmds = {'close':      '_cmdClose',
83  
-                       'closed':     '_cmdClose',
84  
-                       'closes':     '_cmdClose',
85  
-                       'fix':        '_cmdClose',
86  
-                       'fixed':      '_cmdClose',
87  
-                       'fixes':      '_cmdClose',
88  
-                       'addresses':  '_cmdRefs',
89  
-                       're':         '_cmdRefs',
90  
-                       'references': '_cmdRefs',
91  
-                       'refs':       '_cmdRefs',
92  
-                       'ref':       '_cmdRefs',
93  
-                       'see':        '_cmdRefs'}
94  
-
95  
-
96  
-    def __init__(self, env):
97  
-        self.env = env
98  
-
99  
-    def process(self, commit, status):
100  
-        self.closestatus = status
101  
-        
102  
-        msg = commit['message']
103  
-        self.env.log.debug("Processing Commit: %s", msg)
104  
-        note = "Changeset: %s" % commit['id']
105  
-        msg = "%s \n %s" % (msg, note)
106  
-        author = commit['author']['name']
107  
-        timestamp = datetime.now(utc)
108  
-        
109  
-        cmd_groups = command_re.findall(msg)
110  
-        self.env.log.debug("Function Handlers: %s" % cmd_groups)
111  
-
112  
-        tickets = {}
113  
-        for cmd, tkts in cmd_groups:
114  
-            funcname = self.__class__._supported_cmds.get(cmd.lower(), '')
115  
-            self.env.log.debug("Function Handler: %s" % funcname)
116  
-            if funcname:
117  
-                for tkt_id in ticket_re.findall(tkts):
118  
-                    func = getattr(self, funcname)
119  
-                    tickets.setdefault(tkt_id, []).append(func)
120  
-
121  
-        for tkt_id, cmds in tickets.iteritems():
122  
-            try:
123  
-                db = self.env.get_db_cnx()
124  
-                
125  
-                ticket = Ticket(self.env, int(tkt_id), db)
126  
-                for cmd in cmds:
127  
-                    cmd(ticket)
128  
-
129  
-                # determine sequence number... 
130  
-                cnum = 0
131  
-                tm = TicketModule(self.env)
132  
-                for change in tm.grouped_changelog_entries(ticket, db):
133  
-                    if change['permanent']:
134  
-                        cnum += 1
135  
-                
136  
-                ticket.save_changes(author, msg, timestamp, db, cnum+1)
137  
-                db.commit()
138  
-                
139  
-                tn = TicketNotifyEmail(self.env)
140  
-                tn.notify(ticket, newticket=0, modtime=timestamp)
141  
-            except Exception, e:
142  
-                import traceback
143  
-                traceback.print_exc(file=sys.stderr)
144  
-                #print>>sys.stderr, 'Unexpected error while processing ticket ' \
145  
-                                   #'ID %s: %s' % (tkt_id, e)
146  
-            
147  
-
148  
-    def _cmdClose(self, ticket):
149  
-        ticket['status'] = self.closestatus
150  
-        ticket['resolution'] = 'fixed'
151  
-
152  
-    def _cmdRefs(self, ticket):
153  
-        pass
1  githubsimple/__init__.py
... ...
@@ -0,0 +1 @@
  1
+from github import GithubSimplePlugin
76  githubsimple/github.py
... ...
@@ -0,0 +1,76 @@
  1
+from trac.core import *
  2
+from trac.config import Option, IntOption, ListOption, BoolOption
  3
+from trac.web.api import IRequestFilter, IRequestHandler, Href
  4
+from trac.util.translation import _
  5
+
  6
+def is_svn_rev(rev):
  7
+    try:
  8
+        revno = int(rev)
  9
+    except (TypeError, ValueError):
  10
+        return False
  11
+    if revno > 100000:
  12
+        return False
  13
+    return True
  14
+
  15
+class GithubSimplePlugin(Component):
  16
+    implements(IRequestHandler, IRequestFilter)
  17
+    
  18
+    browser = Option('githubsimple', 'browser', '', doc="""Place your GitHub Source Browser URL here to have the /browser entry point redirect to GitHub.""")
  19
+
  20
+    def __init__(self):
  21
+        self.env.log.debug("Browser: %s" % self.browser)
  22
+    
  23
+    # This has to be done via the pre_process_request handler
  24
+    # Seems that the /browser request doesn't get routed to match_request :(
  25
+    def pre_process_request(self, req, handler):
  26
+        if self.browser:
  27
+            serve = req.path_info.startswith('/browser') \
  28
+			and not is_svn_rev(req.args.get('rev'))
  29
+            self.env.log.debug("Handle Pre-Request /browser: %s" % serve)
  30
+            if serve:
  31
+                self.processBrowserURL(req)
  32
+
  33
+            serve2 = req.path_info.startswith('/changeset') \
  34
+			and not is_svn_rev(req.path_info.replace('/changeset/', ''))
  35
+            self.env.log.debug("Handle Pre-Request /changeset: %s" % serve2)
  36
+            if serve2:
  37
+                self.processChangesetURL(req)
  38
+
  39
+        return handler
  40
+
  41
+
  42
+    def post_process_request(self, req, template, data, content_type):
  43
+        return (template, data, content_type)
  44
+
  45
+
  46
+    def processChangesetURL(self, req):
  47
+        self.env.log.debug("processChangesetURL")
  48
+        browser = self.browser.replace('/tree/master', '/commit/')
  49
+        
  50
+        url = req.path_info.replace('/changeset/', '')
  51
+        if not url:
  52
+            browser = self.browser
  53
+            url = ''
  54
+
  55
+        redirect = '%s%s' % (browser, url)
  56
+        self.env.log.debug("Redirect URL: %s" % redirect)
  57
+        out = 'Going to GitHub: %s' % redirect
  58
+
  59
+        req.redirect(redirect)
  60
+
  61
+
  62
+    def processBrowserURL(self, req):
  63
+        self.env.log.debug("processBrowserURL")
  64
+        browser = self.browser.replace('/master', '/')
  65
+        rev = req.args.get('rev')
  66
+        
  67
+        url = req.path_info.replace('/browser', '')
  68
+        if not rev:
  69
+            rev = ''
  70
+
  71
+        redirect = '%s%s%s' % (browser, rev, url)
  72
+        self.env.log.debug("Redirect URL: %s" % redirect)
  73
+        out = 'Going to GitHub: %s' % redirect
  74
+
  75
+        req.redirect(redirect)
  76
+
30  setup.py
... ...
@@ -1,29 +1,19 @@
1 1
 from setuptools import find_packages, setup
2 2
 
3  
-# name can be any name.  This name will be used to create .egg file.
4  
-# name that is used in packages is the one that is used in the trac.ini file.
5  
-# use package name as entry_points
6  
-
7 3
 setup(
8  
-    name='GithubPlugin',
9  
-    version='0.4',
10  
-    author='Dav Glass',
11  
-    author_email='davglass@gmail.com',
12  
-    description = "Creates an entry point for a GitHub post-commit hook.",
13  
-    license = """Unknown Status""",
14  
-    url = "http://github.com/davglass/github-trac/tree/master",
  4
+    name='GithubSimplePlugin',
  5
+    version='0.1',
  6
+    author='Pauli Virtanen, Dav Glass',
  7
+    author_email='pav@iki.fi',
  8
+    description = "Redirects Trac /browser and /changeset urls to github.com",
  9
+    license = "BSD",
  10
+    url = "http://github.com/pv/githubsimple-trac",
15 11
     packages = find_packages(exclude=['*.tests*']),
16  
-	package_data={'github' : []},
17  
-
18  
-    install_requires = [
19  
-        'simplejson>=2.0.5',
20  
-        'GitPython>=0.1.6',
21  
-    ],
  12
+    package_data={'githubsimple' : []},
  13
+    install_requires = [],
22 14
     entry_points = {
23 15
         'trac.plugins': [
24  
-            'github = github',
25  
-
  16
+            'githubsimple = githubsimple',
26 17
         ]    
27 18
     }
28  
-
29 19
 )

0 notes on commit c15b551

Please sign in to comment.
Something went wrong with that request. Please try again.