Package: qa.debian.org Severity: wishlist Tags: patch X-Debbugs-Cc: zixing....@canonical.com
Hi Debian QA Team, I would like to see a fakeupstream service implemented for https://static.rust-lang.org/dist so that the debian/watch file inside the rustc package could be simplified and actually useful for checking new releases. Attached below is a patch that I proposed to add the said functionality. You can find the same patch at: https://salsa.debian.org/qa/qa/-/merge_requests/48 if you prefer using Debian Salsa to merge the patch/merge request. Thanks, Zixing
>From 9bbd2ecffe31822cf2a77ed0ce9ed69f78931aee Mon Sep 17 00:00:00 2001 From: liushuyu <liushuyu...@gmail.com> Date: Mon, 23 Oct 2023 22:27:29 -0600 Subject: [PATCH] cgi-bin/fakeupstream.cgi: add support ... ... for monitoring Rust releases --- cgi-bin/fakeupstream.cgi | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/cgi-bin/fakeupstream.cgi b/cgi-bin/fakeupstream.cgi index c13538e8..718b2540 100755 --- a/cgi-bin/fakeupstream.cgi +++ b/cgi-bin/fakeupstream.cgi @@ -26,6 +26,8 @@ use JSON; use File::Temp qw/ tempdir /; use Date::Format; use Date::Parse; +use Time::Piece; +use Time::Seconds qw(ONE_DAY); use Dpkg::Version; use threads; use constant MAX_THREADS => 3; @@ -1110,6 +1112,81 @@ elsif( $upstream_param =~ m%^google-fonts/($project_char_re+)/($project_char_re+ exit 0; } +elsif( $upstream_param eq 'rustc' ) +{ + my $ua = LWP::UserAgent->new; + + sub fetch_rust_github_tags($) { + my $ua = shift; + my @versions; + my $page_number = 1; + my $per_page = 100; + my $url = "https://api.github.com/repos/rust-lang/rust/tags?per_page=$per_page"; + while (1) { + my $response = $ua->get( "$url&page=$page_number" ); + return_error( "failed to read $url : $response->status_line" ) if( not $response->is_success ); + my $json = JSON::decode_json( $response->decoded_content ); + foreach my $version (@{$json}) { + my $version_name = $version->{"name"}; + if ( $version_name =~ /^\d+\.\d+\.\d+$/ ) { + push @versions, $version_name; + } + } + last if (scalar @versions) < $per_page; + } + $page_number++; + return @versions; + } + + sub fetch_rust_last_unstable_date($$) { + my $ua = shift; + my $channel = shift; + my $url = "https://static.rust-lang.org/dist/channel-rust-$channel-date.txt"; + my $response = $ua->get ( $url ); + return_error( "failed to read $url : $response->status_line" ) unless( $response->is_success ); + return $response->decoded_content; + } + + sub make_header($) { + my $channel = shift; + my $title = "Rust toolchain version listing ($channel)"; + print $q->header; + print $q->start_html({ -title => $title }); + print $q->h1($title) . "\n"; + print $q->start_ul; + } + + $type_param = 'stable' unless $type_param; + my $channel = $type_param; + + if ($channel eq 'stable') { + my @tags = fetch_rust_github_tags( $ua ); + make_header($channel); + foreach my $version (@tags) { + print $q->li( $q->a( { -href => "https://static.rust-lang.org/dist/rustc-$version-src.tar.xz" }, $version ) ); + } + } else { + my $last_date = fetch_rust_last_unstable_date ( $ua, $channel ); + my $limit = 10; + make_header($channel); + print $q->p( "For unstable channels, only releases within the last $limit days are listed." ); + while ($limit > 0) { + my $response = $ua->get( "https://static.rust-lang.org/dist/$last_date/channel-rust-$channel.toml" ); + if ($response->is_success()) { + if ($response->decoded_content =~ /(1\.\d+\.\d+-(?:nightly|beta)(?:\.\d+)?\s+\([0-9a-f]{9}\s+\d+-\d+-\d+\))/) { + print $q->li( $q->a( { -href => "https://static.rust-lang.org/dist/$last_date/rustc-$channel-src.tar.xz" }, $1 ) ); + } + } + my $next_last_date = Time::Piece->strptime($last_date, "%Y-%m-%d") - ONE_DAY; + $last_date = $next_last_date->ymd; + $limit--; + } + } + + print $q->end_ul; + print $q->end_html; + exit 0; +} my %upstream_info_per_package = ( -- GitLab