Making WordPress.org

Changeset 3024


Ignore:
Timestamp:
04/27/2016 03:40:45 PM (8 years ago)
Author:
ocean90
Message:

Translate, Plugin Directory: Send a Slack notification when a translation sync was processed.

See #1636.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/sync/class-translation-sync.php

    r3018 r3024  
    4848        }
    4949
     50        $time = date( 'r' );
     51        $message = "_Time: {$time}_\nTranslation sync from dev to stable in process...\n";
    5052        foreach ( $translation_sets as $translation_set ) {
    5153            if ( 0 == $translation_set->current_count() ) {
     
    5557            // Sync translations in a separate process.
    5658            $cmd = WPORGTRANSLATE_WPCLI . ' wporg-translate sync-plugin-translations ' . escapeshellarg( $args['gp_project'] ) . ' ' . escapeshellarg( $translation_set->locale ) . ' --set=' . escapeshellarg( $translation_set->slug );
    57             echo shell_exec( $cmd );
    58         }
     59            $output = shell_exec( $cmd );
     60            if ( 'No translations available.' !== $output ) {
     61                $message .= "\t" . $output;
     62            }
     63        }
     64        $message .= 'Translation sync was successfully processed.';
     65
     66        $attachment = [
     67            'title'      => "Translation Sync for {$args['plugin']}",
     68            'title_link' => "https://translate.wordpress.org/projects/wp-plugins/{$args['plugin']}",
     69            'text'       => $message,
     70            'fallback'   => "Translations for {$args['plugin']} were synced.",
     71            'color'      => '#00a0d2',
     72            'mrkdwn_in'  => [ 'text' ],
     73        ];
     74        $this->slack( $attachment );
    5975
    6076        return true;
     
    241257        return true;
    242258    }
     259
     260    /**
     261     * Sends a notifcation to the the Slack channel.
     262     *
     263     * @param array $attachment The attachment of a notification.
     264     */
     265    private function slack( $attachment ) {
     266        if ( ! defined( 'GLOTPRESS_SLACK_WEBHOOK' ) ) {
     267            return;
     268        }
     269
     270        require_once API_WPORGPATH . 'includes/slack-config.php';
     271        $send = new \Dotorg\Slack\Send( GLOTPRESS_SLACK_WEBHOOK );
     272        $send->add_attachment( $attachment );
     273        $send->set_username( 'Plugin Translation Sync' );
     274        $send->send( '#meta-language-packs' );
     275    }
    243276}
Note: See TracChangeset for help on using the changeset viewer.