#!/usr/bin/env bash
# open a mail client with template last rites mail based on current diff
# (c) 2019-2024 Michał Górny <mgorny@gentoo.org>
# SPDX-License-Identifier: GPL-2.0-or-later

set -e

scriptdir=${BASH_SOURCE%/*}
cd "$(git rev-parse --show-toplevel)"
msg=$(
	git diff -U0 HEAD^ profiles/package.mask |
	sed -n -e 's/^+\([^+]\)/\1/p'
)

pkg=( $(echo "${msg}" | grep '^[^#]') )
pkg=${pkg[*]}

exec xdg-open "mailto:gentoo-dev-announce@lists.gentoo.org?cc=gentoo-dev@lists.gentoo.org&reply-to=gentoo-dev@lists.gentoo.org&subject=$("${scriptdir}"/urlencode <<<"Last rites: ${pkg// /, }")&body=$("${scriptdir}"/urlencode <<<"${msg}")"
