Modify

Opened 19 years ago

Closed 19 years ago

Last modified 19 years ago

#105 closed enhancement (invalid)

Include changeset summaries in tickets

Reported by: billbrasky66@… Owned by: anybody
Priority: normal Component: Request-a-Hack
Severity: normal Keywords:
Cc: Trac Release:

Description

It would be nice to automagically include changeset summaries in tickets. So, if you commit to svn with something like: Ticket #2: Fixed bug in preprocessor that was causing NPE the changeset summary would get posted as a comment in the ticket (or at least linked). This is helpful on large projects where you want quick access to what diffs were required to fix a bug.

We did this in the past with a subversion hook that posted into a bugzilla database: (code compliments of Luke Francl look at recursion dot org)

#! /usr/bin/python

# Update Bugzilla when a commit message includes a bug number.

import sys
import os
import re
import MySQLdb
import time



# MySQL connection configuration
db_host="deathstar"
db_user="bugs"
db_password="bugs"
db_name="bugs"

# Regex taken from ViewCVS .92 with bug linking patch.
# match BUG followed by up to three non digit caracters followed by 
# three or more digits.
bug_re = re.compile( "[Bb][Uu][Gg]\D{1,3}(\d{3,})", re.DOTALL )

# map Subversion names to bugzilla login 
name_map = { 'jason' : 'jcwik', 'kurt': 'kmehlhof' }

# full path to svnlook
svnlook = "/usr/bin/svnlook"

def get_message( revision, repository_path ) :
    command = svnlook + " log -r " + revision + " " + repository_path

    pipe = os.popen( command )

    log_message = pipe.read()

    pipe.close()

    print( log_message )

    return log_message


def get_bugs( log_message ) :

    bugs = []

    for match in bug_re.finditer( log_message ) :
        bug_number = match.group( 1 )

        print( "Found bug number: " + bug_number )

        if ( bugs.count( bug_number ) == 0 ) :
           bugs.append( bug_number )

    return bugs


def get_userid( revision_number, repository_path ) :
    command = svnlook + " author -r " + revision_number + " " + repository_path

    pipe = os.popen( command )

    author = pipe.read().strip()

    pipe.close()

    if ( author == None or author == "" ) :
       raise Exception( "No author for " + revision_number + " in " + repository_path )

    if ( name_map.has_key( author ) ) :
       author = name_map[ author ]

    query = "select userid from profiles where login_name = '" + author + "'"

    print query

    connection = MySQLdb.connect( host=db_host, user=db_user, passwd=db_password, db=db_name )

    cursor = connection.cursor()

    if ( cursor.execute( query ) ) :

       row = cursor.fetchone()

       return row[0]


def get_changed_files( revision_number, repository_path ) :

    command = svnlook + " changed -r " + revision_number + " " + repository_path

    pipe = os.popen( command ) 

    changed_files = pipe.read()

    pipe.close()

    return changed_files


def add_comment( userid, bug_number, message ) : 

    insert = "insert into longdescs values( %s, %s, now(), %s )" 
    connection = MySQLdb.connect( host=db_host, user=db_user, passwd=db_password, db=db_name )

    cursor = connection.cursor()

    cursor.execute( insert, ( bug_number, userid, message ) )

    cursor.close()

    connection.close()


if __name__ == '__main__' :
   if ( len( sys.argv ) != 3 ) :
      print """Usage: update-bugzilla.py repository_path revision_number"""

      sys.exit()


   repository_path = sys.argv[ 1 ]
   revision_number = sys.argv[ 2 ]

   log_message = get_message( revision_number, repository_path )

   bugs = get_bugs( log_message )

   userid = get_userid( revision_number, repository_path )

   if userid == None : 
      sys.exit()

   changed_files = get_changed_files( revision_number, repository_path )

   message = log_message + "\n\n" + "Revision: " + revision_number + "\n" + "Changes: \n\n"
   message += changed_files

   print( repr( bugs ) )

   print( "UserID: " + str( userid ) )

   for bug_number in bugs:
      add_comment( userid, bug_number, message )

Attachments (0)

Change History (1)

comment:1 Changed 19 years ago by Alec Thomas

Resolution: invalid
Status: newclosed

This is already included in Trac.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain anybody.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.