Skip to content

Commit 7b2109e

Browse files
authored
Merge pull request #69531 from aireilly/update-rn-checker
Update link checker
2 parents f580d37 + 542df09 commit 7b2109e

File tree

1 file changed

+22
-59
lines changed

1 file changed

+22
-59
lines changed

scripts/check-rn-link-perms.sh

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,30 @@
11
#!/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.
2+
# Report errors for links to Red Hat JIRA bugs that are behind a login
43

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/*')
4+
# Get modifed lines, remove deleted lines from the diff
5+
git_diff=$(git diff --unified=0 --stat --diff-filter=AM HEAD~1 HEAD "*release-notes*.adoc" ':(exclude)_unused_topics/*' | grep '^+' | grep -Ev '^(\+\+\+ a/ b/)')
86

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)
7+
# Exit zero if there are no release-notes changes
8+
if [ -z "${git_diff}" ]; then
9+
exit 0
10+
fi
4111

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
12+
# Remove all multi-line comments and single line comments
13+
git_diff=$(echo "${git_diff}" | sed '\|^+////|,\|^+////|c\\' | sed '\|^+//| s|.*|//|')
4714

48-
done
15+
# Search the git diff for links
16+
link_regex='https://issues\.redhat\.com/browse/[A-Z]+-[0-9]+'
17+
links=$(echo "${git_diff}" | grep -o -E "$link_regex" | sort -u)
4918

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-
}
19+
for link in ${links}; do
20+
# Check for links that require a login
21+
response=$(curl -I "${link}" 2>&1)
22+
if echo "${response}" | grep -q "permissionViolation"; then
23+
errors=true
24+
echo -e "\e[31mERROR: Do not include links to JIRA issues that require a login (${link})\n"
25+
fi
26+
done
6127

62-
if [[ $FILES == *"release-notes"* ]]; then
63-
check_rn_links
64-
else
65-
echo "No release notes updated, exiting."
66-
exit 0
28+
if [ "$errors" = true ]; then
29+
exit 1
6730
fi

0 commit comments

Comments
 (0)