mantis整合svn续:把提交的所有信息自动保存为note

60 篇文章 0 订阅
4 篇文章 0 订阅

http://blog.csdn.net/newjueqi/article/details/7828432

在前面两篇转载的文章中,介绍了mantis和svn的整合

http://blog.csdn.net/newjueqi/article/details/7785373

http://blog.csdn.net/newjueqi/article/details/7785382


但有这样一个需求:在提交svn后,mantis能把提交的所有信息自动保存为note(用"bug #0001" 和 “fixed bug #0001” 两种格式的记录都能提交note)

在mantis的源码中没法实现,于是研究了一下mantis的源码,最终实现了这个功能:


我把代码放在github上 https://github.com/newjueqi/source-integration


效果如图所示:



具体的实现 https://github.com/newjueqi/source-integration/blob/master/Source/Source.API.php Source_Process_Changesets()


  1. # Parse note bug links  
  2. $t_note_bugs = array();   
  3.   
  4. # Find and associate resolve links with the changeset  
  5. foreach$p_changesets as $t_changeset ) {  
  6.     $t_bugs = Source_Parse_Buglinks( $t_changeset->message );  
  7.   
  8.     foreach$t_bugs as $t_bug_id ) {  
  9.         $t_note_bugs$t_bug_id ] = $t_changeset;  
  10.     }  
  11.   
  12.     # Add the link to the normal set of buglinks  
  13.     $t_changeset->bugs = array_uniquearray_merge$t_changeset->bugs, $t_bugs ) );  
  14. }  
	# Parse note bug links
	$t_note_bugs = array();	
	
	# Find and associate resolve links with the changeset
	foreach( $p_changesets as $t_changeset ) {
		$t_bugs = Source_Parse_Buglinks( $t_changeset->message );

		foreach( $t_bugs as $t_bug_id ) {
			$t_note_bugs[ $t_bug_id ] = $t_changeset;
		}

		# Add the link to the normal set of buglinks
		$t_changeset->bugs = array_unique( array_merge( $t_changeset->bugs, $t_bugs ) );
	}


把修改放在note上


  1.   
  2. # Start add note for  issues  
  3. foreach$t_note_bugs as $t_bug_id => $t_changeset ) {  
  4.   
  5.     # make sure the bug exists before processing  
  6.     if ( !bug_exists( $t_bug_id ) ) {  
  7.         continue;  
  8.     }  
  9.   
  10.     # fake the history entries as the committer/author user ID  
  11.     $t_user_id = null;  
  12.     if ( $t_changeset->committer_id > 0 ) {  
  13.         $t_user_id = $t_changeset->committer_id;  
  14.     } else if ( $t_changeset->user_id > 0 ) {  
  15.         $t_user_id = $t_changeset->user_id;  
  16.     }  
  17.   
  18.     if ( !is_null$t_user_id ) ) {  
  19.         $g_cache_current_user_id = $t_user_id;  
  20.     } else if ( !is_null$t_current_user_id ) ) {  
  21.         $g_cache_current_user_id = $t_current_user_id;  
  22.     } else {  
  23.         $g_cache_current_user_id = 0;  
  24.     }  
  25.   
  26.     # generate the branch mappings  
  27.     $t_version = '';  
  28.     $t_pvm_version_id = 0;  
  29.     if ( $t_enable_mapping ) {  
  30.         $t_repo_id = $t_changeset->repo_id;  
  31.   
  32.         if ( !isset( $t_mappings$t_repo_id ] ) ) {  
  33.             $t_mappings$t_repo_id ] = SourceMapping::load_by_repo( $t_repo_id );  
  34.         }  
  35.   
  36.         if ( isset( $t_mappings$t_repo_id ][ $t_changeset->branch ] ) ) {  
  37.             $t_mapping = $t_mappings$t_repo_id ][ $t_changeset->branch ];  
  38.             if ( Source_PVM() ) {  
  39.                 $t_pvm_version_id = $t_mapping->apply_pvm( $t_bug_id );  
  40.             } else {  
  41.                 $t_version = $t_mapping->apply( $t_bug_id );  
  42.             }  
  43.         }  
  44.     }  
  45.   
  46.     # generate a note message  
  47.     if ( $t_enable_message ) {  
  48.           
  49.             $changelog = "";  
  50.             foreach($t_changeset->files as $file) {  
  51.                 switch($file->action) {  
  52.                     case 'add'$changelog.='A'break;  
  53.                     case 'rm' : $changelog.='D'break;  
  54.                     case 'mod'$changelog.='M'break;  
  55.                     case 'mv' : $changelog.='R'break;  
  56.                     default   : $changelog.='C'break;  
  57.                 }  
  58.                 $changelog.="    ".$file->filename.'<br/>';  
  59.             }  
  60.             $t_message = sprintf( $t_message_template$t_changeset->branch, $t_changeset->revision, $t_changeset->timestamp, $t_changeset->message, $t_repos$t_changeset->repo_id ]->name, $t_changeset->id, $t_changeset->author, $changelog );       
  61.       
  62.     } else {  
  63.         $t_message = '';  
  64.     }  
  65.   
  66.     $t_bug = bug_get( $t_bug_id );  
  67.   
  68.     bugnote_add( $t_bug_id$t_message );  
  69.       
  70. }     
	
	# Start add note for  issues
	foreach( $t_note_bugs as $t_bug_id => $t_changeset ) {

		# make sure the bug exists before processing
		if ( !bug_exists( $t_bug_id ) ) {
			continue;
		}

		# fake the history entries as the committer/author user ID
		$t_user_id = null;
		if ( $t_changeset->committer_id > 0 ) {
			$t_user_id = $t_changeset->committer_id;
		} else if ( $t_changeset->user_id > 0 ) {
			$t_user_id = $t_changeset->user_id;
		}

		if ( !is_null( $t_user_id ) ) {
			$g_cache_current_user_id = $t_user_id;
		} else if ( !is_null( $t_current_user_id ) ) {
			$g_cache_current_user_id = $t_current_user_id;
		} else {
			$g_cache_current_user_id = 0;
		}

		# generate the branch mappings
		$t_version = '';
		$t_pvm_version_id = 0;
		if ( $t_enable_mapping ) {
			$t_repo_id = $t_changeset->repo_id;

			if ( !isset( $t_mappings[ $t_repo_id ] ) ) {
				$t_mappings[ $t_repo_id ] = SourceMapping::load_by_repo( $t_repo_id );
			}

			if ( isset( $t_mappings[ $t_repo_id ][ $t_changeset->branch ] ) ) {
				$t_mapping = $t_mappings[ $t_repo_id ][ $t_changeset->branch ];
				if ( Source_PVM() ) {
					$t_pvm_version_id = $t_mapping->apply_pvm( $t_bug_id );
				} else {
					$t_version = $t_mapping->apply( $t_bug_id );
				}
			}
		}

		# generate a note message
		if ( $t_enable_message ) {
			
             $changelog = "";
             foreach($t_changeset->files as $file) {
                 switch($file->action) {
                     case 'add': $changelog.='A'; break;
                     case 'rm' : $changelog.='D'; break;
                     case 'mod': $changelog.='M'; break;
                     case 'mv' : $changelog.='R'; break;
                     default   : $changelog.='C'; break;
                 }
                 $changelog.="    ".$file->filename.'<br/>';
             }
 			$t_message = sprintf( $t_message_template, $t_changeset->branch, $t_changeset->revision, $t_changeset->timestamp, $t_changeset->message, $t_repos[ $t_changeset->repo_id ]->name, $t_changeset->id, $t_changeset->author, $changelog );		
		
		} else {
			$t_message = '';
		}

		$t_bug = bug_get( $t_bug_id );

		bugnote_add( $t_bug_id, $t_message );
		
	}	


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值