Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created January 14, 2024 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandfoy/26558df7292c601c6aa39c6bdf3570a5 to your computer and use it in GitHub Desktop.
Save briandfoy/26558df7292c601c6aa39c6bdf3570a5 to your computer and use it in GitHub Desktop.
Import rt.cpan.org issues to GitHub issues
use v5.26;
use open qw(:std :utf8);
use Mojo::JSON qw(decode_json);
use Mojo::UserAgent;
use Mojo::Util qw(dumper);
# See another gist to create JSON https://gist.github.com/briandfoy/656a8986e2d998122e37486df1f1f999
@ARGV = '/Users/brian/Desktop/net-ssh-perl-rt.json';
my $raw = Mojo::File->new($ARGV[0])->slurp;
my $data = decode_json($raw);
my $headers = {
Accept => 'application/vnd.github+json',
Authorization => "Bearer $ENV{GITHUB_TOKEN}",
'X-GitHub-Api-Version' => '2022-11-28',
};
# too lazy to make these settable. Left as an exercise to the programmer
my $owner = 'briandfoy';
my $repo = 'net-ssh-perl';
my $url = sprintf 'https://api.github.com/repos/%s/%s/issues', $owner, $repo;
my $ua = Mojo::UserAgent->new();
foreach my $ticket_id ( sort { $a <=> $b } keys %$data ) {
my $h = $data->{$ticket_id};
my $body =<<~"HERE";
This ticket was imported from [rt.cpan.org $ticket_id]($h->{url})
* Requestor: $h->{requestor}
* Date: $h->{date}
* Original subject: $h->{subject}
* Original link: [rt.cpan.org $ticket_id]($h->{url})
___
$h->{original}
HERE
my $json = {
title => $data->{$ticket_id}{subject},
body => $body,
labels => [ "imported from rt.cpan.org" ],
};
my $tx = $ua->post($url => $headers => json => $json);
if( $tx->res->is_success ) {
say "\tOK";
}
else {
say $tx->res->body;
}
sleep 10;
}
__END__
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/issues \
-d '{"title":"Found a bug","body":"I'\''m having a problem with this.","assignees":["octocat"],"milestone":1,"labels":["bug"]}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment