Devel-Cover-Report-Coveralls

 view release on metacpan or  search on metacpan

lib/Devel/Cover/Report/Coveralls.pm  view on Meta::CPAN

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    $config = YAML::LoadFile($CONFIG_FILE);
}
 
my $json = {};
$json->{repo_token} = $config->{repo_token} if $config->{repo_token};
$json->{repo_token} = $ENV{COVERALLS_REPO_TOKEN} if $ENV{COVERALLS_REPO_TOKEN};
$json->{flag_name} = $ENV{COVERALLS_FLAG_NAME} if $ENV{COVERALLS_FLAG_NAME};
$json->{parallel} = \1 if $ENV{COVERALLS_PARALLEL};
 
my $is_travis;
my $endpoint = ($ENV{COVERALLS_ENDPOINT} || $API_ENDPOINT) . $API_ENDPOINT_STEM;
if ($ENV{TRAVIS}) {
    $is_travis = 1;
    $json->{service_name} = $config->{service_name} || 'travis-ci';
    $json->{service_job_id} = $ENV{TRAVIS_JOB_ID};
    if($ENV{TRAVIS_PULL_REQUEST} && $ENV{TRAVIS_PULL_REQUEST} ne 'false'){
        $json->{service_pull_request} = $ENV{TRAVIS_PULL_REQUEST};
    }
} elsif ($ENV{CIRCLECI}) {
    $json->{service_name} = 'circleci';
    $json->{service_number} = $ENV{CIRCLE_WORKFLOW_ID};

lib/Devel/Cover/Report/Coveralls.pm  view on Meta::CPAN

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
        $json->{service_name} = $config->{service_name} || $SERVICE_NAME;
        $json->{service_event_type} = 'manual';
    }
 
    die "required repo_token in $CONFIG_FILE, make sure the environment var \"COVERALLS_REPO_TOKEN\" is set or launch via Travis" if !$json->{repo_token} && !$is_travis;
 
    if (exists $ENV{COVERALLS_PERL_SERVICE_NAME} && $ENV{COVERALLS_PERL_SERVICE_NAME}) {
        $json->{service_name} = $ENV{COVERALLS_PERL_SERVICE_NAME};
    }
 
    return ($json, $endpoint);
}
 
sub _parse_line ($) {
    my $c = shift;
 
    return sub {
        my $l = $c->location(shift);
 
        return $l unless $l;

lib/Devel/Cover/Report/Coveralls.pm  view on Meta::CPAN

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
my @sfs;
 
for my $file (@{$options->{file}}) {
    my $f = $cover->file($file);
    my $c = $f->statement();
 
    push @sfs, get_source( $file, _parse_line $c );
}
 
my ($json, $endpoint) = get_config();
$json->{git} = eval { get_git_info() } || {};
$json->{source_files} = \@sfs;
 
my $coder = JSON::PP->new->ascii;
 
my $response = HTTP::Tiny->new( verify_SSL => 1 )
    ->post_form( $endpoint, { json => $coder->encode($json) } );
 
my $res = eval { decode_json $response->{content} };
 
 
print("- Report::Coveralls --------\n");
if(exists($json->{service_number})){
    print "My build number: ". $json->{service_number} ."\n";
}
if ($@) {
    print "error: " . $response->{content};

t/01_basic.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use strict;
use utf8;
 
use FindBin;
 
my $normal_endpoint = 'https://coveralls.io/api/v1/jobs';
my $endpoint_stem = '/api/v1/jobs';
 
subtest 'get_config (travis)' => sub {
    local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
    local $ENV{TRAVIS}        = 'true';
    local $ENV{TRAVIS_JOB_ID} = 100000;
    local $ENV{GITHUB_TOKEN} = undef;
    local $ENV{TRAVIS_PULL_REQUEST} = 'false';
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
    is $got->{service_job_id}, 100000, 'config service_job_id';
    is $got->{service_name}, 'travis-ci', 'config service_name';
    ok !exists $got->{service_pull_request},'not a pull request';
    local $ENV{TRAVIS_PULL_REQUEST} = '456';
    ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
    is $got->{service_pull_request},'456','config pull request';
    is $endpoint, $normal_endpoint, 'config endpoint';
};
 
subtest 'get_config extra env (travis)' => sub {
    local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
    local $ENV{TRAVIS}        = 'true';
    local $ENV{TRAVIS_JOB_ID} = 100000;
    my $diff_endpoint = 'http://localhost';
    local $ENV{COVERALLS_ENDPOINT} = $diff_endpoint;
    local $ENV{COVERALLS_FLAG_NAME} = 'Unit';
    local $ENV{GITHUB_TOKEN} = undef;
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
    is $got->{service_job_id}, 100000, 'config service_job_id';
    is $got->{service_name}, 'travis-ci', 'config service_name';
    is $got->{flag_name}, 'Unit', 'config flag_name';
    is $endpoint, $diff_endpoint . $endpoint_stem, 'new endpoint';
};
 
subtest 'get_config github' => sub {
    local $ENV{TRAVIS}          = undef; # reset on travis
    local $ENV{DRONE}           = undef; # reset on drone
    local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
    local $ENV{GITHUB_ACTIONS}  = 1;
    local $ENV{GITHUB_SHA}      = '123456789';
    local $ENV{GITHUB_TOKEN} = undef;
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
    is $got->{service_name}, 'github-actions', 'config service_name';
    is $got->{service_number}, '123456789', 'config service_number';
    is $endpoint, $normal_endpoint;
};
 
subtest 'get_config github actions improved' => sub {
    local $ENV{TRAVIS} = undef;
    local $ENV{DRONE} = undef; # reset on drone
    local $ENV{COVERALLS_REPO_TOKEN} = undef;
    local $ENV{GITHUB_TOKEN} = 'abcdef';
    local $ENV{GITHUB_RUN_ID} = '123456789';
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
    is $got->{service_name}, 'github', 'config service_name';
    is $got->{service_job_id}, '123456789', 'config service_job_id';
};
 
subtest 'get_config azure' => sub {
    local $ENV{TRAVIS}         = undef; # reset on travis
    local $ENV{GITHUB_ACTIONS} = undef; # reset on github
    local $ENV{GITHUB_REF}     = undef; # reset on github
    local $ENV{DRONE}           = undef; # reset on drone
    local $ENV{SYSTEM_TEAMFOUNDATIONSERVERURI} = 1;
    local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
    local $ENV{BUILD_SOURCEBRANCHNAME} = 'feature';
    local $ENV{BUILD_BUILDID} = '123456789';
    local $ENV{GITHUB_TOKEN} = undef;
 
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
 
    is $got->{service_name}, 'azure-pipelines', 'config service_name';
    is $got->{service_number}, '123456789', 'config service_number';
    is $endpoint, $normal_endpoint;
 
    $got = Devel::Cover::Report::Coveralls::get_git_info();
    is $got->{branch}, 'feature', 'git branch';
};
 
subtest 'get_config drone' => sub {
    local $ENV{TRAVIS}         = undef; # reset on travis
    local $ENV{GITHUB_ACTIONS} = undef; # reset on github
    local $ENV{GITHUB_REF}     = undef; # reset on github
    local $ENV{CIRCLECI}       = undef;
    local $ENV{DRONE_PULL_REQUEST} = '666';
    local $ENV{DRONE_BUILD_NUMBER} = '123';
    local $ENV{DRONE} = "drone";
    local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
 
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
 
    is $got->{service_name}, 'drone', 'config service_name';
    is $got->{service_number}, '123', 'config service_number';
    is $got->{service_pull_request}, '666', 'config service_pull_request';
    is $endpoint, $normal_endpoint;
};
 
subtest 'get_config local' => sub {
    local $ENV{TRAVIS}         = undef; # reset on travis
    local $ENV{GITHUB_ACTIONS} = undef; # reset on github
    local $ENV{DRONE}           = undef; # reset on drone
    local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
    local $ENV{GITHUB_TOKEN} = undef;
 
    my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
 
    is $got->{service_name}, 'coveralls-perl', 'config service_name';
    is $got->{service_event_type}, 'manual', 'config service_event_type';
    is $endpoint, $normal_endpoint;
};
 
subtest 'get_source' => sub {
    my $source = {
        name => "$FindBin::Bin/example.pl",
        source => <<EOS,
#!/usr/bin/env perl
use strict;
use utf8;



( run in 1.028 second using v1.01-cache-2.11-cpan-49f99fa48dc )