From 97641cafbb349708b2b9d46976d465dfca75244c Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Wed, 28 Sep 2011 00:44:25 -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, 37 insertions(+), 1 deletions(-) diff --git a/versioncontrol_project.module b/versioncontrol_project.module index dc8d11e..22b2dea 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,42 @@ 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+)/', $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, + ); + $placeholders = array( + '!revision' => $operation->formatRevisionIdentifier('short'), // @TODO Need to print link, assume helper function? + '@labels' => implode(', ', $operation->labels), // @TODO Need to access ->name, possibly an existing helper function? + '@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 username without a link and post as the auto-followup user. + if ($operation->committer_uid) { + $placeholders['!committer'] = l($operation->committer, 'user/' . $operation->committer_uid); + $changes['comment'] = t('Commit !revision on @labels 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