Skip to content
Snippets Groups Projects
Commit 0fb6c7a4 authored by Grégoire Kubler's avatar Grégoire Kubler
Browse files

feat: homoegeineized the API call to retrieve branches

parent 5a06de24
No related branches found
No related tags found
No related merge requests found
...@@ -55,14 +55,13 @@ ...@@ -55,14 +55,13 @@
echo "*************************************************************************" echo "*************************************************************************"
echo "*************************************************************************" echo "*************************************************************************"
echo "**" echo "**"
echo "** CHOOSING WHICH BRANCH TO PULL" echo "** CHOOSING WHICH BRANCH / RELEASE / REF TO PULL"
echo "**" echo "**"
echo "*************************************************************************" echo "*************************************************************************"
echo "*************************************************************************" echo "*************************************************************************"
DEFAULT_BRANCH="dev" # default branch to pull DEFAULT_BRANCH="dev" # default branch to pull
BRANCH_TO_PULL=$DEFAULT_BRANCH # default branch to pull BRANCH_TO_PULL=$DEFAULT_BRANCH # default branch to pull
echo "Default branch to pull : $BRANCH_TO_PULL" echo "Default branch to pull : $BRANCH_TO_PULL"
echo "Retrieving branches of $DEP_NAME \"$DEP_API_URL/repository/branches\""
echo "Choosing a branch / tag to pull dependending if we are in a Non draft merge request or not." echo "Choosing a branch / tag to pull dependending if we are in a Non draft merge request or not."
echo "CI_COMMIT_TAG = $CI_COMMIT_TAG" echo "CI_COMMIT_TAG = $CI_COMMIT_TAG"
echo "CI_MERGE_REQUEST_ID = $CI_MERGE_REQUEST_ID" echo "CI_MERGE_REQUEST_ID = $CI_MERGE_REQUEST_ID"
...@@ -71,6 +70,7 @@ ...@@ -71,6 +70,7 @@
################################ ################################
# CASE NON DRAFT MERGE REQUEST # CASE NON DRAFT MERGE REQUEST
if [[ ! -z "$CI_MERGE_REQUEST_ID" && "$CI_MERGE_REQUEST_TITLE" != *'Draft'* ]]; then # case we are in a merge request if [[ ! -z "$CI_MERGE_REQUEST_ID" && "$CI_MERGE_REQUEST_TITLE" != *'Draft'* ]]; then # case we are in a merge request
echo "Retrieving branches of $DEP_NAME \"$DEP_API_URL/repository/branches?per_page=100\""
DEP_BRANCHES=$(curl -s "$DEP_API_URL/repository/branches?per_page=100") DEP_BRANCHES=$(curl -s "$DEP_API_URL/repository/branches?per_page=100")
# If the MR is not in draft: pulling from target branch (if exists otherwise dev) # If the MR is not in draft: pulling from target branch (if exists otherwise dev)
echo "NON DRAFT MERGE REQUEST Pipeline detected : Pulling from CI_MERGE_REQUEST_TARGET_BRANCH_NAME \"$CI_MERGE_REQUEST_TARGET_BRANCH_NAME\"." echo "NON DRAFT MERGE REQUEST Pipeline detected : Pulling from CI_MERGE_REQUEST_TARGET_BRANCH_NAME \"$CI_MERGE_REQUEST_TARGET_BRANCH_NAME\"."
...@@ -115,7 +115,8 @@ ...@@ -115,7 +115,8 @@
# CASE CASUAL COMMIT or Draft MR PIPELINE # CASE CASUAL COMMIT or Draft MR PIPELINE
else else
# checking if a branch with same name exists in $DEP_NAME, otherwise, pulling from DEV # checking if a branch with same name exists in $DEP_NAME, otherwise, pulling from DEV
DEP_BRANCHES=$(curl -s "$DEP_API_URL/repository/branches") echo "Retrieving branches of $DEP_NAME \"$DEP_API_URL/repository/branches?per_page=100\""
DEP_BRANCHES=$(curl -s "$DEP_API_URL/repository/branches?per_page=100")
echo "Looking for branch $CI_COMMIT_BRANCH in repo $DEP_NAME" echo "Looking for branch $CI_COMMIT_BRANCH in repo $DEP_NAME"
FILTERED_BRANCHES=$(jq --arg branch "$CI_COMMIT_REF_NAME" 'map(select( .name == $branch ))' <<<"$DEP_BRANCHES") FILTERED_BRANCHES=$(jq --arg branch "$CI_COMMIT_REF_NAME" 'map(select( .name == $branch ))' <<<"$DEP_BRANCHES")
if [[ $(jq length <<<$FILTERED_BRANCHES) -gt 0 ]]; then if [[ $(jq length <<<$FILTERED_BRANCHES) -gt 0 ]]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment