[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#808790: fakeupstream.cgi: add redirector for crates.io website



Package: qa.debian.org
Severity: wishlist
Tags: patch

The standard packaging tool for the Rust programming language ("cargo") distributes package sources via the https://crates.io/ website.  Unfortunately for uscan, the dynamic content for this website is all served via JSON.  According to a discussion with upstream[*], the upstream infrastructure isn't able to easily serve HTML-formatted dynamic content at this time.

The attached patch adds a wrapper to fakeupstream.cgi to reformat the relevant "versions" JSON blob as uscan-friendly HTML.  Please apply.

[*] Upstream discussion: https://github.com/rust-lang/crates.io/issues/238

Thanks!
 - Gus
Index: fakeupstream.cgi
===================================================================
--- fakeupstream.cgi	(revision 3453)
+++ fakeupstream.cgi	(working copy)
@@ -46,6 +46,7 @@
 my $project_char_re = '[a-zA-Z0-9\-]';
 my $pypi_project_char_re = '[a-zA-Z0-9\-\.]';
 my $npmjs_project_char_re = '[a-zA-Z0-9\-\.]';
+my $cratesio_project_char_re = '[a-zA-Z0-9_.-]';
 my $hg_repository_re = '[a-zA-Z0-9\.\-:/]+';
 my $href_char_re    = '[a-zA-Z0-9\-\._/]';
 my $href_p_char_re    = '[a-zA-Z0-9\-\._/%]';
@@ -735,6 +736,35 @@
 	} );
 }
 
+# https://packages.qa.debian.org/c/cargo.html
+# https://crates.io/crates/cargo
+# http://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/cargo
+if( $upstream_param =~ m%^crates\.io/($cratesio_project_char_re+)% )
+{
+    my $project = $1;
+
+    my $url = "https://crates.io/api/v1/crates/$project/versions";;
+    my $ua = LWP::UserAgent->new;
+    my $response = $ua->get( $url );
+    return_error( "failed to read $url : $response->status_line" ) if( not $response->is_success );
+    my $json = JSON::decode_json( $response->decoded_content );
+    print $q->header;
+    print $q->start_html;
+    print $q->start_ul;
+    foreach my $vers ( @{$json->{"versions"}} )
+    {
+	next if $vers->{"yanked"};
+	my $version = $vers->{"num"};
+	my $dl_uri = URI->new_abs($vers->{"dl_path"}, $url);
+
+	print $q->li( $q->a( { -href => $dl_uri }, $version ) );
+    }
+
+    print $q->end_ul;
+    print $q->end_html;
+    exit 0;
+}
+
 my %upstream_info_per_package =
 (
 	'stopwatch' =>

Reply to: