This file is indexed.

/usr/bin/whups-git-hook is in php-horde-whups 3.0.9-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/php
<?php
/**
 * This script scans commit logs for ticket numbers denoted by a flexible
 * regular expression and post the log message and a link to the changeset diff
 * in a comment to those tickets.
 *
 * Usage: whups-git-hook PATH_TO_REPO REVISION
 *
 * @category Horde
 * @package  maintainer_tools
 */

require_once 'Horde/Autoloader/Default.php';


/**
 ** Initialize expected values to rule out pre-existing input by any
 ** means, then include our configuration file.
 **/

$git = $rpc_endpoint = $rpc_method = null;
$rpc_options = array();

require __DIR__ . '/commit-update-tickets-conf.php';


/**
 ** Sanity checks
 **/

if (!is_executable($git)) {
    abort("Required program $git is not executable.");
}

if (is_null($rpc_endpoint) || is_null($rpc_method)) {
    abort("Required XML-RPC configuration is missing or incomplete.");
}

if (count($_SERVER['argv']) < 4) {
    usage();
}


/**
 ** Command-line parsing
 **/

array_shift($_SERVER['argv']);
$repo = array_shift($_SERVER['argv']);
$rev = array_shift($_SERVER['argv']);
$links = implode("\n", $_SERVER['argv']);

if (!file_exists($repo)) {
    abort("Repository $repo does not exist.");
}

if (!is_dir($repo)) {
    abort("Repository $repo is not a directory.");
}


/**
 ** Read the log message for this revision
 **/

// Run git show to get the log message for this revision
$log_message = shell_exec(implode(' ', array(
    escapeshellcmd($git),
    '--git-dir=' . escapeshellarg($repo),
    'show',
    '--summary',
    '--pretty=format:%s%n%b',
    escapeshellarg($rev)
)));

if (!empty($log_message)) {
    $tickets = find_tickets($log_message);
    $kolab_tickets = find_kolab_tickets($log_message);

    foreach ($kolab_tickets as $ticket) {
        $log_message .= "\nThis ticket also references kolab issue: http://issues.kolab.org/issue$ticket\n\n";
    }

    if (count($tickets)) {
        $log_message = "Changes have been made in Git for this ticket:\n\n$log_message$links";
        foreach ($tickets as $ticket) {
            post_comment($ticket, $log_message);
        }
    }
}

exit(0);


/**
 ** Functions
 **/

function abort($msg) {
    fputs(STDERR, $msg . "\n");
    exit(1);
}

function usage() {
    abort("usage: commit-update-tickets.php PATH_TO_REPO REVISION LINKS");
}

function find_tickets($log_message) {
    preg_match_all('/(?:(?<!kolab\/)(?:bug|ticket|request|enhancement|issue):?\s*#?|#)(\d+)/i', $log_message, $matches);
    return array_unique($matches[1]);
}

/**
 * Locate kolab tickets with kolab/issue1234
 */
function find_kolab_tickets($log_message) {
    preg_match_all('/(?:(?:kolab\/issue))(\d+)/i', $log_message, $matches);
    return array_unique($matches[1]);
}

function post_comment($ticket, $log_message) {
    $http = new Horde_Http_Client($GLOBALS['rpc_options']);
    try {
        $result = Horde_Rpc::request(
            'xmlrpc',
            $GLOBALS['rpc_endpoint'],
            $GLOBALS['rpc_method'],
            $http,
            array((int)$ticket, $log_message));
    } catch (Horde_Http_Exception $e) {
        abort($e->getMessage());
    }

    return true;
}