Skip to content

Commit

Permalink
Add releease status to social posts
Browse files Browse the repository at this point in the history
For non-stable releases, that is. Closes #72.
  • Loading branch information
theory committed Feb 17, 2024
1 parent 4816746 commit fc97bbf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Revision history for Perl extension PGXN::Manager
ridiculous waste of memory, and also prevents it from being processed
by Locale::Maketext, which requires tildes to escape brackets and
trailing backslashes (#76).
- Added the release status to Twitter and Mastodon toots for testing and
unstable releases (#72).

0.31.1 2023-10-07T21:40:53Z
- Restored the writing of the pgxn_consumer PID file, accidentally
Expand Down
5 changes: 4 additions & 1 deletion lib/PGXN/Manager/Consumer/mastodon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ sub handle {
version => lc $meta->{version},
});

my $status = $meta->{release_status} eq 'stable' ? ''
: " ($meta->{release_status})";

my %emo = map { $_ => $EMOJI{$_}[rand @{ $EMOJI{$_} }] } keys %EMOJI;
$self->toot($release, join("\n\n",
"$emo{send} Released: $meta->{name} $meta->{version}",
"$emo{send} Released: $meta->{name} $meta->{version}$status",
"$emo{info} $meta->{abstract}",
"$emo{user} By $meta->{user}",
$url,
Expand Down
4 changes: 3 additions & 1 deletion lib/PGXN/Manager/Consumer/twitter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ sub handle {
$nick = $nick ? "\@$nick" : $meta->{user};

my $release = lc "$meta->{name}-$meta->{version}";
my $status = $meta->{release_status} eq 'stable' ? ''
: " ($meta->{release_status})";
$self->logger->log(INFO => "Posting $release to Twitter");

my $url = URI::Template->new($pgxn->config->{release_permalink})->process({
dist => lc $meta->{name},
version => lc $meta->{version},
});
try {
$client->update( "$meta->{name} $meta->{version} released by $nick: $url" );
$client->update( "$meta->{name} $meta->{version}$status released by $nick: $url" );
} catch {
$self->logger->log(ERROR => "Error posting $release to Twitter: $_");
};
Expand Down
12 changes: 11 additions & 1 deletion t/mastodon.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use strict;
use warnings;
use utf8;

use Test::More tests => 37;
use Test::More tests => 41;
# use Test::More 'no_plan';
use JSON::XS;
use Test::Exception;
Expand Down Expand Up @@ -179,12 +179,22 @@ SEND: {
my $mock_masto = Test::MockModule->new('PGXN::Manager::Consumer::mastodon');
my ($rel, $msg);
$mock_masto->mock(toot => sub { ($rel, $msg) = ($_[1], $_[2]) });
$meta->{release_status} = 'stable';
ok $mastodon->handle(release => $meta), 'Should send release message';
is $rel, lc("$meta->{name}-$meta->{version}"), 'Release should have been passed';
like $msg, qr/\S+ \QReleased: $meta->{name} $meta->{version}\E\n\n\S+ \Q$meta->{abstract}\E\n\n\S+ \QBy $meta->{user}\E\n\n$url/ms,
'Should have sent the formatted message';
is output(), "$logtime - INFO: Posting pgtap-1.3.5 to Mastodon\n",
'Should have info log message';

# Try non-stable.
$meta->{release_status} = 'testing';
ok $mastodon->handle(release => $meta), 'Should send release message';
is $rel, lc("$meta->{name}-$meta->{version}"), 'Release should have been passed';
like $msg, qr/\S+ \QReleased: $meta->{name} $meta->{version} ($meta->{release_status})\E\n\n\S+ \Q$meta->{abstract}\E\n\n\S+ \QBy $meta->{user}\E\n\n$url/ms,
'Should have sent the formatted message';
is output(), "$logtime - INFO: Posting pgtap-1.3.5 to Mastodon\n",
'Should have info log message';
}

# Have Mastodon throw an exception.
Expand Down
1 change: 1 addition & 0 deletions t/pod-spelling.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ JSON
merchantability
metadata
middlewares
multimarkdown
OAuth
PGXN
Plack
Expand Down
2 changes: 1 addition & 1 deletion t/pub.t
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test_psgi $app => sub {
page_title => 'howto_page_title',
});

my $content = quotemeta $mt->maketext('howto_body');
my $content = quotemeta $mt->from_file('howto.html');
like $res->decoded_content, qr/$content/, 'Content should match locale section data';
};

Expand Down
4 changes: 3 additions & 1 deletion t/twitter.t
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ my $meta = {
user => 'theory',
name => 'pgTAP',
version => '1.3.5',
release_status => 'stable',
};
my $pgxn = PGXN::Manager->instance;
my $url = URI::Template->new($pgxn->config->{release_permalink})->process({
Expand Down Expand Up @@ -153,8 +154,9 @@ is output(),

# Look up the Twitter username in the database.
$logger->{verbose} = 1;
$meta->{release_status} = 'testing';
$meta->{user} = TxnTest->user;
$tweet = "$meta->{name} $meta->{version} released by \@notHere: $url";
$tweet = "$meta->{name} $meta->{version} (testing) released by \@notHere: $url";
ok $twitter->handle(release => $meta), 'Should send message with Twitter nick';
is output(),
"$logtime - INFO: Posting \L$meta->{name}-$meta->{version}\E to Twitter\n",
Expand Down

0 comments on commit fc97bbf

Please sign in to comment.