#!/bin/sh

# copyright, licensing and documentation at the end

. "$DPT__SCRIPTS/lib/dpt-lib.sh"

is_key_pkg () {
	is_command curl
	local P="$1"
	local RES
	RES=$(echo "$P" | curl --silent --data-binary @- \
		https://udd.debian.org/cgi-bin/select-key-packages.cgi)
	if [ "$RES" ]
	then
		echo "✔ $P is a key package"
	else
		echo "✘ $P is no key package"
	fi
}

gitddiff() {
	local TAG
	if [ "$(dpkg-source --print-format .)" != "3.0 (native)" ]; then
		TAG=$(git rev-list -n1 --tags=debian)
	else
		TAG=$(git rev-list -n1 --tags)
	fi
	git diff --ignore-space-at-eol $TAG
}

header "gbp pull"
gbp pull

header "Bugs"
if is_installed "pkg-perl-tools" "0.69"; then
	bts-srcpkg -t
else
	warn "Running 'bts-srcpkg' without -t, sorry for the duplicate title."
	bts-srcpkg
fi

header "rmadison"
rmadison $PKG

header "grep-excuses"
grep-excuses $PKG

header "Last upload"
who-uploads --date --max-uploads=1 $PKG

# TODO: call popcon -v once #1011634 is fixed
header "Popcon"
if is_command popcon python3-popcon; then
	popcon $PKG
	info "(Output will be nicer once #1011634 is fixed.)"
fi

header "Key package?"
is_key_pkg $PKG

header "Git diff against last Debian tag"
anykey
gitddiff

POD=<<'EOF'
=head1 NAME

dpt-prepare - prepare yourself and a source directory before working on a package

=head1 SYNOPSIS

B<dpt prepare>

=head1 DESCRIPTION

B<dpt prepare> runs a couple of commands in the checked out directory of a
source package which are useful -- either for the person or the code -- as a
preparation before working on the package.

=head1 CONFIGURATION, OPTIONS, & PARAMETERS

None (yet).

=head1 COPYRIGHT & LICENSE

=over

=item Copyright 2022 gregor herrmann L<gregoa@debian.org>

=back

This program is free software, licensed under the same term as perl.

=cut
EOF
