Skip to content

Commit

Permalink
Add PR option to copy kiali repo script (#338)
Browse files Browse the repository at this point in the history
* Add PR option to copy kiali repo script

* Fix unbound variable issue
  • Loading branch information
ferhoyos authored Jul 30, 2024
1 parent 1682991 commit ec42f59
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions hack/copy-frontend-src-to-ossmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOURCE_REPO_URL="${DEFAULT_SOURCE_REPO_URL}"
# The git ref (branch or tag name) to checkout when cloning the source repo
DEFAULT_SOURCE_REF="master"
SOURCE_REF="${DEFAULT_SOURCE_REF}"
PULL_REQUEST=""

# This is to be the top-level directory of the local OSSM git repo.
# This is where DEST_DIR should be located.
Expand All @@ -44,6 +45,7 @@ while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-dr|--dest-repo) DEST_REPO="$2" ;shift;shift ;;
-pr|--pull-request) PULL_REQUEST="$2" ;shift;shift ;;
-sr|--source-ref) SOURCE_REF="$2" ;shift;shift ;;
-su|--source-url) SOURCE_REPO_URL="$2" ;shift;shift ;;
-h|--help)
Expand All @@ -58,6 +60,13 @@ Valid options:
repo's "${DEST_DIR}" directory.
Default: ${DEFAULT_DEST_REPO}
-pr|--pull-request <pull request number>
A git reference (pull request number) found in the remote source repo. This is the
Kiali pull request that will be checked out when cloning the remote source repo.
This option takes precedence over the --source-ref option
See also: --source-ref
Default: ""
-sr|--source-ref <branch or tag name>
A git reference (branch or tag name) found in the remote source repo. This is the
branch or tag that will be checked out when cloning the remote source repo.
Expand Down Expand Up @@ -111,7 +120,19 @@ if [ ! -d "${ABS_SOURCE_DIR}" ]; then
exit 1
fi

COMMIT_HASH="$(cd ${ABS_SOURCE_DIR} && git rev-parse HEAD)"
cd ${ABS_SOURCE_DIR}

if [ -n "${PULL_REQUEST}" ]; then
echo "Applying changes from PR ${PULL_REQUEST} (https://github.com/kiali/kiali/pull/${PULL_REQUEST})"
git fetch origin pull/${PULL_REQUEST}/head:pr-${PULL_REQUEST}
git checkout pr-${PULL_REQUEST}

GIT_REF="PR ${PULL_REQUEST}"
else
GIT_REF="${SOURCE_REF}"
fi

COMMIT_HASH="$(git rev-parse HEAD)"
GITHUB_COMMIT_URL="https://github.com/kiali/kiali/tree/${COMMIT_HASH}/${SOURCE_DIR}"

if ! curl --silent --show-error --fail "${GITHUB_COMMIT_URL}" > /dev/null; then
Expand All @@ -128,7 +149,7 @@ DEST_BRANCH="kiali-frontend-update-${DATETIME_NOW}"
COMMIT_MESSAGE=$(cat <<EOM
Copy of Kiali frontend source code
Kiali frontend source originated from:
* git ref: ${SOURCE_REF}
* git ref: ${GIT_REF}
* git commit: ${COMMIT_HASH}
* GitHub URL: ${GITHUB_COMMIT_URL}
EOM
Expand Down Expand Up @@ -183,4 +204,4 @@ else
echo "Kiali frontend code has been copied to a new branch in the OSSMC git repo."
echo "Create a PR based on that branch:"
echo "cd ${ABS_DEST_DIR} && git push ${GIT_REMOTE:-<the git remote name>} ${DEST_BRANCH}"
fi
fi

0 comments on commit ec42f59

Please sign in to comment.