Lines 22-27
use utf8;
Link Here
|
22 |
use Getopt::Long qw(GetOptionsFromArray); |
22 |
use Getopt::Long qw(GetOptionsFromArray); |
23 |
use Try::Tiny qw(catch try); |
23 |
use Try::Tiny qw(catch try); |
24 |
use File::Temp; |
24 |
use File::Temp; |
|
|
25 |
|
25 |
use GitBz::Git; |
26 |
use GitBz::Git; |
26 |
use GitBz::Exception; |
27 |
use GitBz::Exception; |
27 |
use GitBz::StatusWorkflow; |
28 |
use GitBz::StatusWorkflow; |
Lines 90-106
sub attach_patches {
Link Here
|
90 |
my ( $self, $bug_ref, $commits, $opts ) = @_; |
91 |
my ( $self, $bug_ref, $commits, $opts ) = @_; |
91 |
|
92 |
|
92 |
my $client = $self->{commands}->{client}; |
93 |
my $client = $self->{commands}->{client}; |
93 |
my $bug = $client->get_bug($bug_ref); |
94 |
my $bug = $client->get_bug($bug_ref); |
94 |
|
95 |
|
95 |
my $is_first = 1; |
96 |
my $is_first = 1; |
96 |
for my $commit (@$commits) { |
97 |
for my $commit (@$commits) { |
97 |
my $patch = GitBz::Git->format_patch( $commit->{id} . '^..' . $commit->{id} ); |
98 |
my $patch = GitBz::Git->format_patch( $commit->{id} . '^..' . $commit->{id} ); |
98 |
my $filename = sprintf( "%s.patch", substr( $commit->{id}, 0, 7 ) ); |
99 |
my $filename = sprintf( "%s.patch", substr( $commit->{id}, 0, 7 ) ); |
99 |
my $description = $commit->{subject}; |
100 |
my $description = $commit->{subject}; |
100 |
my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} ); |
101 |
my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} ); |
101 |
my $comment = $body || "Patch from commit " . substr( $commit->{id}, 0, 7 ); |
102 |
my $comment = $body || "Patch from commit " . substr( $commit->{id}, 0, 7 ); |
102 |
my @obsoletes; |
103 |
my @obsoletes; |
103 |
|
104 |
|
104 |
if ( $opts->{edit} && $is_first ) { |
105 |
if ( $opts->{edit} && $is_first ) { |
105 |
( $description, $comment, my $obsoletes_ref ) = $self->edit_attachment_comment( $bug, $commit ); |
106 |
( $description, $comment, my $obsoletes_ref ) = $self->edit_attachment_comment( $bug, $commit ); |
106 |
@obsoletes = @$obsoletes_ref if $obsoletes_ref; |
107 |
@obsoletes = @$obsoletes_ref if $obsoletes_ref; |
Lines 111-117
sub attach_patches {
Link Here
|
111 |
$patch, |
112 |
$patch, |
112 |
$filename, |
113 |
$filename, |
113 |
$description, |
114 |
$description, |
114 |
comment => $comment, |
115 |
comment => $comment, |
115 |
obsoletes => \@obsoletes |
116 |
obsoletes => \@obsoletes |
116 |
); |
117 |
); |
117 |
|
118 |
|
Lines 126-136
sub edit_attachment_comment {
Link Here
|
126 |
my $template = ""; |
127 |
my $template = ""; |
127 |
$template .= "# Attachment to Bug $bug->{id} - $bug->{summary}\n\n"; |
128 |
$template .= "# Attachment to Bug $bug->{id} - $bug->{summary}\n\n"; |
128 |
$template .= $commit->{subject} . "\n\n"; |
129 |
$template .= $commit->{subject} . "\n\n"; |
129 |
|
130 |
|
130 |
# Add commit body as initial comment |
131 |
# Add commit body as initial comment |
131 |
my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} ); |
132 |
my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} ); |
132 |
$template .= $body . "\n\n" if $body; |
133 |
$template .= $body . "\n\n" if $body; |
133 |
|
134 |
|
134 |
# Show existing patches for obsoleting |
135 |
# Show existing patches for obsoleting |
135 |
if ( $bug->{attachments} && @{ $bug->{attachments} } ) { |
136 |
if ( $bug->{attachments} && @{ $bug->{attachments} } ) { |
136 |
for my $patch ( @{ $bug->{attachments} } ) { |
137 |
for my $patch ( @{ $bug->{attachments} } ) { |
Lines 140-156
sub edit_attachment_comment {
Link Here
|
140 |
} |
141 |
} |
141 |
$template .= "\n"; |
142 |
$template .= "\n"; |
142 |
} |
143 |
} |
143 |
|
144 |
|
144 |
# Add status options |
145 |
# Add status options |
145 |
my $client = $self->{commands}->{client}; |
146 |
my $client = $self->{commands}->{client}; |
146 |
my $workflow = GitBz::StatusWorkflow->new($client); |
147 |
my $workflow = GitBz::StatusWorkflow->new($client); |
147 |
$template .= "# Current status: $bug->{status}\n"; |
148 |
$template .= "# Current status: $bug->{status}\n"; |
148 |
my $status_values = $workflow->get_next_status_values($bug->{status}); |
149 |
my $status_values = $workflow->get_next_status_values( $bug->{status} ); |
149 |
for my $status (@$status_values) { |
150 |
for my $status (@$status_values) { |
150 |
$template .= "# Status: $status\n"; |
151 |
$template .= "# Status: $status\n"; |
151 |
} |
152 |
} |
152 |
$template .= "\n"; |
153 |
$template .= "\n"; |
153 |
|
154 |
|
154 |
# Add patch complexity options |
155 |
# Add patch complexity options |
155 |
my $complexity = $bug->{cf_patch_complexity} || ""; |
156 |
my $complexity = $bug->{cf_patch_complexity} || ""; |
156 |
$template .= "# Current patch-complexity: $complexity\n"; |
157 |
$template .= "# Current patch-complexity: $complexity\n"; |
Lines 161-179
sub edit_attachment_comment {
Link Here
|
161 |
} |
162 |
} |
162 |
} |
163 |
} |
163 |
$template .= "\n"; |
164 |
$template .= "\n"; |
164 |
|
165 |
|
165 |
# Add depends options |
166 |
# Add depends options |
166 |
my $depends = $bug->{depends_on} || []; |
167 |
my $depends = $bug->{depends_on} || []; |
167 |
my $depends_str = ref($depends) eq 'ARRAY' ? join(' ', @$depends) : $depends; |
168 |
my $depends_str = ref($depends) eq 'ARRAY' ? join( ' ', @$depends ) : $depends; |
168 |
$template .= "# Current depends: $depends_str\n"; |
169 |
$template .= "# Current depends: $depends_str\n"; |
169 |
$template .= "# Depends: bug xxxx\n"; |
170 |
$template .= "# Depends: bug xxxx\n"; |
170 |
$template .= "# Depends: bug yyyy\n"; |
171 |
$template .= "# Depends: bug yyyy\n"; |
171 |
$template .= "\n"; |
172 |
$template .= "\n"; |
172 |
|
173 |
|
173 |
$template .= "# Please edit the description (first line) and comment (other lines).\n"; |
174 |
$template .= "# Please edit the description (first line) and comment (other lines).\n"; |
174 |
$template .= "# Lines starting with '#' will be ignored. Delete everything to abort.\n"; |
175 |
$template .= "# Lines starting with '#' will be ignored. Delete everything to abort.\n"; |
175 |
$template .= "# To obsolete existing patches, uncomment the appropriate lines.\n"; |
176 |
$template .= "# To obsolete existing patches, uncomment the appropriate lines.\n"; |
176 |
|
177 |
|
177 |
my $edited = $self->edit_template($template); |
178 |
my $edited = $self->edit_template($template); |
178 |
return $self->parse_edited_content($edited); |
179 |
return $self->parse_edited_content($edited); |
179 |
} |
180 |
} |
Lines 198-215
sub edit_template {
Link Here
|
198 |
|
199 |
|
199 |
sub parse_edited_content { |
200 |
sub parse_edited_content { |
200 |
my ( $self, $content ) = @_; |
201 |
my ( $self, $content ) = @_; |
201 |
|
202 |
|
202 |
my @lines = split /\n/, $content; |
203 |
my @lines = split /\n/, $content; |
203 |
my @non_comment_lines = grep { !/^#/ && /\S/ } @lines; # Also filter empty lines |
204 |
my @non_comment_lines = grep { !/^#/ && /\S/ } @lines; # Also filter empty lines |
204 |
|
205 |
|
205 |
my $description = shift @non_comment_lines || ""; |
206 |
my $description = shift @non_comment_lines || ""; |
206 |
$description =~ s/^\s+|\s+$//g; |
207 |
$description =~ s/^\s+|\s+$//g; |
207 |
|
|
|
208 |
|
208 |
|
209 |
|
|
|
210 |
my @obsoletes; |
209 |
my @obsoletes; |
211 |
my @comment_lines; |
210 |
my @comment_lines; |
212 |
|
211 |
|
213 |
for my $line (@non_comment_lines) { |
212 |
for my $line (@non_comment_lines) { |
214 |
if ( $line =~ /^\s*Obsoletes\s*:\s*(\d+)/ ) { |
213 |
if ( $line =~ /^\s*Obsoletes\s*:\s*(\d+)/ ) { |
215 |
push @obsoletes, $1; |
214 |
push @obsoletes, $1; |
Lines 217-228
sub parse_edited_content {
Link Here
|
217 |
push @comment_lines, $line; |
216 |
push @comment_lines, $line; |
218 |
} |
217 |
} |
219 |
} |
218 |
} |
220 |
|
219 |
|
221 |
my $comment = join( "\n", @comment_lines ); |
220 |
my $comment = join( "\n", @comment_lines ); |
222 |
$comment =~ s/^\s+|\s+$//g; |
221 |
$comment =~ s/^\s+|\s+$//g; |
223 |
|
222 |
|
224 |
GitBz::Exception->throw("Empty description, aborting\n") unless $description; |
223 |
GitBz::Exception->throw("Empty description, aborting\n") unless $description; |
225 |
|
224 |
|
226 |
return ( $description, $comment, \@obsoletes ); |
225 |
return ( $description, $comment, \@obsoletes ); |
227 |
} |
226 |
} |
228 |
|
227 |
|