#!/bin/sh for D in `find ./$1* -type d -maxdepth 0 -mindepth 0` do echo "==============> $D <===============" cd $D if [ -d .git ] then UPSTREAM=$(git remote | grep upstream) UPSTREAM_LENGTH=${#UPSTREAM} if [ $UPSTREAM_LENGTH -eq 0 ] then GITHUB_URL=$(git remote -v | grep -v origin|head -n 1|cut -f2|cut -d " " -f1) GITHUB_URL_LENGTH=${#GITHUB_URL} if [ $GITHUB_URL_LENGTH -eq 0 ] then echo "Repository not forked!!" else git remote add upstream $GITHUB_URL UPSTREAM=$(git remote | grep upstream) UPSTREAM_LENGTH=${#UPSTREAM} fi fi ORIGIN=$(git remote | grep -v origin|grep -v upstream) ORIGIN_LENGTH=${#ORIGIN} if [ $ORIGIN_LENGTH -eq 0 ] then ORIGIN="origin" ORIGIN_USER="Apollon77" else echo "ORIGIN = $ORIGIN" ORIGIN_USER="$ORIGIN" fi PROJECT=$(echo "$D"|cut -d "/" -f2) OPEN_CHANGES_INIT=$(git rev-list --left-right --count "master...$ORIGIN/master") OPEN_CHANGES_INIT_LOCAL=$(echo "$OPEN_CHANGES_INIT"|cut -f1) OPEN_CHANGES_INIT_REMOTE=$(echo "$OPEN_CHANGES_INIT"|cut -f2) echo "Local changes: $OPEN_CHANGES_INIT_LOCAL Remote changes: $OPEN_CHANGES_INIT_REMOTE" if [ "$OPEN_CHANGES_INIT_REMOTE" != "0" ] then echo "PULL CHANGES FROM REMOTE" fi if [ $ORIGIN_LENGTH -eq 0 ] then git pull --no-edit else git fetch upstream git rebase upstream/master git push fi # if [ $ORIGIN_LENGTH -ne 0 ] # then # git rev-list --left-right --count master...$ORIGIN/master # git fetch $ORIGIN # git checkout master # git merge $ORIGIN/master --no-edit # git push # fi OPEN_CHANGES=$(git rev-list --left-right --count "master...$ORIGIN/master") OPEN_CHANGES_LOCAL=$(echo "$OPEN_CHANGES"|cut -f1) OPEN_CHANGES_REMOTE=$(echo "$OPEN_CHANGES"|cut -f2) if [ "$OPEN_CHANGES_LOCAL" != "0" ] then echo "Local changes: $OPEN_CHANGES_LOCAL Remote changes: $OPEN_CHANGES_REMOTE" PULL_CHECK=$(curl -sSL "https://api.github.com/repos/$ORIGIN/$PROJECT/pulls"|grep Apollon77|wc -l|tr -d '[:space:]') if [ "$PULL_CHECK" != "0" ] then echo "-----> Pull Request open" elif [ "$ORIGIN" != "ioBroker" ] && [ "$ORIGIN" != "Apollon77" ] then echo "Create Pull-Request: gcli pull create $ORIGIN_USER $PROJECT --base \"master\" --head \"Apollon77:master\" --quiet=true --title \"Update CI testing\"|cat" fi else if [ "$OPEN_CHANGES_REMOTE" != "0" ] then echo "Local changes: $OPEN_CHANGES_LOCAL Remote changes: $OPEN_CHANGES_REMOTE" fi fi D_LOWER=$(echo "$PROJECT" | awk '{print tolower($0)}') PACKAGE_VERSION_LOCAL=$(node -p -e "require('./package.json').version") PACKAGE_VERSION_NPM=$(npm view $D_LOWER version 2>/dev/null) if [ "$PACKAGE_VERSION_LOCAL" != "$PACKAGE_VERSION_NPM" ] then echo "Local: $PACKAGE_VERSION_LOCAL - NPM: $PACKAGE_VERSION_NPM" fi if [ -f io-package.json ] then PACKAGE_ADAPTER_NAME=$(node -p -e "require('./io-package.json').common.name") PACKAGE_VERSION_REPO=$(node -p -e "try{require('../ioBroker.repositories/sources-dist-stable.json')['$PACKAGE_ADAPTER_NAME'].version;} catch(e) {}") if [ "$PACKAGE_VERSION_REPO" != "$PACKAGE_VERSION_NPM" ] then printf "Stable: $PACKAGE_VERSION_REPO - NPM: $PACKAGE_VERSION_NPM Local Filedate io-package: " date -r io-package.json fi fi if [ -f npm-debug.log ] then rm npm-debug.log fi fi cd .. sleep 10 done