|
| 1 | +#!/bin/bash |
| 2 | +# Checks if a release notes file is updated. If true, searches the release notes file for links to bugs that are behind a login and fails the build. |
| 3 | +# We should not include internal bugs in our release notes. |
| 4 | + |
| 5 | +# Get the repo path and files changed |
| 6 | +REPO_PATH="$(git rev-parse --show-toplevel)" |
| 7 | +FILES=$(git diff --name-only HEAD~1 HEAD --diff-filter=d "*release-notes*.adoc" ':(exclude)_unused_topics/*') |
| 8 | + |
| 9 | +# Function to check links in updated release notes |
| 10 | +check_rn_links () { |
| 11 | + |
| 12 | + # Iterate through RN files because could potentially be more than one (e.g. OCP + ROSA) |
| 13 | + for RELEASE_FILE in ${FILES}; do |
| 14 | + echo "" |
| 15 | + echo "#########" |
| 16 | + echo "You updated the following release notes file:" |
| 17 | + echo "$RELEASE_FILE" |
| 18 | + echo "#########" |
| 19 | + echo "" |
| 20 | + |
| 21 | + # Read the content from the local release note file |
| 22 | + content=$(cat "$REPO_PATH/$RELEASE_FILE") |
| 23 | + |
| 24 | + # Exclude content within //// multi-line comments |
| 25 | + content=$(echo "${content}" | sed ':a;N;$!ba;s#////\n.*////##g') |
| 26 | + |
| 27 | + # Extract links from the content, excluding single-line comments |
| 28 | + links=$(echo "$content" | grep -v '^//.*' | grep -o 'https://issues[^]]*' | sed 's/\[.*//') |
| 29 | + protected_links=() |
| 30 | + |
| 31 | + echo "" |
| 32 | + echo "#########" |
| 33 | + echo "Checking for internal bug links in $REPO_PATH/$RELEASE_FILE" |
| 34 | + echo "#########" |
| 35 | + echo "" |
| 36 | + |
| 37 | + # Iterate over the links and check their authorization status |
| 38 | + for link in $links |
| 39 | + do |
| 40 | + response=$(curl -I "$link" 2>&1) |
| 41 | + |
| 42 | + if echo "$response" | grep -q "permissionViolation"; then |
| 43 | + echo "The link $link points to an internal bug." |
| 44 | + protected_links+=("$link") |
| 45 | + fi |
| 46 | + done |
| 47 | + |
| 48 | + done |
| 49 | + |
| 50 | + # Print the list of links that require authentication |
| 51 | + if [ ${#protected_links[@]} -eq 0 ]; then |
| 52 | + echo "No links require authentication, exiting." |
| 53 | + exit 0 |
| 54 | + else |
| 55 | + echo "Links that require authentication:" |
| 56 | + printf '%s\n' "${protected_links[@]}" |
| 57 | + echo "Build failed. Ensure there are no links to internal JIRA bugs, which have a security level of Red Hat Employee only." |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +} |
| 61 | + |
| 62 | +if [[ $FILES == *"release-notes"* ]]; then |
| 63 | + check_rn_links |
| 64 | +else |
| 65 | + echo "No release notes updated, exiting." |
| 66 | + exit 0 |
| 67 | +fi |
0 commit comments