forked from bingos/bot-gumbynet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-commit
More file actions
executable file
·131 lines (102 loc) · 2.85 KB
/
Copy pathpost-commit
File metadata and controls
executable file
·131 lines (102 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl -w
use POE qw(Filter::Line Filter::Stream Wheel::SocketFactory Wheel::ReadWrite Wheel::Run);
use Carp;
my ($server) = 'localhost';
my ($port) = 9090;
my ($svnlook) = '/usr/local/bin/svnlook';
my ($repos) = $ARGV[0] || die;
my ($rev) = $ARGV[1] || die;
my ($channel) = '#PoE';
my ($friendly) = 'PoCo-IRC';
POE::Session->create(
inline_states => { _start => \&start_client,
},
package_states => [
'main' => [
qw(_child_error _child_closed _child_stdout _child_stderr _connect _sock_down _sock_flushed _sock_up _sock_err)
],
],
options => { trace => 0 },
);
$poe_kernel->run();
exit 0;
sub start_client {
my ($kernel,$heap) = @_[KERNEL,HEAP];
$heap->{wheel} = POE::Wheel::Run->new(
Program => $svnlook,
ProgramArgs => [ 'info', $repos, '-r', $rev ],
ErrorEvent => '_child_error',
CloseEvent => '_child_closed', # Child closed all output.
StdoutEvent => '_child_stdout', # Event to emit with child stdout information.
StderrEvent => '_child_stderr', # Event to emit with child stderr information.
StdioFilter => POE::Filter::Line->new(), # Or some other filter.
);
undef;
}
sub _child_error {
my ($kernel,$heap) = @_[KERNEL,HEAP];
delete ( $heap->{wheel} );
if ( scalar @{ $heap->{svnlooklines} } == 0 ) {
return undef;
}
$author = shift @{ $heap->{svnlooklines} };
$date = shift @{ $heap->{svnlooklines} };
shift @{ $heap->{svnlooklines} };
$logentry = shift @{ $heap->{svnlooklines} };
$kernel->yield( '_connect' );
undef;
}
sub _child_closed {
my ($kernel,$heap) = @_[KERNEL,HEAP];
delete ( $heap->{wheel} );
undef;
}
sub _child_stdout {
my ($kernel,$heap,$input) = @_[KERNEL,HEAP,ARG0];
push( @{ $heap->{svnlooklines} }, $input );
undef;
}
sub _child_stderr {
my ($kernel,$heap,$input) = @_[KERNEL,HEAP,ARG0];
warn "$input\n";
undef;
}
sub _connect {
my ($kernel,$heap) = @_[KERNEL,HEAP];
$heap->{sockfactory} = POE::Wheel::SocketFactory->new(
SocketProtocol => 'tcp',
RemoteAddress => $server,
RemotePort => $port,
SuccessEvent => '_sock_up',
FailureEvent => '_sock_err',
);
undef;
}
sub _sock_up {
my ($kernel, $heap, $session, $socket) = @_[KERNEL, HEAP, SESSION, ARG0];
delete ( $heap->{sockfactory} );
$heap->{socket} = new POE::Wheel::ReadWrite
( Handle => $socket,
Driver => POE::Driver::SysRW->new(),
Filter => POE::Filter::Line->new(),
InputEvent => '_parseline',
ErrorEvent => '_sock_down',
FlushedEvent => '_sock_flushed',
);
if ( $heap->{socket} ) {
$heap->{socket}->put("CTCP $channel :ACTION $friendly commit: '$logentry' by $author");
}
undef;
}
sub _sock_err {
delete ( $_[HEAP]->{sockfactory} );
undef;
}
sub _sock_down {
delete ( $_[HEAP]->{socket} );
undef;
}
sub _sock_flushed {
delete ( $_[HEAP]->{socket} );
undef;
}