[Bps-public-commit] r18320 - in Net-Google-Code/branches/write: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Feb 10 07:46:19 EST 2009


Author: sunnavy
Date: Tue Feb 10 07:46:19 2009
New Revision: 18320

Modified:
   Net-Google-Code/branches/write/   (props changed)
   Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm

Log:
 r19749 at sunnavys-mb:  sunnavy | 2009-02-10 20:24:06 +0800
 added create method for issue


Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm	(original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm	Tue Feb 10 07:46:19 2009
@@ -135,6 +135,62 @@
 
 }
 
+sub create {
+    my $self = shift;
+    my %args = validate(
+        @_,
+        {
+            labels => { type => HASHREF | ARRAYREF, optional => 1 },
+            files  => { type => ARRAYREF, optional => 1 },
+            map { $_ => { type => SCALAR, optional => 1 } }
+              qw/comment summary status owner cc/,
+        }
+    );
+
+    # convert hash to array. e.g. Type => Defect to Type-Defect
+    if ( $args{labels} && ref $args{labels} eq 'HASH' ) {
+        $args{labels} =
+          [ map { $_ . '-' . $args{labels}{$_} } keys %{ $args{labels} } ];
+    }
+
+    $self->sign_in;
+    $self->fetch( 'issues/entry' );
+
+    $self->mech->form_with_fields( 'comment', 'summary' );
+
+    $self->mech->field( 'label', $args{labels} );
+
+    # the page doesn't have any file field yet :/
+    if ( $args{files} ) {
+        for ( my $i = 0; $i < scalar @{ $args{files} }; $i++ ) {
+            $self->mech->field( 'file' . ($i + 1), $args{files}[$i] );
+        }
+    }
+
+    $self->mech->submit_form(
+        fields => {
+            map { $_ => $args{$_} }
+              grep { exists $args{$_} }
+              qw/comment summary status owner cc/
+        }
+    );
+
+    my ( $contains, $id ) = $self->html_contains(
+        look_down => [ class => 'notice' ],
+        as_text   => qr/Issue\s+(\d+)/i,
+    );
+
+    if ( $contains )
+    {
+        $self->load( $id );
+        return $id;
+    }
+    else {
+        warn 'create issue failed';
+        return;
+    }
+}
+
 sub update {
     my $self = shift;
     my %args = validate(
@@ -233,11 +289,15 @@
 
 =head2 description
 
+=head2 create
+comment, summary, status, owner, cc, labels, files.
+
+Caveat: 'files' field doesn't work right now, please don't use it.
+
 =head2 update
 comment, summary, status, owner, merge_into, cc, labels, blocked_on, files.
 
-Caveat: currently, 'files' field doesn't work right now, please don't try to
-use it.
+Caveat: 'files' field doesn't work right now, please don't use it.
 
 =head1 AUTHOR
 



More information about the Bps-public-commit mailing list