Skip to content

Commit 93e4e49

Browse files
committed
Merge branch 'main' into DOC-3706
2 parents c2084da + 7c8b7b3 commit 93e4e49

File tree

4,361 files changed

+307938
-119519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,361 files changed

+307938
-119519
lines changed

.github/workflows/autocomment.yaml

Lines changed: 0 additions & 169 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: autocomment_jira_link
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
auto-comment:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: 'Checkout'
16+
uses: 'actions/checkout@v3'
17+
18+
- name: Create Comment
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
PR_NUMBER: ${{ github.event.pull_request.number }}
22+
REPO: ${{ github.repository }}
23+
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
24+
run: |
25+
generate_post_data()
26+
{
27+
cat <<EOF
28+
{
29+
"body": "$COMMENT"
30+
EOF
31+
}
32+
33+
if [[ "$BRANCH_NAME" == DOC-* ]]; then
34+
CREATE_COMMENT_URL="https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/comments"
35+
36+
JIRA_TICKET=$(grep -Eo '^DOC-[0-9]+' <<< "$BRANCH_NAME")
37+
JIRA_LINK="https://redislabs.atlassian.net/browse/${JIRA_TICKET}"
38+
COMMENT="[${JIRA_TICKET}](${JIRA_LINK})"
39+
40+
# Write comment on pull request
41+
curl -Ls \
42+
-X POST \
43+
-H "Accept: application/vnd.github+json" \
44+
-H "X-GitHub-Api-Version: 2022-11-28" \
45+
-H "Authorization: token ${GITHUB_TOKEN}" \
46+
$CREATE_COMMENT_URL \
47+
--data "$(generate_post_data)" 1>/dev/null
48+
49+
printf '%s\n' 'Comment written!'
50+
fi
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: autocomment_staging_links
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'content/**'
7+
types:
8+
- opened
9+
- synchronize
10+
permissions:
11+
pull-requests: write
12+
contents: read
13+
14+
jobs:
15+
auto-comment:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: 'Checkout'
19+
uses: 'actions/checkout@v3'
20+
21+
- name: 'Install jq'
22+
run: sudo apt-get install jq
23+
24+
- name: Create Comment
25+
run: |
26+
set -e
27+
28+
PR_NUMBER=${{ github.event.pull_request.number }}
29+
BRANCH_NAME=${{ github.head_ref }}
30+
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
31+
CREATE_COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
32+
UPDATE_COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/comments"
33+
FILES_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}/files"
34+
35+
# Check if comment already exists
36+
EXISTING_COMMENT_JSON=$(curl -Ls \
37+
-H "Accept: application/vnd.github+json" \
38+
-H "X-GitHub-Api-Version: 2022-11-28" \
39+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
40+
$CREATE_COMMENT_URL \
41+
| jq -r '.[] | select(.user.login == "github-actions[bot]" and ((.body // "") | contains("Staging links:")))'
42+
)
43+
EXISTING_COMMENT_ID=$(jq -r '.id' <<<"$EXISTING_COMMENT_JSON")
44+
EXISTING_COMMENT=$(jq -r '.body' <<<"$EXISTING_COMMENT_JSON")
45+
46+
# Get all changed md files
47+
CHANGED_MD_FILES=$(curl -Ls \
48+
-H "Accept: application/vnd.github+json" \
49+
-H "X-GitHub-Api-Version: 2022-11-28" \
50+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
51+
$FILES_URL \
52+
| jq -r --arg prefix $BRANCH_NAME/ '.[] | select(((.filename | test("content/(?!.*embed).*\\.md")) and .status != "removed")) | ($prefix + .filename)' \
53+
| sed -E -e 's|(^[^/]+/)([^/]+/)|\1|' -e 's|^|https://redis.io/docs/staging/|' -e 's|(\/_?index)?\.md|\/|' \
54+
| sort \
55+
| uniq)
56+
57+
# Get all changed image files
58+
CHANGED_IMAGE_FILES=$(curl -Ls \
59+
-H "Accept: application/vnd.github+json" \
60+
-H "X-GitHub-Api-Version: 2022-11-28" \
61+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
62+
$FILES_URL \
63+
| jq -r '.[] | select(.filename | test("^static/images\/.+(.png|.svg|.gif|.)")) | .filename | sub("^static/";"")')
64+
65+
# Get all changed embeds files
66+
CHANGED_EMBED_FILES=$(curl -Ls \
67+
-H "Accept: application/vnd.github+json" \
68+
-H "X-GitHub-Api-Version: 2022-11-28" \
69+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
70+
$FILES_URL \
71+
| jq -r '.[] | select(.filename | test("^content/embeds\/.+.md")) | .filename | split("/")[-1]')
72+
73+
if [[ -n "$CHANGED_IMAGE_FILES" ]]
74+
then
75+
# For each image, work out in which README it is present
76+
MD_FILES_WITH_IMAGE=()
77+
for CHANGED_IMAGE_FILE in "${CHANGED_IMAGE_FILES[@]}"; do
78+
MD_FILE_WITH_IMAGE=$(grep -ro "$CHANGED_IMAGE_FILE" content \
79+
| sed -E -e 's|:.+||' -e "s|^content/|https://redis.io/docs/staging/$BRANCH_NAME/|" -e 's|(_?index)?\.md||' \
80+
| grep -v "https://redis.io/docs/staging/$BRANCH_NAME/embeds/" \
81+
| sort \
82+
| uniq)
83+
MD_FILES_WITH_IMAGE+=($MD_FILE_WITH_IMAGE)
84+
done
85+
CHANGED_MD_FILES=$(printf "%s\n" "${CHANGED_MD_FILES}" "${MD_FILES_WITH_IMAGE[@]}" \
86+
| sort \
87+
| uniq)
88+
fi
89+
90+
if [[ -n "$CHANGED_EMBED_FILES" ]]
91+
then
92+
# For each embed, work out in which README it is present
93+
MD_FILES_WITH_EMBED=()
94+
for CHANGED_EMBED_FILE in "${CHANGED_EMBED_FILES[@]}"; do
95+
MD_FILE_WITH_EMBED=$(grep -ro "< embed-md \"${CHANGED_EMBED_FILE}\" >" content \
96+
| sed -E -e 's|:.+||' -e "s|^content/|https://redis.io/docs/staging/$BRANCH_NAME/|" -e 's|(_?index)?\.md||' \
97+
| sort \
98+
| uniq)
99+
MD_FILES_WITH_EMBED+=($MD_FILE_WITH_EMBED)
100+
done
101+
CHANGED_MD_FILES=$(printf "%s\n" "${CHANGED_MD_FILES}" "${MD_FILES_WITH_EMBED[@]}" \
102+
| sort \
103+
| uniq)
104+
fi
105+
106+
CHANGED_MD_FILES=$(printf "%s\n" "${CHANGED_MD_FILES}" \
107+
| xargs \
108+
| sed 's/ /<br>/g')
109+
110+
if [[ -z "$CHANGED_MD_FILES" ]]
111+
then
112+
if [[ -z "$EXISTING_COMMENT_ID" ]]
113+
then
114+
printf '%s\n' 'Nothing to do!'
115+
exit 0
116+
else
117+
# If a comment already exists but there are no changed files in the PR anymore, delete the comment
118+
curl -Ls \
119+
-X DELETE \
120+
-H "Accept: application/vnd.github+json" \
121+
-H "X-GitHub-Api-Version: 2022-11-28" \
122+
-H "Authorization: token ${GITHUB_TOKEN}" \
123+
"${UPDATE_COMMENT_URL}/${EXISTING_COMMENT_ID}"
124+
printf '%s\n' 'Comment deleted!'
125+
exit 0
126+
fi
127+
fi
128+
129+
COMMENT="Staging links:<br> $CHANGED_MD_FILES"
130+
131+
printf '%s %s\n' 'Writing comment: ' "$COMMENT"
132+
133+
generate_post_data()
134+
{
135+
cat <<EOF
136+
{
137+
"body": "$COMMENT"
138+
EOF
139+
}
140+
141+
if [[ -n "$EXISTING_COMMENT_ID" ]]
142+
then
143+
# Update comment on pull request if comment is actually different
144+
if [[ "$COMMENT" != "$EXISTING_COMMENT" ]]
145+
then
146+
curl -Ls \
147+
-X PATCH \
148+
-H "Accept: application/vnd.github+json" \
149+
-H "X-GitHub-Api-Version: 2022-11-28" \
150+
-H "Authorization: token ${GITHUB_TOKEN}" \
151+
"${UPDATE_COMMENT_URL}/${EXISTING_COMMENT_ID}" \
152+
--data "$(generate_post_data)" 1>/dev/null
153+
154+
printf '%s\n' 'Comment updated!'
155+
else
156+
printf '%s\n' 'Nothing changed!'
157+
fi
158+
else
159+
# Write comment on pull request
160+
curl -Ls \
161+
-X POST \
162+
-H "Accept: application/vnd.github+json" \
163+
-H "X-GitHub-Api-Version: 2022-11-28" \
164+
-H "Authorization: token ${GITHUB_TOKEN}" \
165+
$CREATE_COMMENT_URL \
166+
--data "$(generate_post_data)" 1>/dev/null
167+
168+
printf '%s\n' 'Comment written!'
169+
fi

0 commit comments

Comments
 (0)