Index: trunk/tools/subversion/hooks/HooksCommon.inc |
— | — | @@ -29,6 +29,7 @@ |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Tests to run, with their configuration |
| 33 | + * @var array |
33 | 34 | */ |
34 | 35 | protected $preCommitTests = array( |
35 | 36 | 'testLogMessageLength' => array( |
— | — | @@ -45,16 +46,31 @@ |
46 | 47 | |
47 | 48 | /** |
48 | 49 | * Places to ping after a commit has completed (CR, CI, etc) |
| 50 | + * @var array |
49 | 51 | */ |
50 | 52 | 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 | + ), |
52 | 67 | ); |
53 | 68 | |
54 | 69 | /** |
55 | 70 | * Class constructor |
56 | 71 | * |
57 | 72 | * @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. |
59 | 75 | */ |
60 | 76 | public function __construct( $repo, $txn ) { |
61 | 77 | $this->repo = $repo; |
— | — | @@ -84,6 +100,18 @@ |
85 | 101 | } |
86 | 102 | |
87 | 103 | /** |
| 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 | + /** |
88 | 116 | * Get commit log message |
89 | 117 | * |
90 | 118 | * @return string |
— | — | @@ -112,7 +140,7 @@ |
113 | 141 | * |
114 | 142 | * @return array filenames are keys and status letters are values |
115 | 143 | */ |
116 | | - protected function getCommitList() { |
| 144 | + private function getCommitList() { |
117 | 145 | $output = null; |
118 | 146 | $cmd = "{$this->svnlook} changed -t '{$this->transaction}' '{$this->repo}'"; |
119 | 147 | exec( $cmd, $output ); |
— | — | @@ -133,7 +161,7 @@ |
134 | 162 | * @param $fileTypes array of file types used for filtering |
135 | 163 | * @return array |
136 | 164 | */ |
137 | | - protected function getChangedFiles( array $fileTypes = array() ) { |
| 165 | + private function getChangedFiles( array $fileTypes = array() ) { |
138 | 166 | $list = $this->getCommitList(); |
139 | 167 | $files = array(); |
140 | 168 | foreach ( $list as $file => $status ) { |
— | — | @@ -155,6 +183,18 @@ |
156 | 184 | } |
157 | 185 | |
158 | 186 | /** |
| 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 | + /** |
159 | 199 | * Check if log message validates length rules |
160 | 200 | * |
161 | 201 | * @param $minLength int minimum length of log message |
— | — | @@ -162,7 +202,7 @@ |
163 | 203 | * |
164 | 204 | * @return bool |
165 | 205 | */ |
166 | | - protected function testLogMessageLength( $minLength = 1, $regex = '' ) { |
| 206 | + private function testLogMessageLength( $minLength = 1, $regex = '' ) { |
167 | 207 | $msg = trim( $this->getLogMessage() ); |
168 | 208 | $length = strlen( $msg ); |
169 | 209 | if ( $length < $minLength ) { |
— | — | @@ -183,7 +223,7 @@ |
184 | 224 | * @param $fileTypes array |
185 | 225 | * @return bool|string |
186 | 226 | */ |
187 | | - protected function testPHPLint( $fileTypes ) { |
| 227 | + private function testPHPLint( $fileTypes ) { |
188 | 228 | $output = null; |
189 | 229 | $result = ''; |
190 | 230 | $changedFiles = $this->getChangedFiles( $fileTypes ); |
— | — | @@ -205,11 +245,50 @@ |
206 | 246 | * @param $badUsers array of bad user names |
207 | 247 | * @return bool|string |
208 | 248 | */ |
209 | | - protected function testBadUsers( $badUsers ) { |
| 249 | + private function testBadUsers( $badUsers ) { |
210 | 250 | $ourUser = $this->getAuthor(); |
211 | 251 | if( in_array( $ourUser, $badUsers ) ) { |
212 | 252 | return "Please do not commit as '{$ourUser}', use your real commit name"; |
213 | 253 | } |
214 | 254 | return true; |
215 | 255 | } |
| 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 | + } |
216 | 295 | } |
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 |
1 | 11 | + native |
Property changes on: trunk/tools/subversion/hooks/pre-commit |
___________________________________________________________________ |
Added: svn:eol-style |
2 | 12 | + native |