Created
March 31, 2012 14:58
-
-
Save tron1point0/2265848 to your computer and use it in GitHub Desktop.
Redmine TODO list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.14; | |
use warnings; | |
use LWP::UserAgent; | |
use List::MoreUtils qw(part); | |
use YAML qw(LoadFile); | |
use JSON::XS qw(decode_json); | |
use Text::FormatTable; | |
use Term::ReadKey; | |
die join "",<DATA> if @ARGV && $ARGV[0] =~ /-h/; | |
my @confs = reverse grep {defined && -r} ( | |
shift @ARGV, | |
qw(.todo.yml .todo), | |
"$ENV{XDG_CONFIG_HOME}/todo/global.yml" | |
); | |
die "Couldn't find suitable configuration." unless @confs; | |
my %config = map {%{LoadFile $_}} @confs; | |
my $ua = LWP::UserAgent->new; | |
$ua->default_header( | |
content_type => 'application/json', | |
':X-Redmine-API-Key' => $config{key}, | |
); | |
@config{qw(base project)} = ($1,$2) if | |
$config{project} =~ m{(http://[^/]+)/projects/([^/]+)}; | |
my $res = $ua->get("$config{base}/issues.json?project_id=$config{project}"); | |
die join "\n", | |
$res->status_line, | |
$res->{_request}->headers->as_string, | |
$res->headers->as_string, | |
$res->content, "" unless $res->is_success; | |
my @fields = @{$config{fields}}; | |
my @issues = | |
map {[ | |
map {{map {ref $_ ? $_->{name} : $_} %$_}} | |
sort {$a->{$config{sort}}{id} <=> $b->{$config{sort}}{id}} | |
@$_]} | |
grep {defined} | |
part {$_->{$config{group}}{id}} | |
@{decode_json($res->content)->{issues}}; | |
my $table = Text::FormatTable->new(join ' ',('l')x@fields); | |
$table->head(map {ucfirst} @fields); | |
$table->row(@$_) for map { | |
map {my %i=%$_; [map {$i{$_}} @fields]} @$_ | |
} @issues; | |
print $table->render((GetTerminalSize)[0]); | |
__DATA__ | |
todo: fetch the current project's issue list from Redmine | |
USAGE: todo [config_file] | |
config_file: If not passed, assumed to be ./.todo.yml, ./.todo or | |
$XDG_CONFIG_HOME/todo/global.yml. See CONFIG FILE section for configuration | |
options. | |
CONFIG FILE: | |
Between all the config files, you must specify the following: | |
key: | |
Your Redmine API key, which you can find on the right side of | |
/my/account on your Redmine instance, under "API access key" | |
fields: | |
A list of the fields you want to see in the results | |
group: | |
The field by which to group the results | |
sort: | |
The field by which to sort the results | |
project: | |
The project from which to fetch the issue list. You can specify the | |
full URL and forego specifying base, or you can specify base and use | |
the human-readable project identifier or the project's ID | |
You may also need to specify: | |
base: | |
The base URL of your Redmine instance. Optional if you use the full URL | |
in project. | |
I put key, base, fields, group, and sort in $XDG_CONFIG_HOME/todo/global.yml | |
and project in ./.todo.yml, but that's just me. Settings in config_file | |
override settings in ./.todo.yml, which override settings in ./.todo, which | |
override settings in the global file. |
This should also try to get the project's name based on the directory you're in. I'm thinking it should find the nearest parent with a .git
child and try to use it as the project name (but only if no project name is given).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There was no reason for this to have been a private gist.