Arepa/Web/Incoming.pm untested

filter: Statementstmt 0.0% 0 / 79 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 131 CC 13 SCAR 34.7
CC
13
Cov
0%
_approve_package
72.0
process
20.0
_remove_uploaded_package
12.0
CRAP 32.1
1 package Arepa::Web::Incoming;
2  
3 use strict;
4 use warnings;
5  
6 use base 'Arepa::Web::Base';
7  
8 use File::Basename;
9 use Parse::Debian::PackageDesc;
10 use Arepa::Repository;
11 use Arepa::BuilderFarm;
12  
13 sub _approve_package {
14 my ($self, $changes_file_path, %opts) = @_;
15  
16 # Only get the file basename, and search for it in the incoming directory
17 my $path = $self->config->get_key('upload_queue:path') . "/" .
18 basename($changes_file_path);
19 my $changes_file = Parse::Debian::PackageDesc->new($path);
20 my $distribution = $changes_file->distribution;
21  
22 # Add the source package to the repo
23 my ($source_file_path) = grep /\.dsc$/, $changes_file->files;
24 my $repository = Arepa::Repository->new($self->config_path);
25 my $farm = Arepa::BuilderFarm->new($self->config_path);
26  
27 my ($arch) = grep { $_ ne 'source' } $changes_file->architecture;
28 my $canonical_distro;
29 eval {
30 $canonical_distro = $farm->canonical_distribution($arch,
31 $distribution);
32 };
33 if ($@) {
34 $self->_add_error($@);
35 return 0;
36 }
37  
38 my $source_pkg_id;
39 if ($canonical_distro) {
40 $source_pkg_id = $repository->insert_source_package(
41 $self->config->get_key('upload_queue:path').
42 "/".$source_file_path,
43 $distribution,
44 canonical_distro => $canonical_distro,
45 %opts);
46  
47 if ($source_pkg_id) {
48 if (! $self->config->key_exists('repository:signature:id') ||
49 $self->config->get_key('repository:signature:id') ne
50 'unsigned') {
51 my $sign_cmd = "sudo -H -u arepa-master arepa sign >/dev/null";
52 if (system($sign_cmd) != 0) {
53 $self->_add_error("Couldn't sign repositories, check " .
54 "your 'sudo' configuration and " .
55 "the README file");
56 }
57 }
58 }
59 else {
60 $self->_add_error("Couldn't approve source package " .
61 "'$source_file_path'.",
62 $repository->last_cmd_output);
63 }
64 }
65 else {
66 $self->_add_error("Can't find any builder for $source_file_path " .
67 "($distribution/$arch)");
68 }
69  
70 if ($self->_error_list) {
71 return 0;
72 }
73 else {
74 # If everything went fine, add the source package to the compilation
75 # queue
76 $farm->request_package_compilation($source_pkg_id);
77  
78 $self->_remove_uploaded_package($path);
79  
80 if ($self->_error_list) {
81 return 0;
82 }
83 }
84  
85 return 1;
86 }
87  
88 sub _remove_uploaded_package {
89 my ($self, $changes_file_path) = @_;
90  
91 my $changes_file = Parse::Debian::PackageDesc->new($changes_file_path);
92 # Remove all files from the pending queue
93 # Files referenced by the changes file
94 foreach my $file ($changes_file->files) {
95 my $file_path = $self->config->get_key('upload_queue:path')."/".$file;
96 if (-e $file_path && ! unlink($file_path)) {
97 $self->add_error("Can't delete '$file_path'.");
98 }
99 }
100 # Changes file itself
101 if (! unlink($changes_file_path)) {
102 $self->add_error("Can't delete '$changes_file_path'.");
103 }
104 }
105  
106 sub process {
107 my ($self) = @_;
108  
109 $self->_only_if_admin(sub {
110 my @field_ids = map { /^package-(\d+)$/; $1 }
111 grep /^package-\d+$/,
112 keys %{$self->tx->req->params->to_hash};
113 foreach my $field_id (@field_ids) {
114 if ($self->param("approve_all") ||
115 $self->param("approve-$field_id")) {
116 $self->_approve_package(
117 $self->param("package-$field_id"),
118 priority => $self->param("priority-$field_id"),
119 section => $self->param("section-$field_id"),
120 comments => $self->param("comments-$field_id"));
121 }
122 elsif ($self->param("reject-$field_id")) {
123 my $changes_file_path = $self->param("package-$field_id");
124 my $path = $self->config->get_key('upload_queue:path')."/".
125 basename($changes_file_path);
126 $self->_remove_uploaded_package($path);
127 }
128 }
129 if ($self->_error_list) {
130 $self->vars(errors => [$self->_error_list]);
131 $self->render('error');
132 }
133 else {
134 $self->redirect_to('home');
135 }
136 });
137 }
138  
139 1;