line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::Cmd::Notification; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
3
|
|
|
|
|
|
|
$Tapper::Cmd::Notification::VERSION = '5.0.11'; |
4
|
5
|
|
|
5
|
|
5568177
|
use Moose; |
|
5
|
|
|
|
|
531081
|
|
|
5
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
35234
|
use Tapper::Model 'model'; |
|
5
|
|
|
|
|
4410
|
|
|
5
|
|
|
|
|
263
|
|
7
|
5
|
|
|
5
|
|
89
|
use YAML::Syck; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
306
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
35
|
use parent 'Tapper::Cmd'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
39
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub get_user |
14
|
|
|
|
|
|
|
{ |
15
|
3
|
|
|
3
|
1
|
11
|
my ($self, $data) = @_; |
16
|
3
|
100
|
|
|
|
12
|
if (not $data->{owner_id}) { |
17
|
2
|
|
33
|
|
|
8
|
my $login = $data->{owner_login} || $ENV{USER}; |
18
|
2
|
|
|
|
|
23
|
my $owner = model('TestrunDB')->resultset('Owner')->search({login => $login}, {rows => 1})->first; |
19
|
2
|
50
|
|
|
|
14745
|
if (not $owner) { |
20
|
0
|
|
|
|
|
0
|
die "User '$login' does not exist in the database. Please create this user first.\n"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
353
|
$data->{owner_id} = $owner->id; |
24
|
2
|
|
|
|
|
89
|
delete $data->{owner_login}; |
25
|
|
|
|
|
|
|
} |
26
|
3
|
|
|
|
|
38
|
return $data; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add { |
33
|
2
|
|
|
2
|
1
|
18860
|
my ($self, $data) = @_; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
10
|
$data = $self->get_user($data); |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
12
|
my $notification = model('TestrunDB')->resultset('Notification')->new($data); |
38
|
2
|
|
|
|
|
1112
|
$notification->insert; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
17452
|
return $notification->id; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub list |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
0
|
1
|
0
|
my ($self, $search) = @_; |
47
|
0
|
|
|
|
|
0
|
return model('TestrunDB')->resultset('Notification')->search($search, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub update { |
53
|
1
|
|
|
1
|
1
|
6111
|
my ($self, $id, $data) = @_; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
8
|
my $notification = model('TestrunDB')->resultset('Notification')->find($id); |
56
|
1
|
50
|
|
|
|
3512
|
die "Notification subscription with id $id not found\n" if not $notification; |
57
|
1
|
50
|
|
|
|
23
|
die "Did not get a hash with data for updating notification subscription with id '$id'" unless ref $data eq 'HASH'; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
5
|
$data = $self->get_user($data); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
8
|
foreach my $key (keys %$data) { |
63
|
5
|
|
|
|
|
1111
|
$notification->$key($data->{$key}); |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
203
|
$notification->update; |
66
|
1
|
|
|
|
|
13870
|
return $notification->id; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub del { |
72
|
1
|
|
|
1
|
1
|
16330
|
my ($self, $id) = @_; |
73
|
1
|
|
|
|
|
7
|
my $notification = model('TestrunDB')->resultset('Notification')->find($id); |
74
|
1
|
50
|
|
|
|
3348
|
die qq(No notification subscription with id "$id" found) if not $notification;; |
75
|
1
|
|
|
|
|
62
|
$notification->delete(); |
76
|
1
|
|
|
|
|
13425
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; # End of Tapper::Cmd::Testrun |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding UTF-8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Tapper::Cmd::Notification |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This project offers backend functions for all projects that manipulate |
97
|
|
|
|
|
|
|
notification subscriptions. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
use Tapper::Cmd::Notification; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $subscription = Tapper::Cmd::Notification->new(); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $details = {event => "testrun_finished", |
104
|
|
|
|
|
|
|
filter => "testrun('id') == 23", |
105
|
|
|
|
|
|
|
comment => "Get back to work, testrun 23 is finished", |
106
|
|
|
|
|
|
|
persist => 0, |
107
|
|
|
|
|
|
|
owner_login => 'anton', |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
my $id = $subscription->add($details); |
110
|
|
|
|
|
|
|
$details->{filter} = "testrun('id') == 24"; |
111
|
|
|
|
|
|
|
my $error = $subscription->update($id, $details); |
112
|
|
|
|
|
|
|
$error = $subscription->delete($id); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Tapper::Cmd::Notification - Backend functions for manipluation of notification subscriptions in the database |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 FUNCTIONS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 get_user |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Make sure the user is given as user id. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
@param hash ref - data for notification subscription |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
@param success - updated hash ref |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
@throws die |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 add |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Add a new notification subscription. Expects all details as a hash reference. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
@param hash ref - notification subscrition data |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
@return success - subscrition id |
137
|
|
|
|
|
|
|
@return error - undef |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
@throws Perl die |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 list |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Return a DBIC resultset object that contains a list of notification |
144
|
|
|
|
|
|
|
subscriptions. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 update |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Update a given notification subscription. The given data has to be a |
149
|
|
|
|
|
|
|
complete hash of what the subscription should look like after the |
150
|
|
|
|
|
|
|
update. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
@param int - subscription id |
153
|
|
|
|
|
|
|
@param hash ref - subscription as it should be |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
@return success - subscription id |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
@throws die |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 del |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Delete a notification subscription with given id. Its named del instead of delete to |
162
|
|
|
|
|
|
|
prevent confusion with the buildin delete function. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
@param int - notification id |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
@return success - 0 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
@throws die |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
AMD OSRC Tapper Team, C<< <tapper at amd64.org> >> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Copyright 2012 AMD OSRC Tapper Team, all rights reserved. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This program is released under the following license: freebsd |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHORS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over 4 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Advanced Micro Devices, Inc.. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This is free software, licensed under: |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |