Skip to content

Commit

Permalink
Adds mapping per module
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Feb 8, 2019
1 parent a9df30b commit eb2b08c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
32 changes: 28 additions & 4 deletions lib/Utils.pm6
Expand Up @@ -2,6 +2,8 @@ use v6;

unit module Utils;

use Cro::HTTP::Client;

constant \url = https://api.github.com/repos/perl6/ecosystem-unbitrot/issues?state=all;

#| gets the issues from the repo
Expand All @@ -10,7 +12,6 @@ sub get-issues($token) is export {
my $cur-url = url;
loop {
note $cur-url;
use Cro::HTTP::Client;
my $resp = await Cro::HTTP::Client.get: $cur-url,
headers => [
User-Agent => perl6 ecosystem unbitrot,
Expand All @@ -25,7 +26,8 @@ sub get-issues($token) is export {
}
last
}
@tickets
my %tickets = @tickets.map: { $_<url> => $_ };
%tickets;
}

#| Returns failing modules
Expand All @@ -34,8 +36,8 @@ sub modules-not-ok( $file = "data/blin-output.txt" ) is export {
}

#! Issue per module
sub issue-per-module( @tickets, @modules --> Hash ) is export {
my %issues-by-title = @tickets.map: { $_<title> => $_<url> };
sub issue-per-module( %tickets, @modules --> Hash ) is export {
my %issues-by-title = %tickets.keys.map: { %tickets{$_}<title> => $_ };
my %issue-per-module;
for @modules -> $m {
%issue-per-module{$m} = %issues-by-title{$m}:exists??%issues-by-title{$m}!!Nil;
Expand All @@ -45,3 +47,25 @@ sub issue-per-module( @tickets, @modules --> Hash ) is export {
}

#| Edit issue
sub open-single-issue(:$url, :$token) {
patch( :$url, :$token, body => { state => 'open' } );
}

sub close-single-issue(:$url, :$token) {
patch( :$url, :$token, body => { state => 'close' } ),
}

#| patch with cro
sub patch(:$url, :$token, :$body ) {

my $resp = await Cro::HTTP::Client.patch: $url,
headers => [
User-Agent => perl6 ecosystem unbitrot,
Authorization => token $token,
],
content-type => application/json,
body => $body,
;

return await $resp.body;
}
11 changes: 6 additions & 5 deletions t/1.t6
Expand Up @@ -10,15 +10,16 @@ ok Utils::url, "{Utils::url} is declared";
my $file = "data/blin-output.txt".IO.e??"data/blin-output.txt"!!"../data/blin-output.txt";
my @not-ok-modules = modules-not-ok( $file );
ok @not-ok-modules, "Some modules are not OK";
my @tickets;
my %tickets;
if %*ENV{'GH_TOKEN'} {
@tickets = get-issues( %*ENV{'GH_TOKEN'} );
ok @tickets, "Downloads tickets";
cmp-ok @tickets.elems, ">", 1, "There are tickets";
my %mapping = issue-per-module( @tickets, @not-ok-modules );
%tickets = get-issues( %*ENV{'GH_TOKEN'} );
ok %tickets, "Downloads tickets";
cmp-ok %tickets.elems, ">", 1, "There are tickets";
my %mapping = issue-per-module( %tickets, @not-ok-modules );
ok %mapping, "Mapping done";
dd %mapping;
} else {
skip "No token for issues",1;
}

done-testing;

0 comments on commit eb2b08c

Please sign in to comment.