spacemacs/.circleci/update/maybe_pr

71 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
## open_pr Opens PR to Spacemacs repository with built-in updates
##
## Copyright (c) 2014-2021 Sylvain Benner & Contributors
##
## Author: Eugene Yaremenko
## URL: https://github.com/syl20bnr/spacemacs
##
## This file is not part of GNU Emacs.
##
## License: GPLv3
skip_when_non_official_repo
if [ ! -f /tmp/built_in.patch ]; then
echo "Nothing to update."
exit 0
fi
echo_headline "Cloning target repository"
target_URL="https://github.com/${prj_owner}/${prj_repo}.git"
git clone "${target_URL}" -b "${CIRCLE_BRANCH}" "/tmp/${PUBLISH}"
if [ $? -ne 0 ]; then
echo "Failed to clone \"${target_URL}\""
exit 2
fi
cd "/tmp/${PUBLISH}"
echo_headline "Applying built-in patch"
if [ ! -f /tmp/built_in.patch ]; then
echo "Built-in files don't need updating. Aborting."
else
git am < /tmp/built_in.patch
if [ $? -ne 0 ]; then
echo "Failed to apply built-in patch."
exit 2
fi
fi
echo_headline "Forking target repository"
export GITHUB_TOKEN=$UPD_BOT_GIT_TK
hub fork
if [ $? -ne 0 ]; then
echo "hub fork failed"
exit 2
fi
fork_url="https://${UPD_BOT_LOGIN}:${UPD_BOT_GIT_TK}"
fork_url+="@github.com/${UPD_BOT_LOGIN}/${UPD_BOT_REPO}.git"
git remote set-url "${UPD_BOT_LOGIN}" "${fork_url}"
echo_headline "Pushing changes"
hub push -f "${UPD_BOT_LOGIN}" "${PUBLISH}" > /dev/null 2>&1
# prevent token leak ^^^^^^^^^^^^^^
if [ $? -ne 0 ]; then
echo "hub push failed"
exit 2
fi
echo_headline "Opening PR to ${UPD_BOT_LOGIN}/${UPD_BOT_REPO} repo"
echo "[bot] Built-in auto-update" > msg
echo >> msg
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
hub pull-request -b "${CIRCLE_BRANCH}" -F msg
if [ $? -ne 0 ]; then
echo "Seems like PR already exists (not a problem)"
fi
echo_headline "Done!"