r94436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94435‎ | r94436 | r94437 >
Date:23:21, 13 August 2011
Author:demon
Status:ok
Tags:
Comment:
Fix up post-commit hooks. I've got a headache so I haven't tested these. Don't worry, I won't deploy them just yet.
Modified paths:
  • /trunk/tools/subversion/hooks/HooksCommon.inc (modified) (history)
  • /trunk/tools/subversion/hooks/post-commit (added) (history)
  • /trunk/tools/subversion/hooks/pre-commit (modified) (history)

Diff [purge]

Index: trunk/tools/subversion/hooks/HooksCommon.inc
@@ -29,6 +29,7 @@
3030
3131 /**
3232 * Tests to run, with their configuration
 33+ * @var array
3334 */
3435 protected $preCommitTests = array(
3536 'testLogMessageLength' => array(
@@ -45,16 +46,31 @@
4647
4748 /**
4849 * Places to ping after a commit has completed (CR, CI, etc)
 50+ * @var array
4951 */
5052 protected $postCommitPings = array(
51 -
 53+ 'notifyMailingList' => array(
 54+ 'mediawiki-cvs@lists.wikimedia.org', /** list **/
 55+ 'lily.knams.wikimedia.org', /** smtp host **/
 56+ ),
 57+ 'notifyIRCBot' => array(
 58+ 'cia_bot.py', /** name of the notifier script **/
 59+ 'mediawiki', /** account name with cia.vc **/
 60+ ),
 61+ 'pingURL' => array(
 62+ 'http://www.mediawiki.org/w/api.php?action=codeupdate&format=xml&repo=MediaWiki&rev=$REV',
 63+ ),
 64+ 'pingURL' => array(
 65+ 'http://ci2.tesla.usability.wikimedia.org:8080/subversion/$UUID/notifyCommit?rev=$REV',
 66+ ),
5267 );
5368
5469 /**
5570 * Class constructor
5671 *
5772 * @param $repo String name of repository
58 - * @param txn
 73+ * @param $txn String on pre-commit, this is a pending transaction, on
 74+ * post-commit, this refers to the committed revision.
5975 */
6076 public function __construct( $repo, $txn ) {
6177 $this->repo = $repo;
@@ -84,6 +100,18 @@
85101 }
86102
87103 /**
 104+ * Run SVN post-commit pings
 105+ *
 106+ * @return int
 107+ */
 108+ public function runPostCommitPings() {
 109+ foreach( $this->postCommitPings as $ping => $params ) {
 110+ call_user_func_array( array( $this, $test ), $params );
 111+ }
 112+ return 0;
 113+ }
 114+
 115+ /**
88116 * Get commit log message
89117 *
90118 * @return string
@@ -112,7 +140,7 @@
113141 *
114142 * @return array filenames are keys and status letters are values
115143 */
116 - protected function getCommitList() {
 144+ private function getCommitList() {
117145 $output = null;
118146 $cmd = "{$this->svnlook} changed -t '{$this->transaction}' '{$this->repo}'";
119147 exec( $cmd, $output );
@@ -133,7 +161,7 @@
134162 * @param $fileTypes array of file types used for filtering
135163 * @return array
136164 */
137 - protected function getChangedFiles( array $fileTypes = array() ) {
 165+ private function getChangedFiles( array $fileTypes = array() ) {
138166 $list = $this->getCommitList();
139167 $files = array();
140168 foreach ( $list as $file => $status ) {
@@ -155,6 +183,18 @@
156184 }
157185
158186 /**
 187+ * Get the repository UUID
 188+ *
 189+ * @return String
 190+ */
 191+ private function getRepoUUID() {
 192+ $output = null;
 193+ $cmd = "{$this->svnlook} uuid '{$this->repo}'";
 194+ exec( $cmd, $output );
 195+ return trim( implode( $output ) );
 196+ }
 197+
 198+ /**
159199 * Check if log message validates length rules
160200 *
161201 * @param $minLength int minimum length of log message
@@ -162,7 +202,7 @@
163203 *
164204 * @return bool
165205 */
166 - protected function testLogMessageLength( $minLength = 1, $regex = '' ) {
 206+ private function testLogMessageLength( $minLength = 1, $regex = '' ) {
167207 $msg = trim( $this->getLogMessage() );
168208 $length = strlen( $msg );
169209 if ( $length < $minLength ) {
@@ -183,7 +223,7 @@
184224 * @param $fileTypes array
185225 * @return bool|string
186226 */
187 - protected function testPHPLint( $fileTypes ) {
 227+ private function testPHPLint( $fileTypes ) {
188228 $output = null;
189229 $result = '';
190230 $changedFiles = $this->getChangedFiles( $fileTypes );
@@ -205,11 +245,50 @@
206246 * @param $badUsers array of bad user names
207247 * @return bool|string
208248 */
209 - protected function testBadUsers( $badUsers ) {
 249+ private function testBadUsers( $badUsers ) {
210250 $ourUser = $this->getAuthor();
211251 if( in_array( $ourUser, $badUsers ) ) {
212252 return "Please do not commit as '{$ourUser}', use your real commit name";
213253 }
214254 return true;
215255 }
 256+
 257+ /**
 258+ * Use svnnotify to notify a mailing list about the commit
 259+ * @param $list String Name of the list
 260+ * @param $smtp String SMTP host to use
 261+ * @todo Make the CR header less hardcoded
 262+ */
 263+ private function notifyMailingList( $list, $smtp, $header = '' ) {
 264+ $cmd = "{$this->svnnotify} --repos-path \"{$this->repo}\" --revision \"{$this->transaction}\""
 265+ . " --to \"{$list}\" --smtp {$smtp} --subject-prefix \"SVN: \""
 266+ . " --subject-cx --no-first-line --with-diff --user-domain \"svn.wikimedia.org\""
 267+ . " --header \"http://www.mediawiki.org/wiki/Special:Code/MediaWiki/{$this->transaction}\""
 268+ . " -l {$this->svnlook}";
 269+ }
 270+
 271+ /**
 272+ * Notify a cia-esque bot about the commit
 273+ * @param $ciaScript String Name of the bot script
 274+ * @param $acctName String Name of the account with cia.vc
 275+ */
 276+ private function notifyIRCBot( $ciaScript, $acctName ) {
 277+ exec( "{$ciaScript} \"{$this->repo}\" \"{$this->transaction}\" \"{$acctName}\"" );
 278+ }
 279+
 280+ /**
 281+ * Submit a POST request to the given URL
 282+ * @param $url String A url to submit revision info to $REV will be replaced
 283+ * with the revision number, and $UUID will become the repo unique identifier
 284+ */
 285+ private function pingURL( $url ) {
 286+ $url = str_replace( array( '$REV', '$UUID' ),
 287+ array( $this->transaction, $this->getRepoUUID() ), $url );
 288+ $ch = curl_init();
 289+ curl_setopt( $ch, CURLOPT_URL,$url );
 290+ curl_setopt( $ch, CURLOPT_POST, true );
 291+ curl_setopt( $ch, CURLOPT_POSTFIELDS, '' );
 292+ curl_exec( $ch );
 293+ curl_close( $ch );
 294+ }
216295 }
Index: trunk/tools/subversion/hooks/post-commit
@@ -0,0 +1,9 @@
 2+#!/usr/bin/php
 3+<?php
 4+
 5+require( "HooksCommon.inc" );
 6+$repo = $argv[1];
 7+$rev = $argv[2];
 8+
 9+$postCommit = new CommitInfo( $repo, $rev );
 10+exit( $postCommit->runPostCommitPings() );
Property changes on: trunk/tools/subversion/hooks/post-commit
___________________________________________________________________
Added: svn:eol-style
111 + native
Property changes on: trunk/tools/subversion/hooks/pre-commit
___________________________________________________________________
Added: svn:eol-style
212 + native

Status & tagging log