Thread: [Codestriker-commits] CVS update: codestriker/lib/Codestriker/Repository ScmBug.pm
                
                Brought to you by:
                
                    sits
                    
                
            
            
        
        
        
    | 
      
      
      From: <si...@us...> - 2008-02-21 02:32:11
       | 
|   User: sits    
  Date: 08/02/20 18:32:10
  Modified:    .        CHANGELOG codestriker.conf
               bin      install.pl
               lib/Codestriker/Action SubmitNewTopic.pm
               lib/Codestriker/BugDB TestDirectorConnection.pm
  Added:       lib/Codestriker/Repository ScmBug.pm
  Log:
  * Support for creating reviews by just entering the bug IDs, and
    retrieving the data from Scmbug.
    Submitted by rob...@us....
  
  
  
  Index: CHANGELOG
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/CHANGELOG,v
  retrieving revision 1.223
  retrieving revision 1.224
  diff -u -r1.223 -r1.224
  --- CHANGELOG	18 Jan 2008 21:20:13 -0000	1.223
  +++ CHANGELOG	21 Feb 2008 02:32:09 -0000	1.224
  @@ -20,6 +20,10 @@
   * Support for TestDirector as a supported bug tracking system.
     Submitted by rob...@us....
   
  +* Support for creating reviews by just entering the bug IDs, and
  +  retrieving the data from Scmbug.
  +  Submitted by rob...@us....
  +
   * Make sure if an invalid CGI parameter value is specified that its
     value is encoded when displaying the generic error page.  Reported
     by ama...@us....
  
  
  
  
  
  Index: codestriker.conf
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/codestriker.conf,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- codestriker.conf	13 Jan 2008 09:15:20 -0000	1.90
  +++ codestriker.conf	21 Feb 2008 02:32:09 -0000	1.91
  @@ -399,6 +399,14 @@
   $bugtracker = 'http://localhost.localdomain/bugzilla/show_bug.cgi?id=';
   #$bugtracker = '/flyspray_dev/?do=details&id=';
   
  +# Some bug tracking systems store details of the files changed under each bug
  +# ID.  A generic plugin for bugzilla is scmbug which can be used to link
  +# with source control systems such as subversion.  The following flag
  +# enables/disables the ability for a user to create a topic by just
  +# using a Bug ID.
  +#$scmbug_hostname = 'hostname-of-scmbug-daemon';
  +#$scmbug_port = 3872;
  +
   # LXR database.  Each repository can be optionally mapped to a
   # different LXR deployment.  If a repository has an associated LXR
   # mapping, then create a new entry where the repository string is the
  
  
  
  
  
  Index: install.pl
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/bin/install.pl,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- install.pl	13 Jan 2008 09:15:21 -0000	1.15
  +++ install.pl	21 Feb 2008 02:32:09 -0000	1.16
  @@ -138,6 +138,14 @@
       push @{$modules}, { name => 'Win32::OLE', version => '0' };
   }
   
  +# Check that the necessary modules are present if ScmBug is used.
  +if (defined $Codestriker::scmbug_hostname &&
  +    $Codestriker::scmbug_hostname ne '') {
  +    push @{$modules}, { name => 'XML::Simple', version => '0' };
  +    push @{$modules}, { name => 'ScmBug::Connection', version => '0' };
  +    push @{$modules}, { name => 'ScmBug::Common', version => '0' };
  +}
  +
   # Check for various character encoding modules that are required.
   if (defined $Codestriker::topic_text_encoding) {
       if ($Codestriker::topic_text_encoding =~ /euc\-cn|gb2312|hz|gbk/) {
  
  
  
  
  
  Index: SubmitNewTopic.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/SubmitNewTopic.pm,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SubmitNewTopic.pm	7 Jun 2006 00:35:02 -0000	1.30
  +++ SubmitNewTopic.pm	21 Feb 2008 02:32:09 -0000	1.31
  @@ -17,6 +17,7 @@
   use Codestriker::Model::Topic;
   use Codestriker::Http::Render;
   use Codestriker::Repository::RepositoryFactory;
  +use Codestriker::Repository::ScmBug;
   use Codestriker::FileParser::Parser;
   use Codestriker::Model::Project;
   use Codestriker::TopicListeners::Manager;
  @@ -54,7 +55,9 @@
       # Indicate whether the topic text needs to be retrieved by the repository
       # object.
       my $retrieve_text_from_rep = 0;
  -    if (($start_tag ne "" || $end_tag ne "") && $module ne "") {
  +    if ((($start_tag ne "" || $end_tag ne "") && $module ne "") ||
  +	(defined $Codestriker::scmbug_host && $Codestriker::scmbug_host ne '' &&
  +	 $bug_ids ne '')) {
   	$retrieve_text_from_rep = 1;
   
   	# Check if this action is permitted.
  @@ -189,10 +192,22 @@
   	}
   	binmode $temp_topic_fh;
   	binmode $temp_error_fh;
  -	
  -	my $rc = $repository->getDiff($start_tag, $end_tag, $module,
  -				      $temp_topic_fh, $temp_error_fh,
  -				      $default_to_head);
  +
  +	my $rc;
  +	if ($start_tag eq '' && $end_tag eq '' && $module eq '') {
  +	    # Retrieve the diff from ScmBug and the repository object.
  +	    my $scmbug = Codestriker::Repository::ScmBug->new($Codestriker::scmbug_hostname,
  +							      $Codestriker::scmbug_port,
  +							      $repository);
  +	    $rc = $scmbug->getDiff($bug_ids, $temp_topic_fh, $temp_error_fh,
  +				   $default_to_head);
  +	    
  +	} else {
  +	    # Retrieve the diff directly from the repository object.
  +	    $rc = $repository->getDiff($start_tag, $end_tag, $module,
  +				       $temp_topic_fh, $temp_error_fh,
  +				       $default_to_head);
  +	}
   
   	# Make sure the data has been flushed to disk.
   	$temp_topic_fh->flush;
  
  
  
  
  
  Index: TestDirectorConnection.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/BugDB/TestDirectorConnection.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDirectorConnection.pm	13 Jan 2008 09:15:22 -0000	1.1
  +++ TestDirectorConnection.pm	21 Feb 2008 02:32:09 -0000	1.2
  @@ -11,7 +11,8 @@
   
   use strict;
   
  -use Win32::OLE;
  +# Optional dependency for people who don't use this module.
  +eval("use Win32::OLE;");
   
   # Static method for building a database connection.
   sub get_connection($) {
  
  
  
  
  
  Index: ScmBug.pm
  ===================================================================
  RCS file: ScmBug.pm
  diff -N ScmBug.pm
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ScmBug.pm	21 Feb 2008 02:32:09 -0000	1.1
  @@ -0,0 +1,151 @@
  +###############################################################################
  +# Codestriker: Copyright (c) 2001,2002,2003 David Sitsky.  All rights reserved.
  +# si...@us...
  +#
  +# This program is free software; you can redistribute it and modify it under
  +# the terms of the GPL.
  +
  +# ScmBug repository access package.
  +
  +package Codestriker::Repository::ScmBug;
  +
  +use strict;
  +
  +# Optional dependencies for people who don't require ScmBug functionality.
  +eval("use XML::Simple");
  +eval("use Scmbug::Connection");
  +eval("use Scmbug::Common");
  +
  +# Create a connection to the ScmBug daemon, and maintain a reference to the
  +# delegate repository.
  +sub new {
  +    my ($type, $hostname, $port, $repository) = @_;
  +    
  +    my $self = {};
  +    $self->{repository} = $repository;
  +    $self->{connection} = Scmbug::Connection->new(0);
  +    $self->{connection}->location($hostname);
  +    $self->{connection}->port($port);
  +
  +    bless $self, $type;
  +}
  +
  +
  +#
  +# Retrieve affected files in XML format from the ScmBug daemon.
  +#
  +sub get_affected_files_XML {
  +    my $self = shift;
  +    my $bugids = shift;
  +
  +    my $new_activity = Scmbug::Activity->new();
  +    $new_activity->{name} = $ScmBug::Common::ACTIVITY_GET_AFFECTED_FILES;
  +    $new_activity->{user} = "codestriker";
  +    
  +    # Comma seperated list of bugs
  +    $new_activity->{bugs} = $bugids;
  +
  +    # Process this tagging activity as well
  +    my $affected_files = $self->{connection}->process_activity($new_activity);
  +
  +    return $affected_files;
  +}
  +
  +#
  +# Convert the XML format to a nice Perl structured format
  +# grouping all the files together
  +#
  +sub convert_from_xml {
  +    my $self = shift;
  +    my $affected_files_xml = shift;
  +    
  +    my $xml = new XML::Simple (NoAttr=>1);
  +    my $raw = $xml->XMLin($affected_files_xml);
  +    
  +    my @changeList = ();
  +    
  +    my $bugid;
  +    foreach $bugid (keys %{$raw}) {
  +    	my $comment_section;
  +    	foreach $comment_section (keys %{$raw->{$bugid}}) {
  +    	    my $file_change;
  +    	    foreach $file_change (keys %{$raw->{$bugid}->{$comment_section}}) {
  +	        my $changeset;
  +	        $changeset->{file} = $raw->{$bugid}->{$comment_section}->{$file_change}->{filename};
  +	        $changeset->{new} = $raw->{$bugid}->{$comment_section}->{$file_change}->{new_version};
  +	        $changeset->{old} = $raw->{$bugid}->{$comment_section}->{$file_change}->{old_version};
  +
  +		# Set the old version for new files to 0
  +		if( "$changeset->{old}" eq "NONE" ) {
  +		    $changeset->{old} = 0;
  +		}
  +		if( "$changeset->{new}" eq "NONE" ) {
  +		    $changeset->{new} = 0;
  +		}
  +		push @changeList, $changeset;
  +    	    }
  +    	}
  +    }
  +    
  +    return \@changeList;
  +}
  +
  +# Retrieve the data corresponding to $filename and $revision.  Store each line
  +# into $content_array_ref.
  +sub retrieve ($$$\$) {
  +    my ($self, $filename, $revision, $content_array_ref) = @_;
  +
  +    $self->{repository}->retrieve($filename, $revision, $content_array_ref);
  +}
  +
  +# Retrieve the "root" of this repository.
  +sub getRoot ($) {
  +    my ($self) = @_;
  +    return $self->{repository}->{repository_url};
  +}
  +
  +# Return a URL which views the specified file and revision.
  +sub getViewUrl ($$$) {
  +    my ($self, $filename, $revision) = @_;
  +
  +    return $self->{repository}->getViewUrl($filename, $revision);
  +}
  +
  +# Return a string representation of this repository.
  +sub toString ($) {
  +    my ($self) = @_;
  +    return $self->{repository}->toString();
  +}
  +
  +# The getDiff operation, pull out a change set based on the bug IDs.
  +sub getDiff {
  +    my ($self, $bugids, $stdout_fh, $stderr_fh, $default_to_head) = @_;
  +
  +    my $affected_files_list =
  +	$self->convert_from_xml($self->get_affected_files_XML($bugids));
  +
  +
  +    foreach my $changeset ( @{ $affected_files_list } ) {
  +	
  +	# Don't diff just directory property changes
  +	if( $changeset->{file} =~ /\/$/ ) {
  +	    next;
  +	}
  +
  +	# Call the delgate repository object for retrieving the actual
  +	# content.
  +	my $old_rev = ($changeset->{old} == 0) ? "" : $changeset->{old};
  +	my $new_rev = ($changeset->{new} == 0) ? "" : $changeset->{new};		
  +	my $ret = $self->{repository}->getDiff($old_rev, $new_rev,
  +					       $changeset->{file},
  +					       $stdout_fh,
  +					       $stderr_fh,
  +					       $default_to_head);
  +	return $ret if $ret != $Codestriker::OK;
  +    }
  +
  +    return $Codestriker::OK;
  +}
  +
  +
  +1;
  
  
  
 | 
| 
      
      
      From: <si...@us...> - 2008-02-22 00:32:11
       | 
|   User: sits    
  Date: 08/02/21 16:32:07
  Modified:    .        codestriker.conf
               bin      codestriker.pl.base install.pl
               lib/Codestriker/Action SubmitNewTopic.pm
               lib/Codestriker/Repository ScmBug.pm
  Log:
  Merged more scmbug-related changes from Rob.
  
  
  
  Index: codestriker.conf
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/codestriker.conf,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- codestriker.conf	21 Feb 2008 02:32:09 -0000	1.91
  +++ codestriker.conf	22 Feb 2008 00:31:55 -0000	1.92
  @@ -404,8 +404,9 @@
   # with source control systems such as subversion.  The following flag
   # enables/disables the ability for a user to create a topic by just
   # using a Bug ID.
  -#$scmbug_hostname = 'hostname-of-scmbug-daemon';
  +#$scmbug_hostname = 'localhost';
   #$scmbug_port = 3872;
  +#$scmbug_lib_dir = 'C:/Program Files/Scmbug/share/scmbug/lib';
   
   # LXR database.  Each repository can be optionally mapped to a
   # different LXR deployment.  If a repository has an associated LXR
  
  
  
  
  
  Index: codestriker.pl.base
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/bin/codestriker.pl.base,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- codestriker.pl.base	24 Sep 2007 22:45:16 -0000	1.24
  +++ codestriker.pl.base	22 Feb 2008 00:32:00 -0000	1.25
  @@ -23,6 +23,7 @@
   # effectively "pre-load" all of the Codestriker modules in the system, as the
   # modules below load all of their supporting modules.  That is why the
   # template plugins are "pre-loaded" here.
  +[% scmbug_lib %]
   [% codestriker_lib %]
   
   use strict;
  
  
  
  
  
  Index: install.pl
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/bin/install.pl,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- install.pl	21 Feb 2008 02:32:09 -0000	1.16
  +++ install.pl	22 Feb 2008 00:32:05 -0000	1.17
  @@ -140,10 +140,11 @@
   
   # Check that the necessary modules are present if ScmBug is used.
   if (defined $Codestriker::scmbug_hostname &&
  -    $Codestriker::scmbug_hostname ne '') {
  -    push @{$modules}, { name => 'XML::Simple', version => '0' };
  -    push @{$modules}, { name => 'ScmBug::Connection', version => '0' };
  -    push @{$modules}, { name => 'ScmBug::Common', version => '0' };
  +    defined $Codestriker::scmbug_lib_dir &&
  +    $Codestriker::scmbug_hostname ne '' &&
  +    $Codestriker::scmbug_lib_dir ne '') {
  +    push @INC, $Codestriker::scmbug_lib_dir;
  +    push @{$modules}, { name => 'ScmBug::ActivityUtilities', version => '0' };
   }
   
   # Check for various character encoding modules that are required.
  @@ -1064,6 +1065,12 @@
       $template_vars->{hash_ex_line} = '#!' . $perl . ' -wT';
   }
   
  +# Check if the Scmbug library location needs to be added
  +if (defined $Codestriker::scmbug_lib_dir &&
  +    $Codestriker::scmbug_lib_dir ne '') {
  +    $template_vars->{scmbug_lib} = 'use lib \'' . $Codestriker::scmbug_lib_dir . '\';';
  +}
  +
   $template_vars->{codestriker_lib} = 'use lib \'' . cwd() . '/../lib\';';
   
   $template_vars->{codestriker_conf} = '\'' . cwd() . '/..\'';
  
  
  
  
  
  Index: SubmitNewTopic.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/SubmitNewTopic.pm,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- SubmitNewTopic.pm	21 Feb 2008 02:32:09 -0000	1.31
  +++ SubmitNewTopic.pm	22 Feb 2008 00:32:05 -0000	1.32
  @@ -56,7 +56,7 @@
       # object.
       my $retrieve_text_from_rep = 0;
       if ((($start_tag ne "" || $end_tag ne "") && $module ne "") ||
  -	(defined $Codestriker::scmbug_host && $Codestriker::scmbug_host ne '' &&
  +	(defined $Codestriker::scmbug_hostname && $Codestriker::scmbug_hostname ne '' &&
   	 $bug_ids ne '')) {
   	$retrieve_text_from_rep = 1;
   
  
  
  
  
  
  Index: ScmBug.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Repository/ScmBug.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScmBug.pm	21 Feb 2008 02:32:09 -0000	1.1
  +++ ScmBug.pm	22 Feb 2008 00:32:07 -0000	1.2
  @@ -12,9 +12,7 @@
   use strict;
   
   # Optional dependencies for people who don't require ScmBug functionality.
  -eval("use XML::Simple");
  -eval("use Scmbug::Connection");
  -eval("use Scmbug::Common");
  +eval("use Scmbug::ActivityUtilities");
   
   # Create a connection to the ScmBug daemon, and maintain a reference to the
   # delegate repository.
  @@ -23,73 +21,12 @@
       
       my $self = {};
       $self->{repository} = $repository;
  -    $self->{connection} = Scmbug::Connection->new(0);
  -    $self->{connection}->location($hostname);
  -    $self->{connection}->port($port);
  +    $self->{scmbug} = Scmbug::ActivityUtilities->new($hostname, $port);
   
       bless $self, $type;
   }
   
   
  -#
  -# Retrieve affected files in XML format from the ScmBug daemon.
  -#
  -sub get_affected_files_XML {
  -    my $self = shift;
  -    my $bugids = shift;
  -
  -    my $new_activity = Scmbug::Activity->new();
  -    $new_activity->{name} = $ScmBug::Common::ACTIVITY_GET_AFFECTED_FILES;
  -    $new_activity->{user} = "codestriker";
  -    
  -    # Comma seperated list of bugs
  -    $new_activity->{bugs} = $bugids;
  -
  -    # Process this tagging activity as well
  -    my $affected_files = $self->{connection}->process_activity($new_activity);
  -
  -    return $affected_files;
  -}
  -
  -#
  -# Convert the XML format to a nice Perl structured format
  -# grouping all the files together
  -#
  -sub convert_from_xml {
  -    my $self = shift;
  -    my $affected_files_xml = shift;
  -    
  -    my $xml = new XML::Simple (NoAttr=>1);
  -    my $raw = $xml->XMLin($affected_files_xml);
  -    
  -    my @changeList = ();
  -    
  -    my $bugid;
  -    foreach $bugid (keys %{$raw}) {
  -    	my $comment_section;
  -    	foreach $comment_section (keys %{$raw->{$bugid}}) {
  -    	    my $file_change;
  -    	    foreach $file_change (keys %{$raw->{$bugid}->{$comment_section}}) {
  -	        my $changeset;
  -	        $changeset->{file} = $raw->{$bugid}->{$comment_section}->{$file_change}->{filename};
  -	        $changeset->{new} = $raw->{$bugid}->{$comment_section}->{$file_change}->{new_version};
  -	        $changeset->{old} = $raw->{$bugid}->{$comment_section}->{$file_change}->{old_version};
  -
  -		# Set the old version for new files to 0
  -		if( "$changeset->{old}" eq "NONE" ) {
  -		    $changeset->{old} = 0;
  -		}
  -		if( "$changeset->{new}" eq "NONE" ) {
  -		    $changeset->{new} = 0;
  -		}
  -		push @changeList, $changeset;
  -    	    }
  -    	}
  -    }
  -    
  -    return \@changeList;
  -}
  -
   # Retrieve the data corresponding to $filename and $revision.  Store each line
   # into $content_array_ref.
   sub retrieve ($$$\$) {
  @@ -121,9 +58,7 @@
   sub getDiff {
       my ($self, $bugids, $stdout_fh, $stderr_fh, $default_to_head) = @_;
   
  -    my $affected_files_list =
  -	$self->convert_from_xml($self->get_affected_files_XML($bugids));
  -
  +    my $affected_files_list = $self->{scmbug}->get_affected_files( $bugids );
   
       foreach my $changeset ( @{ $affected_files_list } ) {
   	
  
  
  
 | 
| 
      
      
      From: <si...@us...> - 2008-07-22 00:57:50
       | 
|   User: sits    
  Date: 08/07/21 17:57:50
  Modified:    .        CHANGELOG
               lib/Codestriker/Repository ScmBug.pm
  Log:
  * Scmbug integration now works correctly if multiple bug IDs are
    specified is the create topic screen.  Fixed by
    rob...@us....
  
  
  
  Index: CHANGELOG
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/CHANGELOG,v
  retrieving revision 1.246
  retrieving revision 1.247
  diff -u -r1.246 -r1.247
  --- CHANGELOG	22 Jul 2008 00:50:44 -0000	1.246
  +++ CHANGELOG	22 Jul 2008 00:57:49 -0000	1.247
  @@ -23,7 +23,11 @@
   * Better detection of filename extensions for highlighting.  This
     previously caused issues for temporary directories which contained 
     a period, but the filename itself didn't.  Reported by
  -  rob...@us....  
  +  rob...@us....
  +  
  +* Scmbug integration now works correctly if multiple bug IDs are
  +  specified is the create topic screen.  Fixed by
  +  rob...@us....
   
   Version 1.9.5
   
  
  
  
  
  
  Index: ScmBug.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Repository/ScmBug.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ScmBug.pm	22 Feb 2008 00:32:07 -0000	1.2
  +++ ScmBug.pm	22 Jul 2008 00:57:49 -0000	1.3
  @@ -58,7 +58,11 @@
   sub getDiff {
       my ($self, $bugids, $stdout_fh, $stderr_fh, $default_to_head) = @_;
   
  -    my $affected_files_list = $self->{scmbug}->get_affected_files( $bugids );
  +    # Remove spaces from the comma-separated list of bug ids so that
  +    # "123, 456" is transformed to "123,456" which is the form
  +    # Scmbug::ActivityUtilities expects.
  +    $bugids =~ s/ //g;
  +    my $affected_files_list = $self->{scmbug}->get_affected_files($bugids);
   
       foreach my $changeset ( @{ $affected_files_list } ) {
   	
  
  
  
 |