Exemplo n.º 1
0
 /**
  *
  * @todo poll only new revisions and append to changelogfile (extend GDO or modulevar?)
  *  if GDO: repository url dynamically
  * @todo add to WC Cronjob
  * @todo rename
  * @author spaceone
  */
 public static function main()
 {
     $svn = new GWF_SvnInfo();
     $svn->setRepository('https://svn.gwf3.gizmore.org/GWF3');
     $startrev = 422;
     //292;
     $logs = $svn->getLog($startrev, $svn->getCurrentRevision());
     # Known users and their WeChall profiles
     $users = array('spaceone' => 'space', 'gizmore' => 'Gizmore');
     $back = '';
     foreach ($logs as $log) {
         $comment = $log['comment'];
         $thx = '';
         if (Common::startsWith($comment, 'WC') || false !== strpos(strtolower($comment), 'wechall')) {
             # TODO: GWF_Date::toString
             if (0 < preg_match_all('/\\(\\s*?thx +([^\\)]+)\\)/', $comment, $matches)) {
                 foreach ($matches[1] as $match) {
                     foreach (preg_split('/[\\s,;]+/', $match) as $username) {
                         $username = htmlspecialchars(trim($username));
                         $username = isset($users[$username]) ? $users[$username] : $username;
                         $thx .= sprintf('<a title="%s" href="%sprofile/%s">%s</a>' . PHP_EOL, $username, GWF_WEB_ROOT, $username);
                     }
                 }
             }
             # TODO: HTML formatting
             $creator = isset($users[$log['creator-displayname']]) ? $users[$log['creator-displayname']] : $log['creator-displayname'];
             $pattern = 'Revision: %s; by <a href="%s/profile/%s">%s</a>; on %s;' . PHP_EOL . '  %s' . PHP_EOL . '%s' . PHP_EOL;
             $back .= sprintf($pattern, $log['version-name'], GWF_WEB_ROOT, $creator, $creator, $log['date'], str_replace("\n", "\n  ", $comment), $thx);
         }
     }
     if (false === file_put_contents(GWF_WWW_PATH . self::$outfile, $back)) {
         # TODO
     }
 }
Exemplo n.º 2
0
function dog_svn_info($key, $repo, $user = '', $pass = '', $displayurl = '', $channels = array())
{
    $keyshort = $key;
    $key = 'DOG_SVNINFO_REVISION_' . $key;
    $svninfo = new GWF_SvnInfo();
    $svninfo->setRepository($repo, $user, $pass);
    if (0 == ($currentRevision = $svninfo->getCurrentRevision())) {
        return Dog_Log::debug('Fetching current revision failed.');
    }
    $lastRevision = GWF_Settings::getSetting($key, $currentRevision);
    if ($currentRevision <= $lastRevision) {
        GWF_Settings::setSetting($key, $currentRevision);
        return;
    }
    $svnlog = $svninfo->getLog($lastRevision + 1, $currentRevision);
    foreach ($svnlog as $entry) {
        $msg = sprintf('[%s] New revision %s by %s: %s', $keyshort, $entry['version-name'], $entry['creator-displayname'], html_entity_decode($entry['comment']));
        if ($displayurl != '') {
            $msg .= ' ( ' . str_replace('%REV%', $entry['version-name'], $displayurl) . ' )';
        }
        if (count($channels) === 0) {
            # To all servers in the main channel
            foreach (DOG::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels = $server->getChannels();
                if (count($channels) > 0) {
                    $channel = array_shift($channels);
                    $channel = $channel->getVar('chan_name');
                    $server->sendPRIVMSG($channel, $msg);
                }
            }
        } else {
            # To all servers in matching channels
            foreach (DOG::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels_now = $server->getChannels();
                foreach ($channels_now as $channel) {
                    $channel instanceof Dog_Channel;
                    $channel = $channel->getName();
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
    }
    GWF_Settings::setSetting($key, $currentRevision);
}