Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Getting close to a working prototype
  • Loading branch information
AlexDaniel committed Feb 8, 2019
1 parent b0c62cc commit b8f8818
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
41 changes: 37 additions & 4 deletions bin/update-issues.p6 100644 → 100755
@@ -1,11 +1,44 @@
#!/usr/bin/env perl6

use JSON::Fast;
use Unbitrot::Utils;

unit main multi MAIN(
unit sub MAIN(
I know what I'm doing,
$token,
IO() $blin-data = data.json,
IO() :$blin-data = data.json,
IO() :$template = template.md,
);

my $data = from-json slurp $blin-data;

my @issues = get-issues;
my %modules = from-json slurp $blin-data;
my @issues = get-issues $token;
my $template-text = slurp $template;

for @issues -> $issue {
.<ticket> = $issue with %modules{$issue<title>};
}

for %modules.keys.sort -> $name {
my $module = %modules{$name};
my $ticket = $module<ticket>;
if $module<status> eq OK {
if $ticket and $ticket<state> ne closed {
note Closing issue {$ticket<number>} for $name;
# close-single-issue $ticket<url>, $token
}
} else {
if not $ticket or $ticket<state> eq closed {
note Creating new issue for $name;

my $text = $template-text;
$text .= subst: 「MODULE」, 42;
$text .= subst: 「MODULE-URL」, 42; # https://modules.perl6.org/dist/$module
$text .= subst: 「OUTPUT」, 42;
$text .= subst: 「PING-AUTHOR」, 42;
$text .= subst: 「PREVIOUS-TICKET」, 42;

# submit-issue $token, $text
}
}
}
17 changes: 3 additions & 14 deletions lib/Unbitrot/Utils.pm6
Expand Up @@ -8,7 +8,7 @@ constant \url = ‘https://api.github.com/repos/perl6/ecosystem-unbitrot/issues?

#| gets the issues from the repo
sub get-issues($token) is export {
my @tickets;
my @issues;
my $cur-url = url;
loop {
note $cur-url;
Expand All @@ -18,26 +18,15 @@ sub get-issues($token) is export {
Authorization => token $token,
],
;
@tickets.append: @(await $resp.body);
@issues.append: @(await $resp.body);
my $next = $resp.headers.first(*.name eq Link).?value;
if $next && $next ~~ /‘<’ (<-[>]>*?) ‘>; rel="next"’/ {
$cur-url = ~$0;
next
}
last
}
my %tickets = @tickets.map: { $_<url> => $_ };
%tickets;
}

#| Issue per module
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;
}
return %issue-per-module;
@issues;
}

#| Edit issue
Expand Down
4 changes: 3 additions & 1 deletion template.md
@@ -1,4 +1,4 @@
Module [$module](https://modules.perl6.org/dist/$module) cannot be
Module [「MODULE」](「MODULE-URL」) cannot be
installed, perhaps it has some failing tests.

* Tickets are opened/closed in this repo automatically (though not
Expand Down Expand Up @@ -32,3 +32,5 @@ Output:
````````````````````````````````````````````````````````

「PING-AUTHOR」

「PREVIOUS-TICKET」

0 comments on commit b8f8818

Please sign in to comment.