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

来源:互联网 发布:linux jdk 中没有jre 编辑:程序博客网 时间:2024/06/07 03:02

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()


[php] view plaincopyprint?
  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. }  


把修改放在note上


[php] view plaincopyprint?
  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. }