-
Notifications
You must be signed in to change notification settings - Fork 3
/
jira.pm
61 lines (55 loc) · 1.77 KB
/
jira.pm
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
package jira;
use strict;
use Net::Netrc;
use LWP::UserAgent;
use JSON::XS;
use lib ".";
use config;
use obssupport;
my $debug=0;
my $jiracreds = Net::Netrc->lookup('jira.suse.com');
die "need jira creds in ~/.netrc" unless $jiracreds;
my $ua = LWP::UserAgent->new;
sub getbug($)
{ my $issueid=shift;
my $req = HTTP::Request->new(GET => "https://jira.suse.com/rest/api/2/issue/$issueid/comment");
$req->authorization_basic($jiracreds->login(), $jiracreds->password());
my $data = $ua->request($req)->as_string;
# equivalent to
#my $data = `curl -s -n "https://jira.suse.com/rest/api/2/issue/$issueid/comment"`;
return $data;
}
sub addcomment($$)
{ my ($issueid, $comment) = @_;
my $req = HTTP::Request->new(POST => "https://jira.suse.com/rest/api/2/issue/$issueid/comment");
$req->authorization_basic($jiracreds->login(), $jiracreds->password());
$req->header("Content-Type", "application/json");
$req->content(encode_json({body=>$comment}));
my $data = $ua->request($req);
return 1;
}
sub filtersr($@)
{ my($bugjson, @sr)=@_;
my @sr2=();
return @sr2 if($bugjson=~m/\A\[\]/);
# drop SRs that were already linked:
foreach my $sr (@sr) {
next if $bugjson=~m/request\/show\/$sr\b/;
push(@sr2, $sr); # keep sr
}
return @sr2;
}
sub addjirasrlinks($@)
{ my($bugid, @sr)=@_;
return 2 unless $bugid=~s/^js[cd]#//; # ignore others
my @sr2=@sr;
if(!$debug) { @sr2=filtersr(getbug($bugid), @sr);}
return 1 unless @sr2;
my $comment="This is an autogenerated message for $config::bsname integration:\nThis bug ($bugid) was mentioned in\n".obssupport::srurlplusinfo(@sr2)."\n";
print "submit $bugid, @sr2 $comment\n";
if(!$debug) {
addcomment($bugid, $comment);
}
return 1;
}
1;