Skip to content

Commit

Permalink
Merge branch 'master' of github.com:stone-payments/pos-mamba-sdk into…
Browse files Browse the repository at this point in the history
… release/next
  • Loading branch information
joliveiradantas committed Jul 12, 2024
2 parents 55c9be4 + 33f7765 commit f8bcc8d
Show file tree
Hide file tree
Showing 2 changed files with 409 additions and 118 deletions.
41 changes: 31 additions & 10 deletions tools/repo_initialization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# --no-repo-setup-run: Don't run repo_setup.py
# -------------------------------------------------------

GITHUB_REPO="stone-payments/pos-mamba-sdk"
GITHUB_BRANCH="master"

# Log and exit with 1
#
# Usage:
Expand All @@ -33,9 +36,7 @@ function log_fatal() {
function add_to_gitignore() {
filename=$1

if grep -Fxq "$filename" .gitignore; then
echo "$filename already on .gitignore."
else
if ! grep -Fxq "$filename" .gitignore; then
echo "$filename" >> .gitignore
echo "$filename added to .gitignore."
fi
Expand All @@ -52,8 +53,7 @@ function add_to_gitignore() {
#
# Note: string2 is optional, if it is not passed then "." It will be used.
function download_from_tools_on_mamba_sdk() {
local BRANCH="master"
local DOWNLOAD_BASEURL="https://raw.githubusercontent.com/stone-payments/pos-mamba-sdk/$BRANCH/tools"
local DOWNLOAD_BASEURL="https://raw.githubusercontent.com/$GITHUB_REPO/$GITHUB_BRANCH/tools"
local DOWNLOAD_TO="."

if [ "$#" -eq 2 ]; then
Expand All @@ -63,7 +63,7 @@ function download_from_tools_on_mamba_sdk() {
fi
local FILE_TO_DOWNLOAD=$1

wget -N -P $DOWNLOAD_TO $DOWNLOAD_BASEURL/$FILE_TO_DOWNLOAD
wget -nv -P $DOWNLOAD_TO -O $FILE_TO_DOWNLOAD $DOWNLOAD_BASEURL/$FILE_TO_DOWNLOAD
add_to_gitignore $FILE_TO_DOWNLOAD
}

Expand Down Expand Up @@ -102,12 +102,33 @@ function download_and_run() {
run_file $1
}

# Get commit hash by branch on sdk repo
#
# Usage:
# get_commit_hash_from_branch
function get_commit_hash_from_branch() {
COMMIT_INFO=$(curl -s "https://api.github.com/repos/$GITHUB_REPO/commits?sha=$GITHUB_BRANCH")
COMMIT_HASH=$(echo $COMMIT_INFO | jq -r '.[0].sha')
echo $COMMIT_HASH
}

# All repo_setup stuff
function repo_setup_init() {
repo_setup_file="repo_setup.py"

download_from_tools_on_mamba_sdk $repo_setup_file

if [[ "$@" != *"--no-repo-setup-run"* ]]; then
commit_hash=$(get_commit_hash_from_branch)
echo $commit_hash
sed -i "s/REPO_SETUP_PLACEHOLDER/$commit_hash/g" $repo_setup_file
run_file repo_setup.py
fi
}

if [[ "$@" != *"--no-hooks"* ]]; then
download_from_tools_on_mamba_sdk _git_hooks/post-checkout _git_hooks
download_and_run _git_hooks/install-hooks.sh _git_hooks
fi

download_from_tools_on_mamba_sdk repo_setup.py
if [[ "$@" != *"--no-repo-setup-run"* ]]; then
run_file repo_setup.py
fi
repo_setup_init $@
Loading

0 comments on commit f8bcc8d

Please sign in to comment.