line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hubot::Scripts::githubIssue; |
2
|
|
|
|
|
|
|
$Hubot::Scripts::githubIssue::VERSION = '0.1.10'; |
3
|
1
|
|
|
1
|
|
779
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
3
|
use JSON; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub load { |
8
|
0
|
|
|
0
|
|
|
my $github = githubot->new; |
9
|
0
|
|
|
|
|
|
my ( $class, $robot ) = @_; |
10
|
|
|
|
|
|
|
$robot->hear( |
11
|
|
|
|
|
|
|
qr/((\S*|^)?#(\d+)).*/, |
12
|
|
|
|
|
|
|
sub { |
13
|
0
|
|
|
0
|
|
|
my $msg = shift; |
14
|
0
|
|
|
|
|
|
my $issue_number = $msg->match->[2]; |
15
|
0
|
|
0
|
|
|
|
my $bot_github_repo = $github->qualified_repo( $msg->match->[1] |
16
|
|
|
|
|
|
|
// $ENV{HUBOT_GITHUB_REPO} ); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $issue_title = ''; |
19
|
|
|
|
|
|
|
$github->request( |
20
|
|
|
|
|
|
|
'get', |
21
|
|
|
|
|
|
|
"/repos/$bot_github_repo/issues/$issue_number", |
22
|
|
|
|
|
|
|
sub { |
23
|
0
|
|
|
|
|
|
my ( $body, $hdr ) = @_; |
24
|
0
|
0
|
0
|
|
|
|
return if ( !$body || $hdr->{Status} !~ /^2/ ); |
25
|
0
|
|
|
|
|
|
my $data = decode_json($body); |
26
|
0
|
|
|
|
|
|
$issue_title = $data->{title}; |
27
|
0
|
|
0
|
|
|
|
my $base_url = $ENV{HUBOT_GITHUB_API} |
28
|
|
|
|
|
|
|
// 'https://api.github.com'; |
29
|
0
|
|
|
|
|
|
my $url; |
30
|
0
|
0
|
|
|
|
|
unless ( $ENV{HUBOT_GITHUB_API} ) { |
31
|
0
|
|
|
|
|
|
$url = "https://github.com"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
$url = $base_url; |
35
|
0
|
|
|
|
|
|
$url =~ s/\/api\/v3//; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
$msg->send( |
38
|
|
|
|
|
|
|
"Issue $issue_number: $issue_title $url/$bot_github_repo/issues/$issue_number" |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
package githubot; |
47
|
|
|
|
|
|
|
$githubot::VERSION = '0.1.10'; |
48
|
1
|
|
|
1
|
|
344
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
49
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
50
|
1
|
|
|
1
|
|
181
|
use AnyEvent::HTTP::ScopedClient; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
53
|
|
|
|
|
|
|
my ( $class, $opts ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$opts->{token} = $ENV{HUBOT_GITHUB_TOKEN}; |
56
|
|
|
|
|
|
|
$opts->{defaultRepo} = $ENV{HUBOT_GITHUB_REPO}; |
57
|
|
|
|
|
|
|
$opts->{defaultUser} = $ENV{HUBOT_GITHUB_USER}; |
58
|
|
|
|
|
|
|
$opts->{apiRoot} = $ENV{HUBOT_GITHUB_API} // "https://api.github.com"; |
59
|
|
|
|
|
|
|
$opts->{apiVersion} = $ENV{HUBOT_GITHUB_VERSION} // "beta"; |
60
|
|
|
|
|
|
|
return bless $opts, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub qualified_repo { |
64
|
|
|
|
|
|
|
my ( $self, $repo ) = @_; |
65
|
|
|
|
|
|
|
unless ($repo) { |
66
|
|
|
|
|
|
|
unless ( $repo = $self->{defaultRepo} ) { |
67
|
|
|
|
|
|
|
print STDERR "Default Github repo not specified"; |
68
|
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
$repo = lc $repo; |
72
|
|
|
|
|
|
|
return $repo unless index( $repo, '/' ) == -1; |
73
|
|
|
|
|
|
|
my $user = $self->{defaultUser}; |
74
|
|
|
|
|
|
|
unless ($user) { |
75
|
|
|
|
|
|
|
print STDERR "Default Github user not specified"; |
76
|
|
|
|
|
|
|
return $repo; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
return "$user/$repo"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub request { |
82
|
|
|
|
|
|
|
my ( $self, $verb, $url, $data, $cb ) = @_; |
83
|
|
|
|
|
|
|
( $cb, $data ) = ( $data, undef ) unless $cb; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $url_api_base = $self->{apiRoot}; |
86
|
|
|
|
|
|
|
if ( $url !~ m/^http/ ) { |
87
|
|
|
|
|
|
|
$url = "/$url" unless $url =~ m|^/|; |
88
|
|
|
|
|
|
|
$url = $url_api_base . $url; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
my $req = AnyEvent::HTTP::ScopedClient->new($url); |
91
|
|
|
|
|
|
|
$req = $req->header( |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
Accept => 'application/vnd.github.' |
94
|
|
|
|
|
|
|
. $self->{apiVersion} . '+json', |
95
|
|
|
|
|
|
|
'User-Agent' => "p5-GitHubot" |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
my $oauth_token = $self->{token}; |
99
|
|
|
|
|
|
|
$req->header( 'Authorization', "token $oauth_token" ) if $oauth_token; |
100
|
|
|
|
|
|
|
my $method = lc $verb; |
101
|
|
|
|
|
|
|
$req->$method( $data, $cb ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Hubot::Scripts::githubIssue |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 VERSION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
version 0.1.10 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SYNOPSIS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#nnn - link to GitHub issue nnn for HUBOT_GITHUB_REPO project |
117
|
|
|
|
|
|
|
repo#nnn - link to GitHub issue nnn for repo project |
118
|
|
|
|
|
|
|
user/repo#nnn - link to GitHub issue nnn for user/repo project |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 CONFIGURATION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * HUBOT_GITHUB_REPO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * HUBOT_GITHUB_TOKEN |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * HUBOT_GITHUB_API |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * HUBOT_GITHUB_ISSUE_LINK_IGNORE_USERS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Hyungsuk Hong |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |