Skip to content

Commit 5e92030

Browse files
committed
Adding script to check for links to internal bugs in updated release note files. Fails out if internal bug link found.
1 parent f0cdb82 commit 5e92030

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ jobs:
1414
- gem install --local _gemfiles/asciidoctor-2.0.20.gem _gemfiles/asciidoctor-diagram-plantuml-1.2023.10.gem _gemfiles/asciidoctor-diagram-ditaamini-1.0.3.gem _gemfiles/rexml-3.2.6.gem _gemfiles/asciidoctor-diagram-2.2.14.gem _gemfiles/rouge-4.1.3.gem
1515
- pip3 install pyyaml aura.tar.gz
1616
script:
17-
# Fail if Asciidoctor encounters errors. Pass otherwise. Then, build updated distros
17+
# Fail if Asciidoctor encounters errors. Or if release notes has links to internal bugs. Pass otherwise. Then, build updated distros
18+
- chmod +x ./scripts/check-rn-link-perms.sh
19+
- ./scripts/check-rn-link-perms.sh || travis_terminate 1
1820
- chmod +x ./scripts/check-asciidoctor-build.sh
1921
- chmod +x ./scripts/get-updated-distros.sh
2022
- ./scripts/check-asciidoctor-build.sh || travis_terminate 1

scripts/check-rn-link-perms.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)