{"thread":{"id":"27556","subject":"New CIA.vc script","startedAt":"2011-06-06T10:36:33Z","lastAt":"2011-06-08T13:20:21Z","messageCount":2,"participants":["JD Horelick","Ramkumar Ramachandra"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"169358","messageId":"BANLkTi=_nXGOcqC1PMLFJfgkdx8HbsweEg@mail.gmail.com","threadId":"27556","inReplyTo":null,"subject":"New CIA.vc script","fromName":"JD Horelick","fromEmail":"jdhore1@gmail.com","sentAt":"2011-06-06T10:36:33Z","receivedAt":"2011-06-06T10:36:33Z","isPatch":false,"sender":{"key":"jdhore1@gmail.com","avatar":null},"body":"Hello all,\n\nI'm apologizing in advance if this email is formatted badly or done\nwrong. I'm not really a mailing list guy.\nI recently decided to take the ciabot.pl script for Git and improve\nupon it and now I am submitting it for inclusion in upstream Git.\n\nI decided to use the Perl version for many reasons including: I know\nPerl better than I know Python, Git seems more Perl-centric to me and\nthe Perl script was already closest to what I needed.\n\nHere are the things this script does better than any other CIA.vc\nclient script implementations i've seen for Git:\n1. It can use both RPC and email for sending commit notifications to\nCIA.vc. The Python and Shell versions only use email, which has been\ndeprecated by CIA.vc for a long while.\n2. It uses Git's config system for storing the options that will\nchange on a per-project basis if the script is running on a central\nhost.\n3. It has support for the \"module\" variable allowing (for example) a\nseperate plugins repository to go to the same project page as the main\nrepository, just prefixed with plugins (or whatever) so it's\ndiscernable. If it is empty, no module variable is sent to CIA.\n\nI'm attaching the new ciabot.pl inline here:\n\n#!/usr/bin/perl -w\n#\n# ciabot -- Mail a git log message to a given address, for the purposes of CIA\n#\n# Loosely based on cvslog by Russ Allbery <rra@stanford.edu>\n# Copyright 1998  Board of Trustees, Leland Stanford Jr. University\n#\n# Copyright 2001, 2003, 2004, 2005  Petr Baudis <pasky@ucw.cz>\n# Copyright 2011 JD Horelick <jdhore1@gmail.com>\n#\n# This program is free software; you can redistribute it and/or modify it under\n# the terms of the GNU General Public License version 2, as published by the\n# Free Software Foundation.\n#\n# The master location of this file is in the Cogito repository\n# (see http://www.kernel.org/git/).\n#\n# This program is designed to run as the .git/hooks/post-commit hook. It takes\n# the commit information, massages it and mails it to the address given below.\n#\n# The calling convention of the post-commit hook is:\n#\n#    .git/hooks/post-commit $commit_sha1 $branch_name\n#\n# If it does not work, try to disable $xml_rpc in the configuration section\n# below. Also, remember to make the hook file executable.\n#\n#\n# Note that you can (and it might be actually more desirable) also use this\n# script as the GIT update hook:\n#\n#    refname=${1#refs/heads/}\n#    [ \"$refname\" = \"master\" ] && refname=\n#    oldhead=$2\n#    newhead=$3\n#    for merged in $(git rev-list $newhead ^$oldhead | tac); do\n#        /path/to/ciabot.pl $merged $refname\n#    done\n#\n# This is useful when you use a remote repository that you only push to. The\n# update hook will be triggered each time you push into that repository, and\n# the pushed commits will be reported through CIA.\n# This script no longer TinyURL's the link to gitweb as the link will be\n# short enough anyway as it's sent on its own line\n\nuse strict;\nuse Carp;\nuse vars qw ($project $module $repo $baseurl $from_email $dest_email\n$noisy $rpc_uri $sendmail\n        $xml_rpc $ignore_regexp $alt_local_message_target);\n\n\n### Configuration\n\n# Project name (as known to CIA).\nchomp($project = `git config --get cia.project`);\n\n# Module name (if applicable)\nchomp($module = `git config --get cia.module`);\n\n# Repository name in the web interface\nchomp($repo = `git config --get cia.repo`);\n\n# Base URL for a GitWeb or cgit instance\n# You must comment all the baseurl lines out if you do not have a web interface\n# or do not want the web interface URL for the commit displayed\n# Gitweb\n#$baseurl = \"http://git.example.com/cgi-bin/gitweb.cgi?p=$repo;a=commit;h=\";\n# cgit\n#$baseurl = \"http://git.example.com/$repo/commit/?id=\";\n\n# The from address in generated mails.\n$from_email = 'cia@example.com';\n\n# Mail all reports to this address.\n$dest_email = 'cia@cia.vc';\n\n# If using XML-RPC, connect to this URI.\n$rpc_uri = 'http://cia.vc/RPC2';\n\n# Path to your USCD sendmail compatible binary (your mailer daemon created this\n# program somewhere).\n$sendmail = '/usr/sbin/sendmail';\n\n# If set, the script will send CIA the full commit message. If unset, only the\n# first line of the commit message will be sent.\n$noisy = 1;\n\n# This script can communicate with CIA either by mail or by an XML-RPC\n# interface. The XML-RPC interface is faster and more efficient, however you\n# need to have RPC::XML perl module installed, and some large CVS hosting sites\n# (like Savannah or Sourceforge) might not allow outgoing HTTP connections\n# while they allow outgoing mail. Also, this script will hang and eventually\n# not deliver the event at all if CIA server happens to be down, which is\n# unfortunately not an uncommon condition.\n$xml_rpc = 1;\n\n# This variable should contain a regexp, against which each file will be\n# checked, and if the regexp is matched, the file is ignored. This can be\n# useful if you do not want auto-updated files, such as e.g. ChangeLog, to\n# appear via CIA.\n#\n# The following example will make the script ignore all changes in two specific\n# files in two different modules, and everything concerning module 'admin':\n#\n# $ignore_regexp = \"^(gentoo/Manifest|elinks/src/bfu/inphist.c|admin/)\";\n$ignore_regexp = \"\";\n\n# It can be useful to also grab the generated XML message by some other\n# programs and e.g. autogenerate some content based on it. Here you can specify\n# a file to which it will be appended.\n$alt_local_message_target = \"\";\n\n\n\n\n### The code itself\n\nuse vars qw ($commit $tree @parent $author $committer);\nuse vars qw ($user $branch $rev @files $logmsg $message $shorturl);\nmy $line;\n\nif ($project eq \"\") {\n    croak \"Project variable is required. Please set one with git\nconfig --add cia.project\";\n}\n\nif ($repo eq \"\") {\n    undef $baseurl;\n}\n\n# Let's be extra-safe here\nif ($module eq \"\") {\n    undef $module;\n}\n\n\n### Input data loading\n\n\n# The commit stuff\n$commit = $ARGV[0];\n$branch = $ARGV[1];\n\nopen COMMIT, \"git cat-file commit $commit|\" or die \"git cat-file\ncommit $commit: $!\";\nmy $state = 0;\n$logmsg = '';\nwhile (defined ($line = <COMMIT>)) {\n  if ($state == 1) {\n    $logmsg .= $line;\n    $noisy or $state++;\n    next;\n  } elsif ($state > 1) {\n    next;\n  }\n\n  chomp $line;\n  unless ($line) {\n    $state = 1;\n    next;\n  }\n\n  my ($key, $value) = split(/ /, $line, 2);\n  if ($key eq 'tree') {\n    $tree = $value;\n  } elsif ($key eq 'parent') {\n    push(@parent, $value);\n  } elsif ($key eq 'author') {\n    $author = $value;\n  } elsif ($key eq 'committer') {\n    $committer = $value;\n  }\n}\nclose COMMIT;\n\n\nopen DIFF, \"git diff-tree -r $parent[0] $tree|\" or die \"git diff-tree\n$parent[0] $tree: $!\";\nwhile (defined ($line = <DIFF>)) {\n  chomp $line;\n  my @f;\n  (undef, @f) = split(/\\t/, $line, 2);\n  push (@files, @f);\n}\nclose DIFF;\n\n\n# Figure out who is doing the update.\n# XXX: Too trivial this way?\n($user) = $author =~ /<(.*?)@/;\n\n\n$rev = substr($commit, 0, 12);\n\n\n\n\n### Remove to-be-ignored files\n\n@files = grep { $_ !~ m/$ignore_regexp/; } @files\n  if ($ignore_regexp);\nexit unless @files;\n\n\n\n### Compose the mail message\n\n\nmy ($VERSION) = '2.0';\nmy $ts = time;\n\n$message = <<EM\n<message>\n   <generator>\n       <name>CIA Perl client for Git</name>\n       <version>$VERSION</version>\n   </generator>\n   <source>\n       <project>$project</project>\n\nEM\n;\n$message .= \"       <module>$module</module>\" if ($module);\n$message .= \"       <branch>$branch</branch>\" if ($branch);\n$message .= <<EM\n   </source>\n   <timestamp>\n       $ts\n   </timestamp>\n   <body>\n       <commit>\n           <author>$user</author>\n           <revision>$rev</revision>\n           <files>\nEM\n;\n\nforeach (@files) {\n  s/&/&amp;/g;\n  s/</&lt;/g;\n  s/>/&gt;/g;\n  $message .= \"  <file>$_</file>\\n\";\n}\n\n$logmsg =~ s/&/&amp;/g;\n$logmsg =~ s/</&lt;/g;\n$logmsg =~ s/>/&gt;/g;\n\nif (defined $baseurl) {\n    $shorturl = $baseurl . $rev;\n    $logmsg = $logmsg . $shorturl;\n}\n\n$message .= <<EM\n           </files>\n    <log>$logmsg</log>\n       </commit>\n   </body>\n</message>\nEM\n;\n\n\n\n### Write the message to an alt-target\n\nif ($alt_local_message_target and open (ALT, \">>$alt_local_message_target\")) {\n  print ALT $message;\n  close ALT;\n}\n\n\n\n### Send out the XML-RPC message\n\n\nif ($xml_rpc) {\n  # We gotta be careful from now on. We silence all the warnings because\n  # RPC::XML code is crappy and works with undefs etc.\n  $^W = 0;\n  $RPC::XML::ERROR if (0); # silence perl's compile-time warning\n\n  require RPC::XML;\n  require RPC::XML::Client;\n\n  my $rpc_client = new RPC::XML::Client $rpc_uri;\n  my $rpc_request = RPC::XML::request->new('hub.deliver', $message);\n  my $rpc_response = $rpc_client->send_request($rpc_request);\n\n  unless (ref $rpc_response) {\n    die \"XML-RPC Error: $RPC::XML::ERROR\\n\";\n  }\n  exit;\n}\n\n\n\n### Send out the mail\n\n\n# Open our mail program\n\nopen (MAIL, \"| $sendmail -t -oi -oem\") or die \"Cannot execute\n$sendmail : \" . ($?>>8);\n\n\n# The mail header\n\nprint MAIL <<EOM;\nFrom: $from_email\nTo: $dest_email\nContent-type: text/xml\nSubject: DeliverXML\n\nEOM\n\nprint MAIL $message;\n\n\n# Close the mail\n\nclose MAIL;\ndie \"$0: sendmail exit status \" . ($? >> 8) . \"\\n\" unless ($? == 0);\n\n# vi: set sw=2:\n\n\nI welcome any constructive criticism and I hope to see this in\ncontrib/ciabot soon. :)\n\nThanks\nJD\n"},{"id":"169608","messageId":"BANLkTi=PiAa7-OoW6UtTqidk8ut0P8ewyw@mail.gmail.com","threadId":"27556","inReplyTo":"BANLkTi=_nXGOcqC1PMLFJfgkdx8HbsweEg@mail.gmail.com","subject":"Re: New CIA.vc script","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-06-08T13:20:21Z","receivedAt":"2011-06-08T13:20:21Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJD Horelick writes:\n> I'm attaching the new ciabot.pl inline here:\n[...]\n\n> I welcome any constructive criticism and I hope to see this in\n> contrib/ciabot soon. :)\n\nThanks.  I haven't read the patch yet, but you must read\nDocumentation/SubmittingPatches if this is to be considered for\ninclusion.  The key points are: commit this script to the appropriate\nplace, include a signoff in the commit message, and use `git\nformat-patch` to generate an email to send to the list.\n\n-- Ram\n"}]}