Last active
November 18, 2020 17:51
-
-
Save samratshaw/4b48a02084d2a7c725bd5f07ec0fa319 to your computer and use it in GitHub Desktop.
Compare two branches for multiple repositories
This file contains 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 | |
# { | |
# "repositories": [ | |
# { | |
# "url": "https://xxx.git", | |
# "baseBranch": "origin/release/1.x", | |
# "targetBranch": "origin/daily" | |
# }, | |
# { | |
# "url": "https://xxx.git", | |
# "baseBranch": "origin/1.x", | |
# "targetBranch": "origin/daily" | |
# } | |
# ] | |
# } | |
CONFIG_FILE=./config.json | |
# Read config file | |
if [ ! -e "$CONFIG_FILE" ]; then | |
echo "ERROR - Missing config file. Failed to update results" | |
exit 1 | |
fi | |
# Read config file | |
NUMBER_OF_REPOS=$(jq '.repositories | length' $CONFIG_FILE) | |
echo "Parsing json..." | |
echo "Total number of repositories = $NUMBER_OF_REPOS" | |
for index in $(seq 1 $NUMBER_OF_REPOS); | |
do | |
REPOSITORY=$(jq ".repositories[$index-1]" $CONFIG_FILE); | |
URL=$(jq -r '.url' <<< $REPOSITORY) | |
BASE_BRANCH=$(jq -r '.baseBranch' <<< $REPOSITORY) | |
TARGET_BRANCH=$(jq -r '.targetBranch' <<< $REPOSITORY) | |
FOLDER_NAME=$(echo $URL | sed "s%^.*/\([^/]*\)\.git$%\1%g") | |
echo "*********************" | |
echo "Repo details" | |
echo "Url = $URL" | |
echo "Folder name = $FOLDER_NAME" | |
echo "Base branch = $BASE_BRANCH" | |
echo "Target branch = $TARGET_BRANCH" | |
echo "*********************" | |
echo "" | |
echo "*********************" | |
echo "Cloning repo..." | |
echo "*********************" | |
echo | |
if [ ! -d "$FOLDER_NAME" ] ; then | |
git clone $URL | |
cd "$FOLDER_NAME" | |
else | |
cd "$FOLDER_NAME" | |
fi | |
git fetch --prune | |
git gc --prune=now | |
git rev-list --left-right --count $BASE_BRANCH...$TARGET_BRANCH | |
# Make sure to return to root directory | |
cd .. | |
done | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment