/[drupal]/contributions/modules/versioncontrol_project/versioncontrol_project.metrics.inc
ViewVC logotype

Contents of /contributions/modules/versioncontrol_project/versioncontrol_project.metrics.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Fri Jan 2 21:29:37 2009 UTC (10 months, 3 weeks ago) by jpetso
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC1, DRUPAL-6--1-0-RC2, DRUPAL-6--1-0-BETA2, DRUPAL-6--1-0-BETA1, HEAD
Changes since 1.4: +2 -1 lines
File MIME type: text/x-php
Update copyright headers. 2008 is now fully wrapped up.
1 <?php
2 // $Id: versioncontrol_project.metrics.inc,v 1.4 2009/01/02 19:19:45 jpetso Exp $
3 /**
4 * @file
5 * Version Control / Project Node Integration - Integrates project nodes
6 * (provided by the Project module) with version control systems supported
7 * by the Version Control API.
8 *
9 * This file integrates versioncontrol_project with the metrics module,
10 * providing node metrics based on VCS data.
11 *
12 * Copyright 2007 by Peter Cawley ("corsix", http://drupal.org/user/210422)
13 * Copyright 2008 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
14 */
15
16 function versioncontrol_project_metrics_functions() {
17 return array(
18 'versioncontrol_project_lines_changed',
19 );
20 }
21
22 function versioncontrol_project_lines_changed($op, $options = NULL, $node = NULL) {
23 switch ($op) {
24 case 'info':
25 return array(
26 'name' => t('Version Control: Total lines changed'),
27 'description' => t("Returns the number of lines that were changed in the project's VCS commits in the last week"),
28 );
29
30 case 'compute':
31 // Before doing anything, check if we can return commit statistics at all.
32 if (isset($node->versioncontrol_project)) {
33 $repo_id = $node->versioncontrol_project['repo_id'];
34 }
35 if (!isset($repo_id) || $repo_id == 0)) {
36 $error_message = t('Version control support is not enabled for this node.');
37 }
38 else {
39 $repository = versioncontrol_get_repository($repo_id);
40 if (!isset($repository)) {
41 $error_message = t('Repository with repository id !id not found.',
42 array('!id' => $repo_id));
43 }
44 }
45
46 if (isset($error_message)) {
47 return array(
48 'value' => 0,
49 'description' => $error_message,
50 );
51 }
52
53 // Ok, we can do it... let's get those line counts.
54 $constraints = array(
55 'date_lower' => time() - (60 * 60 * 24 * 7),
56 );
57 $constraints = versioncontrol_project_get_operation_constraints(
58 $constraints, array('nids' => array($node->nid))
59 );
60 $commit_operations = versioncontrol_get_commit_operations($constraints);
61 $count = 0;
62 foreach ($commit_operations as $key => $commit_operation) {
63 $operation_items = versioncontrol_get_operation_items($commit_operation, TRUE);
64 foreach ($operation_items as $path => $item) {
65 $count += $item['line_changes']['added'];
66 $count += $item['line_changes']['removed'];
67 }
68 }
69
70 return array(
71 'value' => $count,
72 'description' => format_plural($count, '1 line of code changed.', '@count lines of code changed.'),
73 );
74
75 case 'options':
76 return array();
77 }
78 }

  ViewVC Help
Powered by ViewVC 1.1.2