From 41f0ed29145c43c99167472a4ff58b367ef08ca1 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Wed, 28 Sep 2011 00:50:05 -0500 Subject: [PATCH] Issue #493074 by boombatower, marvil07 | dww: Back-link to the commit as a comment on the related issue. --- versioncontrol_project.module | 55 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 54 insertions(+), 1 deletions(-) diff --git a/versioncontrol_project.module b/versioncontrol_project.module index dc8d11e..18155e8 100644 --- a/versioncontrol_project.module +++ b/versioncontrol_project.module @@ -499,7 +499,7 @@ function versioncontrol_project_get_project_maintainers($repo_id) { * TODO This should be moved to be tied to hooks notifying that history syncs * are happening, rather than the individual entity insert. */ -function versioncontrol_project_versioncontrol_entity_commit_insert($operation) { +function versioncontrol_project_versioncontrol_entity_commit_insert(VersioncontrolOperation $operation) { if (isset($operation->repo_id)) { // invalidate block cache for maintainers block $project = versioncontrol_project_project_load($operation->repo_id); @@ -508,6 +508,59 @@ function versioncontrol_project_versioncontrol_entity_commit_insert($operation) _versioncontrol_project_block_cache_set($cid, NULL); } } + + // Look for a commit operation being inserted that has an issue reference in + // the commit message to a valid project issue node. + if ($operation->type == VERSIONCONTROL_OPERATION_COMMIT && preg_match_all('/#(\d+)\b/', $operation->message, $matches, PREG_SET_ORDER)) { + // Allow for multiple issue references to be made in a single commit. + foreach ($matches as $match) { + if (($node = node_load($match[1])) && $node->type == 'project_issue') { + // Build project_issue followup changes and t() parameters for comment. + $changes = array( + 'nid' => $node->nid, + ); + $url_handler = $operation->repository->getUrlHandler(); + $label_names = array(); + foreach ($operation->labels as $label) { + $label_names = $label->name; + } + $placeholders = array( + '!revision' => $url_handler->getCommitViewUrl($operation->revision), + '@labels' => implode(', ', $label_names), + '@message' => $operation->message, + ); + + // If the Drupal user is known then format the author as a link and post + // the comment as the detected user. Otherwise format the author as the + // VCS committer without a link and post as the auto-followup user. + if ($operation->committer_uid) { + $committer = new stdClass(); + $committer->uid = $operation->committer_uid; + $committer->name = check_plain($operation->committer); + $placeholders['!committer'] = theme('username', $committer); + if ($operation->author_uid == $operation->committer_uid) { + $changes['comment'] = t('Commit !revision on @labels by !committer:
@message
', $placeholders); + } + else { + $author = new stdClass(); + $author->uid = $operation->author_uid; + $author->name = check_plain($operation->author); + $placeholders['!author'] = theme('username', $author); + $changes['comment'] = t('Commit !revision on @labels authored by !author, committed by !committer:
@message
', $placeholders); + } + + $changes['uid'] = $operation->committer_uid; + project_issue_add_followup($changes); + } + else { + $placeholders['!committer'] = $operation->committer; + $changes['comment'] = t('Commit !revision on @labels by !committer:
@message
"', $placeholders); + + project_issue_add_auto_followup($changes); + } + } + } + } } /** -- 1.7.6.3