use warnings;
use Data::Dumper;
use CIL::Issue;
+use CIL::Comment;
use Term::CallEditor;
use File::Touch;
use File::Glob ':glob';
add => 1,
show => 1,
edit => 1,
+ comment => 1,
};
my $new_issue_text = <<"EOF";
[Issue]
-
Summary =
Status =New
CreatedBy =$ENV{GIT_AUTHOR_NAME} <$ENV{GIT_AUTHOR_EMAIL}>
END_OF_DESCRIPTION
EOF
+my $add_comment_text = <<"EOF";
+[Comment]
+CreatedBy = $ENV{GIT_AUTHOR_NAME} <$ENV{GIT_AUTHOR_EMAIL}>
+Description = <<END_OF_DESCRIPTION
+
+END_OF_DESCRIPTION
+EOF
+
## ----------------------------------------------------------------------------
{
my ($issue_name) = @ARGV;
edit($issue_name);
}
+ elsif ( $command eq 'comment' ) {
+ my ($issue_name) = @ARGV;
+ comment($issue_name);
+ }
else {
fatal("program error when trying command '$command'");
fatal("couldn't parse issue: $@");
}
unless ( defined $issue_edited ) {
- fatal("couldn't parse issue (program error)");
+ fatal("couldn't create issue (program error)");
}
# for the fields we're interested in, set them
}
}
+sub comment {
+ my ($issue_name) = @_;
+
+ my $issue = CIL::Issue->new_load_issue($issue_name);
+ unless ( defined $issue ) {
+ fatal("Couldn't load issue '$issue'");
+ }
+
+ # read in the new issue text
+ my $fh = solicit( $add_comment_text );
+
+ my $cfg;
+ eval {
+ $cfg = Config::IniFiles->new( -file => $fh );
+ };
+ if ( $@ ) {
+ fatal("couldn't parse comment: $@");
+ }
+
+ unless ( defined $cfg ) {
+ fatal("not a valid inifile");
+ }
+
+ my $comment = CIL::Comment->new();
+ foreach my $field ( qw(CreatedBy Description) ) {
+ # modify the data directly, otherwise Updated will kick in
+ my $value = $cfg->val( 'Comment', $field );
+ next unless defined $value;
+
+ $value =~ s/^\s*//;
+ $value =~ s/\s*$//;
+ $comment->set_no_update($field, $value);
+ }
+
+ # tell the comment when it was inserted
+ $comment->inserted;
+
+ # add the comment to the issue, update it's timestamp and save it out
+ $issue->add_comment( $comment );
+ $issue->save();
+}
+
## ----------------------------------------------------------------------------
sub check_paths {
field( 'Labels', $issue->Labels() );
separator();
text('Description', $issue->Description());
- separator();
- title('Comments');
+ my $comments = $issue->comments();
+ foreach my $comment ( @$comments ) {
+ separator();
+ title('Comment');
+ field( 'CreatedBy', $comment->CreatedBy() );
+ field( 'Inserted', $comment->Inserted() );
+ field( 'Updated', $comment->Inserted() );
+ text('Description', $comment->Description());
+ }
separator();
}
croak "filename '$filename' does no exist";
}
- my $issue = CIL::Issue->new();
- $issue->{data} = LoadFile( $filename );
- return $issue;
+ my $data = LoadFile( $filename );
- my $cfg = Config::IniFiles->new( -file => $filename );
- unless ( defined $cfg ) {
- croak("not a valid inifile");
- }
+ my $issue = CIL::Issue->new();
- # my $issue = CIL::Issue->new();
+ # do the issue
foreach my $field ( qw(Summary Name Description CreatedBy Status Labels Inserted Updated) ) {
# modify the data directly, otherwise Updated will kick in
- $issue->{data}{$field} = $cfg->val( 'Issue', $field );
+ $issue->{data}{$field} = $data->{$field};
}
- $issue->{data}{Comments} = [];
- # set the issue Name
+ # now the comments
+ foreach my $c ( @{$data->{comments}} ) {
+ my $comment = CIL::Comment->new();
+ foreach my $field ( qw(CreatedBy Inserted Updated Description) ) {
+ # modify the data directly, otherwise Updated will kick in
+ $comment->set_no_update($field, $c->{$field});
+ }
+ push @{$issue->{comments}}, $comment;
+ }
$issue->{data}{Name} = $name;
return $issue;
return $issue;
}
+sub comments {
+ my ($self) = @_;
+ return $self->{comments};
+}
+
+sub add_comment {
+ my ($self, $comment) = @_;
+
+ croak "can only add comments of type CIL::Comment"
+ unless ref $comment eq 'CIL::Comment';
+
+ push @{$self->{comments}}, $comment;
+}
+
sub save {
my ($self) = @_;
my $name = $self->Name;
my $filename = "issues/$name.yaml";
- DumpFile($filename, $self->{data});
+ my $data = {};
+ %$data = ( %{$self->{data}});
+ foreach my $comment ( @{$self->{comments}} ) {
+ push @{$data->{comments}}, $comment->{data};
+ }
+ DumpFile($filename, $data);
}
sub reset {
}
}
-sub add_comment {
- my ($self, $comment_h) = @_;
-
- my $comment = CIL::Comment->new($comment_h);
-
-}
-
## ----------------------------------------------------------------------------
1;
## ----------------------------------------------------------------------------