Skip to content

Commit 4cc9a4d

Browse files
committed
[GitHub] Broaden redirects comment to include partial checks
1 parent e92a792 commit 4cc9a4d

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

.github/workflows/comment-changed-filenames.yml renamed to .github/workflows/potential-redirects-or-partials.yml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Flag changed filenames
1+
name: Potential redirects or partials
22

33
# **What it does**: Adds or removes a comment if a PR renames or removes a file.
44
# **Why we have it**: Highlights when we need redirects covering certain file paths.
@@ -22,7 +22,7 @@ jobs:
2222
- name: Checkout Repository
2323
uses: actions/checkout@v4
2424

25-
- name: Get Renamed or Removed Files from Pull Request
25+
- name: Potential redirects
2626
env:
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2828
run: |
@@ -37,17 +37,31 @@ jobs:
3737
echo "${files}" >> "$GITHUB_ENV"
3838
echo "${delimiter}" >> "$GITHUB_ENV"
3939
40+
- name: Updated partial files
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
files=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
45+
-H "Accept: application/vnd.github.v3+json" \
46+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | \
47+
jq -r '.[] | select(.status=="modified" | select (.filename | startswith("src/content/partials")) | select(.filename | endswith(".mdx")) \
48+
# Use random delimiter for security reasons
49+
delimiter="$(openssl rand -hex 8)"
50+
echo "PARTIAL_FILES<<${delimiter}" >> "$GITHUB_ENV"
51+
echo "${files}" >> "$GITHUB_ENV"
52+
echo "${delimiter}" >> "$GITHUB_ENV"
53+
4054
- name: Comment or Update Comment on PR based on changed files
4155
env:
4256
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4357
run: |
4458
# If there are no changed files
45-
if [ -z "$CHANGED_FILES" ]; then
59+
if [ -z "$CHANGED_FILES" ] || [ -z "$PARTIAL_FILES" ]; then
4660
# Fetch the ID of the existing comment, if it exists
4761
existing_comment_id=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
4862
-H "Accept: application/vnd.github.v3+json" \
4963
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | \
50-
jq '.[] | select(.user.id == 41898282) | select(.body | contains("This PR changes current filenames or deletes current files")) | .id')
64+
jq '.[] | select(.user.id == 41898282) | select(.body | contains("This PR requires additional review attention because it affects the following areas")) | .id')
5165
5266
# If the comment exists, delete it
5367
if [ ! -z "$existing_comment_id" ]; then
@@ -58,18 +72,38 @@ jobs:
5872
fi
5973
else
6074
# Construct the comment body for changed files
61-
comment_body="This PR changes current filenames or deletes current files. Make sure you have [redirects](https://developers.cloudflare.com/pages/configuration/redirects/) set up to cover the following paths:"
62-
for path in $CHANGED_FILES; do
63-
clean_path=$(echo $path | sed 's/"//g') # Remove quotation marks
75+
comment_body="This PR requires additional review attention because it affects the following areas:"
76+
77+
# Add CHANGED_FILES logic
78+
if [ -n "$CHANGED_FILES" ]; then
6479
comment_body="$comment_body
65-
- [ ] \`$clean_path\`"
66-
done
80+
81+
### Redirects
82+
This PR changes current filenames or deletes current files. Make sure you have [redirects](https://developers.cloudflare.com/pages/configuration/redirects/) set up to cover the following paths:"
83+
for path in $CHANGED_FILES; do
84+
clean_path=$(echo "$path" | sed 's/"//g') # Remove quotation marks
85+
comment_body="$comment_body
86+
- [ ] \`$clean_path\`"
87+
done
88+
fi
89+
90+
# Conditional bit for PARTIAL_FILES
91+
if [ -n "$PARTIAL_FILES" ]; then
92+
comment_body="$comment_body
93+
94+
### Partials
95+
This PR updates partial files, which are bits of content used across multiple files.
96+
for path in $PARTIAL_FILES; do
97+
comment_body="$comment_body
98+
- [ ] \`$path\`"
99+
done
100+
fi
67101
68102
# Check if a comment already exists
69103
existing_comment_id=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
70104
-H "Accept: application/vnd.github.v3+json" \
71105
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | \
72-
jq '.[] | select(.user.id == 41898282) | select(.body | contains("This PR changes current filenames or deletes current files")) | .id')
106+
jq '.[] | select(.user.id == 41898282) | select(.body | contains("This PR requires additional review attention because it affects the following areas")) | .id')
73107
74108
comment_payload=$(echo '{}' | jq --arg body "$comment_body" '.body = $body')
75109

src/content/partials/1.1.1.1/ipv6.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ slug: 1.1.1.1/ipv6
66
2606:4700:4700::1111
77
2606:4700:4700::1001
88
```
9+
10+
TEST

0 commit comments

Comments
 (0)