[Bps-public-commit] App-Changeloggr branch, master, updated. ba2445801e6bef6346c08ed00fc8a88d010a1cbb

Alex M Vandiver alexmv at bestpractical.com
Mon Apr 27 18:20:20 EDT 2009


The branch, master has been updated
       via  ba2445801e6bef6346c08ed00fc8a88d010a1cbb (commit)
       via  ad34d5be0cef998e25a8650d19233434c6ca6f1d (commit)
      from  37ac04acb20e01837423469529c3b6e3c84218ae (commit)

Summary of changes:
 etc/config.yml                                     |    2 +-
 .../Action/{DeleteTag.pm => CreateCommitLink.pm}   |    7 ++-
 .../Action/{DeleteTag.pm => DeleteCommitLink.pm}   |    4 +-
 lib/App/Changeloggr/Model/Changelog.pm             |    6 ++
 lib/App/Changeloggr/Model/CommitLink.pm            |   56 ++++++++++++++++++++
 lib/App/Changeloggr/View.pm                        |    7 ++-
 lib/App/Changeloggr/View/Admin.pm                  |   24 ++++++++
 t/{00-model-Vote.t => 00-model-CommitLink.t}       |   14 +++---
 8 files changed, 105 insertions(+), 15 deletions(-)
 copy lib/App/Changeloggr/Action/{DeleteTag.pm => CreateCommitLink.pm} (66%)
 copy lib/App/Changeloggr/Action/{DeleteTag.pm => DeleteCommitLink.pm} (75%)
 create mode 100644 lib/App/Changeloggr/Model/CommitLink.pm
 copy t/{00-model-Vote.t => 00-model-CommitLink.t} (67%)

- Log -----------------------------------------------------------------
commit ad34d5be0cef998e25a8650d19233434c6ca6f1d
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Mon Apr 27 15:37:58 2009 -0400

    Fix admin link after reorg

diff --git a/lib/App/Changeloggr/View.pm b/lib/App/Changeloggr/View.pm
index dbde416..7405a2a 100644
--- a/lib/App/Changeloggr/View.pm
+++ b/lib/App/Changeloggr/View.pm
@@ -70,7 +70,7 @@ sub changelog_summary {
         span {};
         my $admin_token = $changelog->as_superuser->admin_token;
         hyperlink(
-            url => "/changelog/$admin_token/admin",
+            url => "/admin/changelog/$admin_token",
             label => "[administrate]",
         );
     }

commit ba2445801e6bef6346c08ed00fc8a88d010a1cbb
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Mon Apr 27 18:20:16 2009 -0400

    Add "commit links", so bugtracker or message-ids can be linked to urls in commit messages

diff --git a/etc/config.yml b/etc/config.yml
index 893a4f4..f4fb446 100644
--- a/etc/config.yml
+++ b/etc/config.yml
@@ -14,7 +14,7 @@ framework:
     Password: ''
     RecordBaseClass: Jifty::DBI::Record::Cachable
     User: ''
-    Version: 0.0.1
+    Version: 0.0.2
   DevelMode: 1
   L10N: 
     PoDir: share/po
diff --git a/lib/App/Changeloggr/Action/CreateCommitLink.pm b/lib/App/Changeloggr/Action/CreateCommitLink.pm
new file mode 100644
index 0000000..31b6c6b
--- /dev/null
+++ b/lib/App/Changeloggr/Action/CreateCommitLink.pm
@@ -0,0 +1,19 @@
+package App::Changeloggr::Action::CreateCommitLink;
+use strict;
+use warnings;
+use base 'App::Changeloggr::Action::Mixin::RequiresAdminToken', 'Jifty::Action::Record::Create';
+
+sub take_action {
+    my $self = shift;
+    $self->record->current_user(App::Changeloggr::CurrentUser->superuser);
+    $self->SUPER::take_action(@_);
+}
+
+sub report_success {
+    my $self = shift;
+    $self->result->message(_('Created commit message link'));
+}
+
+1;
+
+
diff --git a/lib/App/Changeloggr/Action/DeleteCommitLink.pm b/lib/App/Changeloggr/Action/DeleteCommitLink.pm
new file mode 100644
index 0000000..484fd57
--- /dev/null
+++ b/lib/App/Changeloggr/Action/DeleteCommitLink.pm
@@ -0,0 +1,18 @@
+package App::Changeloggr::Action::DeleteCommitLink;
+use strict;
+use warnings;
+use base 'App::Changeloggr::Action::Mixin::RequiresAdminToken', 'Jifty::Action::Record::Delete';
+
+sub take_action {
+    my $self = shift;
+    $self->record->current_user(App::Changeloggr::CurrentUser->superuser);
+    $self->SUPER::take_action(@_);
+}
+
+sub report_success {
+    my $self = shift;
+    $self->result->message('Removed the commit link');
+}
+
+1;
+
diff --git a/lib/App/Changeloggr/Model/Changelog.pm b/lib/App/Changeloggr/Model/Changelog.pm
index 30c1334..212bc5c 100644
--- a/lib/App/Changeloggr/Model/Changelog.pm
+++ b/lib/App/Changeloggr/Model/Changelog.pm
@@ -76,6 +76,12 @@ sub tags {
     return M('TagCollection', changelog_id => $self);
 }
 
+sub commit_links {
+    my $self = shift;
+
+    return M('CommitLinkCollection', changelog_id => $self);
+}
+
 sub choose_change {
     my $self = shift;
 
diff --git a/lib/App/Changeloggr/Model/CommitLink.pm b/lib/App/Changeloggr/Model/CommitLink.pm
new file mode 100644
index 0000000..1d54089
--- /dev/null
+++ b/lib/App/Changeloggr/Model/CommitLink.pm
@@ -0,0 +1,56 @@
+use strict;
+use warnings;
+
+package App::Changeloggr::Model::CommitLink;
+use Jifty::DBI::Schema;
+
+use App::Changeloggr::Record schema {
+    column changelog_id =>
+        refers_to App::Changeloggr::Model::Changelog,
+        is mandatory,
+        is immutable,
+        render as 'hidden';
+
+    column find =>
+        type is 'text',
+        is mandatory
+        label is 'Find',
+        hints are 'Any valid regular expression';
+
+    column href =>
+        type is 'text',
+        is mandatory,
+        label is 'Link to',
+        hints are 'Use $1 and $2 to refer to capture groups';
+
+};
+
+use constant since => '0.0.2';
+
+sub linkify {
+    my $self = shift;
+    my $text = shift;
+
+    my $find = $self->find;
+    $text =~ 
+        s{($find)}{
+            my @matches = map {substr($text,$-[$_], $+[$_] - $-[$_])} 1..$#+;
+            my $href = $self->href;
+            $href =~ s{\$(\d+)}{$matches[$1]}eg;
+            qq{<a href="$href">$matches[0]</a>}
+        }eg;
+    return $text;
+}
+
+sub current_user_can {
+    my $self  = shift;
+    my $right = shift;
+
+    # anyone can read
+    return 1 if $right eq 'read';
+
+    return $self->SUPER::current_user_can($right, @_);
+}
+
+1;
+
diff --git a/lib/App/Changeloggr/View.pm b/lib/App/Changeloggr/View.pm
index 7405a2a..1fd5ff4 100644
--- a/lib/App/Changeloggr/View.pm
+++ b/lib/App/Changeloggr/View.pm
@@ -81,7 +81,10 @@ sub show_change {
 
     h3 {
         { class is "change" };
-        outs( $change->message );
+        my $message = Jifty->web->escape($change->message);
+        my $links = $change->changelog->commit_links;
+        $message = $_->linkify($message) while $_ = $links->next;
+        outs_raw( $message );
     }
 }
 
diff --git a/lib/App/Changeloggr/View/Admin.pm b/lib/App/Changeloggr/View/Admin.pm
index 621699a..ba62eaf 100644
--- a/lib/App/Changeloggr/View/Admin.pm
+++ b/lib/App/Changeloggr/View/Admin.pm
@@ -24,6 +24,8 @@ template '/changelog' => page {
 
     add_changes_to($changelog);
 
+    edit_links($changelog);
+
     edit_tags($changelog);
 
     my $delete = $changelog->as_delete_action;
@@ -55,6 +57,28 @@ sub add_changes_to {
     };
 }
 
+sub edit_links {
+    my $changelog = shift;
+    my $links = $changelog->commit_links;
+
+    while (my $link = $links->next) {
+        form {
+            my $delete_link = $link->as_delete_action;
+            render_action $delete_link;
+            form_submit(label => $link->find . " => " . $link->href);
+        }
+    }
+
+    form {
+        my $add_link = new_action(
+            class     => "CreateCommitLink",
+            arguments => { changelog_id => $changelog->id }
+        );
+        render_action $add_link;
+        form_submit(label => 'Add Link');
+    }
+}
+
 sub edit_tags {
     my $changelog = shift;
     my $tags = M("TagCollection", changelog_id => $changelog);
diff --git a/t/00-model-CommitLink.t b/t/00-model-CommitLink.t
new file mode 100644
index 0000000..1338324
--- /dev/null
+++ b/t/00-model-CommitLink.t
@@ -0,0 +1,49 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A basic test harness for the CommitLink model.
+
+=cut
+
+use Jifty::Test tests => 11;
+
+# Make sure we can load the model
+use_ok('App::Changeloggr::Model::CommitLink');
+
+# Grab a system user
+my $system_user = App::Changeloggr::CurrentUser->superuser;
+ok($system_user, "Found a system user");
+
+# Try testing a create
+my $o = App::Changeloggr::Model::CommitLink->new(current_user => $system_user);
+my ($id) = $o->create();
+ok($id, "CommitLink create returned success");
+ok($o->id, "New CommitLink has valid id set");
+is($o->id, $id, "Create returned the right id");
+
+# And another
+$o->create();
+ok($o->id, "CommitLink create returned another value");
+isnt($o->id, $id, "And it is different from the previous one");
+
+# Searches in general
+my $collection =  App::Changeloggr::Model::CommitLinkCollection->new(current_user => $system_user);
+$collection->unlimit;
+is($collection->count, 2, "Finds two records");
+
+# Searches in specific
+$collection->limit(column => 'id', value => $o->id);
+is($collection->count, 1, "Finds one record with specific id");
+
+# Delete one of them
+$o->delete;
+$collection->redo_search;
+is($collection->count, 0, "Deleted row is gone");
+
+# And the other one is still there
+$collection->unlimit;
+is($collection->count, 1, "Still one left");
+

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list