Skip to content

Instantly share code, notes, and snippets.

@robweber
Last active August 22, 2019 22:48
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 robweber/3008e50e27349fb15a8406d18cf715da to your computer and use it in GitHub Desktop.
Save robweber/3008e50e27349fb15a8406d18cf715da to your computer and use it in GitHub Desktop.
Kodi Addon Checker Pull Request Script
#!/bin/bash
#will either check your addon (same as PR will do) or send a pull request on up to the repo
#cultivated from instructions at https://kodi.wiki/view/HOW-TO:Create_add-on_PRs_using_Git_Subtree_Merging and modified
## ARGS pass in file to source other args as -f or --filename ##
ADDON_CHECKER_VERSION=0.0.14
KODI_FORK=https://github.com/robweber/repo-scripts.git
KODI_REPO_BRANCH=jarvis
ADDON_URL=https://github.com/robweber/xbmcbackup.git
ADDON_BRANCH=master
ADDON_NAME=script.xbmcbackup
ADDON_VERSION=1.1.3
function createPullRequest(){
#go into the repo scripts directory
if [ ! -d "repo-scripts/" ]; then
git clone $KODI_FORK
fi
cd "repo-scripts/"
#check if remote exists
CHECK_REMOTE=`git config "remote.$ADDON_NAME.url"`
if [ ! $CHECK_REMOTE > /dev/null ]; then
git remote add $ADDON_NAME $ADDON_URL
fi
git fetch $ADDON_NAME
#check if the branch exists
LOCAL_BRANCH_NAME=$ADDON_NAME"_"$ADDON_BRANCH
CHECK_BRANCH=`git rev-parse --verify --quiet $LOCAL_BRANCH_NAME`
echo "CHECKING FOR $LOCAL_BRANCH_NAME"
if [ "$CHECK_BRANCH" != "" ]; then
echo "found branch"
git checkout $LOCAL_BRANCH_NAME
git pull
else
git checkout -b $LOCAL_BRANCH_NAME "$ADDON_NAME/$ADDON_BRANCH"
fi
#remove the ignore file
rm .gitignore
#checkout the kodi branch
git checkout $KODI_REPO_BRANCH
#check if addon exists
if [ -d "$ADDON_NAME/" ]; then
#remove it
git rm -r "$ADDON_NAME/"
fi
#merge in the updated addon info
git read-tree --prefix="$ADDON_NAME/" -u "$LOCAL_BRANCH_NAME"
git commit -m "[$ADDON_NAME] $ADDON_VERSION"
#check if we need to squash commits - happens when modifications are needed
read -p "Enter the number of commits to merge (SQUASH) 0 means none: " SQUASH_COMMITS
GIT_FORCE=""
if [ $SQUASH_COMMITS != 0 ]; then
git rebase -i HEAD~$SQUASH_COMMITS
GIT_FORCE="--force"
fi
#check if we should push to the repo
read -p "Push Changes? (Y/N): " PUSH_CHANGES
if [ "$PUSH_CHANGES" = 'Y' -o "$PUSH_CHANGES" = 'y' ]; then
git push $GIT_FORCE
fi
}
function checkAddon(){
#checkout the addon
if [ ! -d $ADDON_NAME ]; then
git clone $ADDON_URL $ADDON_NAME
fi
#checkout the specific branch we want
cd $ADDON_NAME
git fetch
git checkout $BRANCH
cd ..
#check if addon checker is installed
if [ ! -d "kodi-addon-checker" ]; then
git clone https://github.com/xbmc/addon-check.git kodi-addon-checker
fi
#checkout the version we want
cd "kodi-addon-checker"
git fetch --tags
git checkout $ADDON_CHECKER_VERSION
#build the addon checker
pip3 install -r requirements.txt
pip3 install pylint
#check the addon
python3 -m kodi_addon_checker --branch=$KODI_REPO_BRANCH ../$ADDON_NAME/
}
while [ "$1" != "" ]; do
case $1 in
-f | --file ) shift
source $1
;;
esac
shift
done
#list some info before we start
echo -e "\e[34m"
echo "$ADDON_NAME $ADDON_VERSION"
echo "$ADDON_URL $ADDON_BRANCH"
echo "Kodi Branch: $KODI_REPO_BRANCH"
echo -e "\e[33m"
echo "What do you want to do?"
echo "1. Check the addon for errors"
echo "2. Create a Pull Request"
echo "3. Exit"
echo -e "\e[39m"
INSTALL_OPTION=0
while [ $INSTALL_OPTION -le 0 ] || [ $INSTALL_OPTION -gt 3 ]; do
read -p "Choose what you want to do? " INSTALL_OPTION
done
echo ""
if [ $INSTALL_OPTION -eq 1 ]; then
checkAddon
elif [ $INSTALL_OPTION -eq 2 ]; then
createPullRequest
elif [ $INSTALL_OPTION -eq 3 ]; then
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment