1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00

Merge pull request #69637 from openshift-cherrypick-robot/cherry-pick-69628-to-enterprise-4.15

[enterprise-4.15] Add conditional checks for PR and slug in autopreview.sh
This commit is contained in:
Gaurav Nelson
2023-12-20 23:31:44 +10:00
committed by GitHub

View File

@@ -8,61 +8,69 @@ GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
USERNAME=${TRAVIS_PULL_REQUEST_SLUG::-15}
# Check if it is a PR
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
echo -e "${YELLOW}❗🙅‍♀️ Not a Pull request. Skipping the preview.${NC}"
exit 0
fi
if [[ "$USERNAME" == "openshift-cherrypick-robot" ]]; then
# Check if slug is empty
if [[ -z "$TRAVIS_PULL_REQUEST_SLUG" ]]; then
echo -e "${YELLOW}🤖 Slug is empty this is a push build. Skipping the preview.${NC}"
exit 0
fi
# Check if the slug is "openshift-cherrypick-robot"
if [[ "${TRAVIS_PULL_REQUEST_SLUG::-15}" == "openshift-cherrypick-robot" ]]; then
echo -e "${YELLOW}🤖 PR by openshift-cherrypick-robot. Skipping the preview.${NC}"
exit 0
fi
if [[ "$TRAVIS_PULL_REQUEST" ]]; then
# Check if modified files meet the conditions
COMMIT_HASH="$(git rev-parse @~)"
modified_files=$(git diff --name-only "$COMMIT_HASH")
send_request=false
# Check if modified files meet the conditions
COMMIT_HASH="$(git rev-parse @~)"
modified_files=$(git diff --name-only "$COMMIT_HASH")
should_send_request() {
for file in $modified_files; do
if [[ $file == *.adoc || $file == "_topic_map.yml" || $file == "_distro_map.yml" || $file == "_topic_maps/"* ]]; then
send_request=true
break
return 0
fi
done
return 1
}
if [ "$send_request" = true ]; then
# Build the JSON
json_data=$(
cat <<EOF
if should_send_request; then
# Build the JSON
json_data=$(
cat <<EOF
{
"PR_BRANCH": "${TRAVIS_PULL_REQUEST_BRANCH}",
"BASE_REPO": "${TRAVIS_REPO_SLUG}",
"PR_NUMBER": "${TRAVIS_PULL_REQUEST}",
"USER_NAME": "${USERNAME}",
"USER_NAME": "${TRAVIS_PULL_REQUEST_SLUG::-15}",
"BASE_REF": "${TRAVIS_BRANCH}",
"REPO_NAME": "${TRAVIS_PULL_REQUEST_SLUG}",
"SHA": "${TRAVIS_PULL_REQUEST_SHA}"
}
EOF
)
)
# Send the curl request
if response=$(curl -s -X POST -H "Content-Type: application/json" --data "$json_data" https://ocpdocs-preview-receiver.vercel.app/api/buildPreview); then
if echo "$response" | jq -e '.message == "Invalid data!"' >/dev/null; then
echo -e "${RED}❌😔 Curl request failed: Invalid data!${NC}"
echo -e "${YELLOW}$json_data${NC}"
exit 1
else
echo -e "${GREEN}✅🥳 $response${NC}"
fi
else
echo -e "${RED}❌😬 Curl request failed: $response${NC}"
# Send the curl request
if response=$(curl -s -X POST -H "Content-Type: application/json" --data "$json_data" https://ocpdocs-preview-receiver.vercel.app/api/buildPreview); then
if echo "$response" | jq -e '.message == "Invalid data!"' >/dev/null; then
echo -e "${RED}❌😔 Curl request failed: Invalid data!${NC}"
echo -e "${YELLOW}$json_data${NC}"
exit 1
else
echo -e "${GREEN}✅🥳 $response${NC}"
fi
echo -e "${GREEN}🚀🎉 Request sent successfully!${NC}"
else
echo -e "${YELLOW}⚠️🤔 No .adoc files, _topic_map.yml, or _distro_map.yml modified. Skipping the preview.${NC}"
echo -e "${RED}❌😬 Curl request failed: $response${NC}"
echo -e "${YELLOW}$json_data${NC}"
exit 1
fi
echo -e "${GREEN}🚀🎉 Request sent successfully!${NC}"
else
echo -e "${YELLOW}❗🙅‍♀️ Not a Pull request. Skipping the preview.${NC}"
fi
echo -e "${YELLOW}⚠️🤔 No .adoc files, _topic_map.yml, or _distro_map.yml modified. Skipping the preview.${NC}"
fi