From 4f64b1ee9aa3ed7eb1a16c53b3b8f645d088eafe Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Tue, 27 Sep 2011 01:05:23 -0500 Subject: Issue #493074 by boombatower: Back-link to the commit as a comment on the related issue. --- versioncontrol_project.module | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/versioncontrol_project.module b/versioncontrol_project.module index dc8d11e..f7241b7 100644 --- a/versioncontrol_project.module +++ b/versioncontrol_project.module @@ -633,3 +633,41 @@ function versioncontrol_project_commits_page($display_type, $node) { } return versioncontrol_render_commitlog_view($view_name, 'default', array($node->nid), '', $feed_url); } + +/** + * Implementation of hook_versioncontrol_operation(). + */ +function versioncontrol_project_versioncontrol_operation($op, $operation, $operation_items) { + // Look for a commit operation being inserted that has a issue reference in + // the commit message to a valid project issue node. + if ($op == 'insert' && $operation['type'] == VERSIONCONTROL_OPERATION_COMMIT && + preg_match('/#(\d+)/', $operation['message'], $match) && ($node = node_load($match[0])) && $node->type == 'project_issue') { + + // Build project_issue followup changes. + $changes = array( + 'nid' => $node->nid, + 'comment' => array( + '!revision' => $operation['revision'], + '@message' => $operation['message'], + ), + 'sid' => PROJECT_ISSUE_STATE_FIXED, // @TODO Provide per-project setting. + ); + + // If Drupal user is known the format author as a link and post comment as + // the detect user, otherwise format author as the VCS username only without + // any link and post as auto-followup user. + if ($operation['uid']) { + $changes['comment']['!author'] = l($operation['username'], 'user/' . $operation['uid']); + $changes['comment'] = t('Commit !revision by !author: "@message"', $changes['comment']); + + $changes['uid'] = $operation['uid']; + project_issue_add_followup($changes); + } + else { + $changes['comment']['!author'] = $operation['username']; + $changes['comment'] = t('Commit !revision by !author: "@message"', $changes['comment']); + + project_issue_add_auto_followup($changes); + } + } +} -- 1.7.6.3