Last active
May 15, 2018 15:18
-
-
Save konifar/2f793dd5c4f3064aad8d757ebb7b093f to your computer and use it in GitHub Desktop.
auto_remove_unused_resources.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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="[email protected]" | |
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