Skip to content

Commit

Permalink
Update with latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
aHenryJard committed Oct 22, 2024
1 parent 99e5aee commit 621c067
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions scripts/clone-opencti.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,35 @@ clone_for_pr_build() {
}

clone_for_push_build() {
echo "[CLONE-DEPS] Build from a commit, checking if a dedicated branch is required."
gh pr view ${PR_BRANCH_NAME}

echo "[CLONE-DEPS] Build from a commit, checking if a dedicated branch is required."
BRANCH_PREFIX=$(echo $PR_BRANCH_NAME | cut -d "/" -f 1 | grep -c "opencti")
if [[ "${BRANCH_PREFIX}" -eq "1" ]]
then
tthen
echo "[CLONE-DEPS] Dedicated OpenCTI branch found, using it"
OPENCTI_BRANCH=$(echo $PR_BRANCH_NAME | cut -d "/" -f2-)
gh repo clone https://github.com/OpenCTI-Platform/opencti ${OPENCTI_DIR} -- --branch ${OPENCTI_BRANCH} --depth=1
git clone -b $OPENCTI_BRANCH https://github.com/OpenCTI-Platform/opencti.git
else
echo "[CLONE-DEPS] No dedicated OpenCTI branch found, using ${PR_TARGET_BRANCH}"
gh repo clone https://github.com/OpenCTI-Platform/opencti ${OPENCTI_DIR} -- --branch ${PR_TARGET_BRANCH} --depth=1
echo "[CLONE-DEPS] No dedicated OpenCTI branch found, using master"
git clone https://github.com/OpenCTI-Platform/opencti.git
fi
}

echo "[CLONE-DEPS] START; with PR_BRANCH_NAME=${PR_BRANCH_NAME},PR_TARGET_BRANCH=${PR_TARGET_BRANCH}, PR_NUMBER=${PR_NUMBER}, OPENCTI_DIR=${OPENCTI_DIR}."
if [[ -z ${PR_NUMBER} ]] || [[ ${PR_NUMBER} == "" ]]
then
# No PR number from Drone = "Push build". And it's only for repository branch (not fork)
# Using github cli to get PR number anyway
PR_NUMBER=$(gh pr view ${PR_BRANCH_NAME} --json number --jq '.number')
PR_TARGET_BRANCH=$(gh pr view ${PR_BRANCH_NAME} --json baseRefName --jq '.baseRefName')
echo "[CLONE-DEPS] Got data from github cli, continue with: PR_TARGET_BRANCH=${PR_TARGET_BRANCH}, PR_NUMBER=${PR_NUMBER}."
clone_for_pr_build

if [[ -z ${PR_NUMBER} ]] || [[ ${PR_NUMBER} == "" ]]
then
echo "[CLONE-DEPS] PR is not created on github yet, using clone without PR number and default fallback to master"
clone_for_push_build
else
echo "[CLONE-DEPS] Got data from github cli, continue with: PR_TARGET_BRANCH=${PR_TARGET_BRANCH}, PR_NUMBER=${PR_NUMBER}."
clone_for_pr_build
fi
else
# PR build is trigger from Pull Request coming both from branch and forks.
# We need to have this clone accross repository that works for forks (community PR)
Expand Down

0 comments on commit 621c067

Please sign in to comment.