watch: add 'watch' support
[girocco/ztw.git] / cgi / watchedit.cgi
blobf83dfa62bec965b30d9b648a1a58ec66fd8889fa
1 #!/usr/bin/perl
2 # (c) Zachary T Welch <zw@superlucidity.net>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib qw(/home/repo/repomgr/cgi);
9 use Git::RepoCGI;
11 my $repo = Git::RepoCGI->new('Manage Watchdogs');
12 my $project = $repo->sparam('project');
13 my $branch = $repo->sparam('branch');
14 my $path = $repo->sparam('path');
15 my $user = $repo->sparam('user');
17 # check for submission
18 $repo->bye('Not yet implemented') if $repo->sparam('go');
20 # check for mutually exclusive parameters
21 $repo->bye("You may view either a project or a user, not both.")
22 if $project && $user;
24 # obtain minimal parameters
25 unless ($project or $user) {
26 print <<EOT;
27 <p>
28 To view watchdogs you must select a project or user.
29 </p>
31 <h3>View Project Watchdogs</h3>
32 <form method="post">
33 <p>Project: <input type="text" name="project" /></p>
34 <p>Branch: <input type="text" name="branch" value="$branch" /></p>
35 <p>Path: <input type="text" name="path" value="$path" /></p>
36 <p><input type="submit" value="View" /></p>
37 </form>
39 <h3>View User Watchdogs</h3>
40 <form method="post">
41 <p>Account: <input type="text" name="user" /></p>
42 <p><input type="submit" value="View" /></p>
43 </form>
44 EOT
45 exit
48 # print on-line documentation
49 print <<EOT;
50 <p>
51 A watchdog set with empty branch and path fields will trigger for all
52 changes pushed to the repository. Regular expressions can be used in
53 these fields to restrict notifications to matching branch or tree paths.
54 </p>
55 <p>
56 When activity occurs in a project, users are sent notification when the
57 fields of one or more watchdog are triggered. These notification events
58 are aggregated for all projects and deliveried periodically via e-mail.
59 </p>
60 <p>
61 A single notification will be produced for each triggiering event, so
62 watchdogs using filter expressions that overlap do <em>not</em> generate
63 duplicate noticiations. All watchdog filters that match will be listed
64 as a source the of an activity's notification, so you can update your
65 settings to eliminate duplicate filters.
66 </p>
67 <p>
68 The number of filters on the system directly impacts the notification
69 period, so you should try to cull redundant filters from these lists.
70 </p>
71 EOT
73 # set up for display user or project specific parts of the page
74 my %for_user = ( title => 'Account', key => 'user', value => $user,
75 auth => 'User', no_dogs => "by $user",
76 url_args => "name=$user" );
77 my %for_proj = ( title => 'Project', key => 'project', value => $project,
78 auth => 'Admin', no_dogs => "to monitor $project",
79 url_args => "project=$project&branch=$branch&path=$path");
80 my ( %showing, %listing );
81 if ($user) {
82 %showing = %for_user;
83 %listing = %for_proj;
84 } else {
85 %showing = %for_proj;
86 %listing = %for_user;
87 print <<EOT;
88 <h3>Contacting Watchers</h3>
89 <p>
90 If you have push access to a project, you can send messages to
91 registered watchers of a particular fork, branch, or path by clicking on
92 the 'discuss' link.
93 </p>
94 EOT
97 # display section
98 print "<h3>Watchdogs for $showing{title} $showing{value}</h3>\n";
100 my @dogs = Git::RepoCGI::load(type => $showing{key}, name => $showing{value});
101 unless (@dogs) {
102 my $no_dogs = <<EOT;
103 No watchdogs have been created $showing{no_dogs}. Do you want to
104 <a href="watchadd.cgi?$showing{url_args}">create one</a>?
106 $repo->bye($no_dogs);
109 print <<EOT;
110 <form method="post">
111 <table>
112 <tr>
113 <th>$listing{title}</th>
114 <th>Branch</th>
115 <th>Path</th>
116 <th>Contact</th>
117 <th>Delete</th>
118 </tr>
121 for my $dog ( @dogs ) {
122 my ( $u, $r, $b, $p ) = ( '', '', '', '' ); #TODO: @$dog;
123 my $key = "$u:$r:$b:$p";
124 my $url_value = $user ? $r : $u;
125 my $url_args = $user ? "project=$r.git&branch=$b&path=$p" : "name=$u";
126 my $url = "<a href=\"watchedit.cgi?$url_args\">$url_value</a>";
127 print <<EOT;
128 <tr>
129 <td>$url</td>
130 <td><input type="text" name="b" value="$b" /></td>
131 <td><input type="text" name="p" value="$p" /></td>
132 <td><a href="watchspam.cgi?project=$r&branch=$b&path=$p">contact</a>
133 <td><a href="watchdel.cgi?name=$u&project=$r&branch=$b&path=$p">delete</a>
134 </tr>
138 print <<EOT
139 </table>
140 <h3>$showing{auth} Authentication</h3>
141 <p>$showing{title}: <em>$showing{value}</em>
142 <input type="hidden" name="$showing{key}" value="$showing{value}" /></p>
143 <p>Password: <input type="password" name="cpwd" /></p>
144 <p><input type="submit" name="go" value="Watch" /></p>
145 </form>