Making WordPress.org

Changeset 1078


Ignore:
Timestamp:
12/31/2014 04:48:29 PM (10 years ago)
Author:
nacin
Message:

Slack: Add hooks for processing tickets/comments from Trac.

Location:
sites/trunk/svn.wordpress.org
Files:
2 added
1 deleted
2 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • sites/trunk/svn.wordpress.org/bin/slack-commit-hook.php

    r1075 r1078  
    77}
    88
    9 define( 'INC', dirname( __DIR__ ) . '/includes/slack-commit-hook/' );
    10 require INC . 'sender.php';
    11 require INC . 'trac.php';
    12 require INC . 'config.php';
     9define( 'INC', dirname( __DIR__ ) . '/includes/slack-trac-hooks' );
     10require INC . '/commits.php';
     11require INC . '/trac.php';
     12require INC . '/config.php';
    1313
    1414list( , $trac, $repo, $rev ) = $argv;
    1515
    1616$slack_hook = 'https://hooks.slack.com/services/...';
    17 $sender = new \SlackCommitHook\Sender( $trac, $repo, $rev, $slack_hook );
     17$sender = new Dotorg\SlackTracHooks\Commits( $trac, $repo, $rev, $slack_hook );
    1818// $sender->use_test_channel( true );
    1919// $sender->set_svnlook_executable( ... );
  • sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/commits.php

    r1075 r1078  
    11<?php
    22
    3 namespace SlackCommitHook;
     3namespace Dotorg\SlackTracHooks;
    44
    5 class Sender {
     5class Commits {
    66    protected $trac;
    77    protected $repo;
     
    2929    public function run() {
    3030        $payload = $this->generate_payload();
    31         foreach ( $this->trac->get_channels( $this->svnlook( 'changed' ) ) as $channel ) {
     31        foreach ( $this->trac->get_commit_channels( $this->svnlook( 'changed' ) ) as $channel ) {
    3232            $this->send( $channel, $payload );
    3333        }
     
    4646        $revision = 'r' . $this->rev;
    4747
    48         $username = $this->trac->get_username();
     48        $username = $this->trac->get_commit_username();
    4949        $emoji    = $this->trac->get_emoji();
    5050        $color    = $this->trac->get_color();
  • sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/config.php

    r1075 r1078  
    11<?php
    22
    3 namespace SlackCommitHook;
     3namespace Dotorg\SlackTracHooks;
    44
    55class Core_Trac extends Trac {
    6     protected $channels = array( '#core', '#core-commits' );
    7     protected $username = 'WordPress commit';
     6    protected $commit_channels = array( '#core', '#core-commits' );
     7    protected $commit_username = 'WordPress commit';
     8    protected $commit_range = array( 3, 5 );
    89    protected $ticket_range = array( 3, 5 );
    9     protected $commit_range = array( 3, 5 );
     10
     11    protected $ticket_channels  = array( '#core', '#core-newtickets' );
     12    protected $ticket_username  = 'WordPress Trac';
     13    protected $firehose_channel = '#core-firehose';
    1014
    1115    /**
     
    1317     * Start regex matches with # as your delimiter.
    1418     */
    15     protected $channel_matcher = array(
     19    protected $commit_path_filters = array(
    1620        'wp-content/themes'       => '#core-themes',
    1721        'customize'               => '#core-customize',
     
    2125        'press-this.php'          => '#feature-pressthis',
    2226    );
     27
     28    /**
     29     * Components or focuses that cause new tickets to be piped to particular channels.
     30     */
     31    protected $ticket_component_filters = array(
     32        'Customize'     => '#core-customize',
     33        'Bundled Theme' => '#core-themes',
     34        'Press This'    => '#feature-pressthis',
     35    );
    2336}
    2437
    2538class Meta_Trac extends Trac {
    26     protected $channels = array( '#meta', '#meta-commits' );
    27     protected $username = 'WordPress.org Meta commit';
     39    protected $commit_channels = array( '#meta', '#meta-commits' );
     40    protected $commit_username = 'WordPress.org Meta commit';
    2841
    29     protected $channel_matcher = array(
     42    protected $ticket_channels = array( '#meta-newtickets' );
     43
     44    protected $commit_path_filters = array(
    3045        'translate.wordpress.org/' => '#meta-i18n',
    3146        'global.wordpress.org/'    => '#meta-i18n',
     
    3449        'wporg-developer/'         => '#meta-devhub',
    3550    );
     51
     52    protected $ticket_component_filters = array(
     53        'International Forums'          => '#meta-i18n',
     54        'International Sites (Rosetta)' => '#meta-i18n',
     55        'translate.wordpress.org'       => '#meta-i18n',
     56        'developer.wordpress.org'       => '#meta-devhub',
     57    );
    3658}
    3759
    3860class bbPress_Trac extends Trac {
    39     protected $channels = array( '#bbpress', '#bbpress-commits' );
    40     protected $username = 'bbPress commit';
     61    protected $commit_channels = array( '#bbpress', '#bbpress-commits' );
     62    protected $commit_username = 'bbPress commit';
     63    protected $ticket_channels = array( '#bbpress', '#bbpress-newtickets' );
    4164    protected $color    = '#080';
    4265    protected $emoji    = ':bbpress:';
     
    4467
    4568class BuddyPress_Trac extends Trac {
    46     protected $channels = array( '#buddypress', '#buddypress-commits' );
    47     protected $username = 'BuddyPress commit';
     69    protected $commit_channels = array( '#buddypress', '#buddypress-commits' );
     70    protected $commit_username = 'BuddyPress commit';
     71    protected $ticket_channels = array( '#buddypress', '#buddypress-newtickets' );
    4872    protected $color    = '#d84800';
    4973    protected $emoji    = ':buddypress:';
     
    5175
    5276class Dotorg_Trac extends Trac {
    53     protected $channels = 'dotorg';
    54     protected $username = 'Private dotorg commit';
     77    protected $commit_channels = 'dotorg';
     78    protected $commit_username = 'Private dotorg commit';
     79    protected $ticket_channels = 'dotorg';
    5580}
    5681
    5782class Deploy_Trac extends Trac {
    58     protected $channels = 'dotorg';
    59     protected $username = 'Deploy commit';
     83    protected $commit_channels = 'dotorg';
     84    protected $commit_username = 'Deploy commit';
     85    protected $ticket_channels = 'dotorg';
    6086}
    6187
    6288class GlotPress_Trac extends Trac {
    63     protected $channels = '#glotpress';
    64     protected $username = 'GlotPress commit';
     89    protected $commit_channels = '#glotpress';
     90    protected $commit_username = 'GlotPress commit';
     91    protected $ticket_channels = '#glotpress';
    6592}
  • sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac.php

    r1077 r1078  
    11<?php
    22
    3 namespace SlackCommitHook;
     3namespace Dotorg\SlackTracHooks;
    44
    55abstract class Trac {
    6     protected $channels = '#test';
    7     protected $username = 'Commit';
     6    protected $commit_channels = '#test';
     7    protected $commit_username = 'Commit';
     8    protected $ticket_channels = '#test';
     9    protected $ticket_username;
     10
     11    protected $firehose_channel = false;
     12
    813    protected $color    = '#21759b';
    914    protected $emoji    = ':wordpress:';
     
    1520
    1621    function __construct() {
    17         // 'SlackCommitHook\Core_Trac' => 'core'
    18         $this->trac = strtolower( str_replace( array( __NAMESPACE__, '\\', '_Trac' ), '', get_class( $this ) ) );
     22        // 'Dotorg\SlackTracHooks\Core_Trac' => 'Core_Trac'
     23        $class = str_replace( __NAMESPACE__ . '\\', '', get_class( $this ) );
     24
     25        // 'Core_Trac' => 'core'
     26        $this->trac = strtolower( str_replace( '_Trac', '', $class ) );
     27
     28        if ( ! isset( $this->ticket_username ) ) {
     29            // 'Core_Trac' => 'Core Trac'
     30            $this->ticket_username = str_replace( '_', ' ', $class );
     31        }
    1932    }
    2033
    21     function get_username() {
    22         return $this->username;
     34    function get_commit_username() {
     35        return $this->commit_username;
     36    }
     37
     38    function get_ticket_username() {
     39        return $this->ticket_username;
    2340    }
    2441
     
    5774    }
    5875
    59     function get_channels( $changed_files = null ) {
    60         $channels = (array) $this->channels;
     76    function get_commit_channels( $changed_files = null ) {
     77        $channels = (array) $this->commit_channels;
    6178
    62         if ( empty( $this->channel_matcher ) || empty( $changed_files ) ) {
     79        if ( isset( $this->firehose_channel ) ) {
     80            $channels[] = $this->firehose_channel;
     81        }
     82
     83        if ( empty( $this->commit_path_filters ) || empty( $changed_files ) ) {
    6384            return $channels;
    6485        }
    6586
    66         foreach ( $this->channel_matcher as $needle => $channels_to_add ) {
     87        foreach ( $this->commit_path_filters as $needle => $channels_to_add ) {
    6788            if ( $needle[0] === '#' ) {
    6889                // Append PCRE_MULTILINE so ^ and $ refer to individual lines.
     
    7495            }
    7596        }
     97   
    7698        return $channels;
    7799    }
     100
     101    function get_ticket_channels( $ticket = null ) {
     102        $channels = (array) $this->ticket_channels;
     103
     104        if ( isset( $this->firehose_channel ) ) {
     105            $channels[] = $this->firehose_channel;
     106        }
     107
     108        if ( empty( $this->ticket_component_filters ) || empty( $ticket ) ) {
     109            return $channels;
     110        }
     111
     112        if ( isset( $ticket->component ) && isset( $this->ticket_component_filters[ $ticket->component ] ) ) {
     113            $channels = array_merge( $channels, (array) $this->ticket_component_filters[ $ticket->component ] );
     114        }
     115
     116        if ( isset( $ticket->focuses ) ) {
     117            foreach ( explode( ', ', $ticket->focuses ) as $focus ) {
     118                if ( isset( $this->ticket_component_filters[ $focus ] ) ) {
     119                    $channels = array_merge( $channels, (array) $this->ticket_component_filters[ $focus ] );
     120                }
     121            }
     122        }
     123        return $channels;
     124    }
     125
     126    function get_firehose_channel() {
     127        return $this->firehose_channel;
     128    }
    78129}
     130
Note: See TracChangeset for help on using the changeset viewer.