Permalink
Browse files

Convert to githubsimple project

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

0 comments on commit c15b551

Please sign in to comment.