forked from pool/vim-plugins
check_for_updates: rewrite to py
Easier rpm parsing. And add suport for github tokens.
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
use Data::Dumper;
|
||||
use JSON;
|
||||
use LWP::UserAgent;
|
||||
|
||||
open(SPEC, '<vim-plugins.spec') or die "cannot open spec";
|
||||
my $spec;
|
||||
{
|
||||
local $/ = undef;
|
||||
$spec = <SPEC>;
|
||||
}
|
||||
close(SPEC);
|
||||
|
||||
my $child = open(SPEC, '-|', qw|rpm -E|, $spec) // die "cannot run rpm";
|
||||
exit 0 unless ($child);
|
||||
|
||||
my $ua = LWP::UserAgent->new;
|
||||
my $json = JSON->new->allow_nonref;
|
||||
|
||||
while (<SPEC>) {
|
||||
chomp;
|
||||
my ($org, $repo, $rel, $ver) = (m@^Source\d+:\s+https://github\.com/([^/]+)/([^/]+)/(?:archive/refs/tags|releases/download/([^/]+))/([^/]+)\.tar\.gz#@);
|
||||
next unless defined $ver;
|
||||
$ver = $rel if defined $rel;
|
||||
|
||||
my $req_url = defined $rel ? 'releases/latest' : 'tags';
|
||||
my $req = HTTP::Request->new(GET => "https://api.github.com/repos/$org/$repo/$req_url");
|
||||
my $res = $ua->request($req);
|
||||
die "bad HTTP reply for $org/$repo -- \"" . $res->status_line . '"' unless ($res->is_success);
|
||||
|
||||
my $j = $json->decode($res->content);
|
||||
$j = @{$j}[0] unless (defined $rel);
|
||||
my $ver2 = $j->{'name'} || $j->{'tag_name'};
|
||||
|
||||
if ($ver2 ne $ver) {
|
||||
print "$org, $repo, $ver -> $ver2\n";
|
||||
}
|
||||
}
|
||||
close(SPEC);
|
||||
|
||||
1;
|
55
check_for_updates.py
Executable file
55
check_for_updates.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import requests
|
||||
import rpm
|
||||
import sys
|
||||
from termcolor import colored
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-t', '--token')
|
||||
args = parser.parse_args()
|
||||
|
||||
ts = rpm.TransactionSet()
|
||||
spec = ts.parseSpec('vim-plugins.spec')
|
||||
|
||||
ver_re = re.compile(r"https://github\.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(?:archive/refs/tags|releases/download/(?P<rel>[^/]+))/(?P<ver>[^/]+)\.tar\.gz#")
|
||||
|
||||
for src in spec.sources:
|
||||
if src[2] != 1: # Source
|
||||
continue
|
||||
|
||||
m = ver_re.match(src[0])
|
||||
if m is None:
|
||||
continue
|
||||
|
||||
org = m.group('org')
|
||||
repo = m.group('repo')
|
||||
rel = m.group('rel')
|
||||
ver = m.group('ver')
|
||||
if ver is None:
|
||||
continue
|
||||
|
||||
print(colored(f"Checking {org}/{repo} (current rel='{rel}' ver='{ver}')", 'green'))
|
||||
|
||||
url_suffix = 'tags'
|
||||
if rel is not None:
|
||||
url_suffix = 'releases/latest'
|
||||
ver = rel
|
||||
|
||||
headers = {}
|
||||
if args.token:
|
||||
headers['Authorization'] = f"token {args.token}"
|
||||
get = requests.get(f"https://api.github.com/repos/{org}/{repo}/{url_suffix}", headers=headers)
|
||||
if not get.ok:
|
||||
print(f"bad HTTP reply for {org}/{repo}: {get.status_code} {get.reason}")
|
||||
sys.exit(1)
|
||||
|
||||
js = get.json()
|
||||
if rel is None:
|
||||
js = js[0] # take the latest tag only
|
||||
|
||||
ver2 = js['name'] or js['tag_name']
|
||||
if ver != ver2:
|
||||
print(colored(f"\t{ver2} available", 'red'))
|
@@ -117,7 +117,7 @@ Source105: cscope-maps-%{cscope_maps_version}.tar.xz
|
||||
Source200: gitrebase.vim
|
||||
Source300: global-rsync-filter
|
||||
Source1000: https://raw.githubusercontent.com/openSUSE/pack-tools/master/contrib/vim/spec.snippets
|
||||
Source1001: check_for_updates.pl
|
||||
Source1001: check_for_updates.py
|
||||
Patch0: salt-syntax-avoid-multiline-lets.patch
|
||||
Patch1: locateopen-1.3-locate-support.patch
|
||||
Patch2: showmarks-signs.patch
|
||||
|
Reference in New Issue
Block a user