Commit d15057af authored by Kiyoshi Aman's avatar Kiyoshi Aman
Browse files

Chessa::Bug::Adelie: iteratively load projects, I guess

parent 53dce30e
......@@ -25,18 +25,7 @@ sub new {
$self->{irc} = $self->{conf}{irc};
$self->{projects} = {};
$http->do_request(
uri => 'https://git.adelielinux.org/api/v4/projects',
on_response => sub {
my ($response) = @_;
$self->log("Fetched projects.");
$self->projects($response);
}, on_error => sub {
my ($error) = @_;
$self->error("Couldn't fetch projects: $error");
croak $error;
}
);
$self->load_projects($http, 'https://git.adelielinux.org/api/v4/projects');
return bless $self, $class || ref $class;
}
......@@ -57,18 +46,37 @@ sub error {
$self->log($msg, $on_info, $errors);
}
sub load_projects {
my $self = shift;
my ($http, $uri) = @_;
$http->do_request(
uri => $uri,
on_response => sub {
my ($response) = @_;
$self->log("Fetched projects from $uri");
$self->projects($http, $response);
}, on_error => sub {
my ($error) = @_;
$self->error("Couldn't fetch projects: $error");
croak $error;
}
);
}
sub projects {
my $self = shift;
my ($response) = @_;
my ($http, $response) = @_;
my $json = JSON::MaybeXS->new->utf8->decode($response->decoded_content);
my %projects;
for my $item (@{ $json }) {
$projects{$item->{path_with_namespace}} = $item->{id};
$self->{projects}{$item->{path_with_namespace}} = $item->{id};
$self->log($item->{path_with_namespace} . ' = ' . $item->{id});
}
$self->{projects} = \%projects;
my $link = $response->header('Link');
if (length($link)) {
$self->load_projects($http, $link);
}
}
sub wants {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment