您的位置:首页 > 其它

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

2013-06-05 16:30 375 查看
/article/1606224.html

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

/article/1606228.html

/article/1606227.html

但有这样一个需求:在提交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?

# 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 ) );
}

# 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上

[php]
view plaincopyprint?

# 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 );

}

# 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 );

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐