Skip to content

Instantly share code, notes, and snippets.

@konifar
Last active May 15, 2018 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konifar/2f793dd5c4f3064aad8d757ebb7b093f to your computer and use it in GitHub Desktop.
Save konifar/2f793dd5c4f3064aad8d757ebb7b093f to your computer and use it in GitHub Desktop.
auto_remove_unused_resources.sh
#!/bin/bash -xe
# Usage:
# ./auto_remove_unused_resources.sh {github token} master
readonly GITHUB_TOKEN=${1}
readonly BASE_BRANCH=${2}
readonly ROOT_DIR=$PWD
readonly SRC_DIR="app/src"
readonly COMPARE_BRANCH="remove_unused_resources"
readonly GITHUB_USER_EMAIL="tachikoma@kyash.co"
readonly GITHUB_USER_NAME="tachikoma"
function removeUnusedResources {
git branch -D ${COMPARE_BRANCH} || true
git checkout -b ${COMPARE_BRANCH}
./gradlew removeUnusedResources
if [ -n "`git diff | grep ${SRC_DIR}`" ]; then
git config user.email ${GITHUB_USER_EMAIL}
git config user.name ${GITHUB_USER_NAME}
git add ${SRC_DIR}
git commit -m 'Removed unused resources'
else
echo "Nothing is changed."
exit 0
fi
}
function sendPullRequest() {
git push -f "https://${GITHUB_TOKEN}@github.com/konifar/gradle-unused-resources-remover-plugin.git" ${COMPARE_BRANCH}:${COMPARE_BRANCH}
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -d @- https://api.github.com/repos/konifar/gradle-unused-resources-remover-plugin/pulls <<EOF
{
"title":"Auto Remove Unused Resources",
"head":"${COMPARE_BRANCH}",
"base":"${BASE_BRANCH}"
}
EOF
echo "Sent PullRequest."
}
removeUnusedResources
sendPullRequest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment