Skip to content

Commit c67b75a

Browse files
committed
Add PHP API Ref to preview comment (#2716)
* Add PHP API Reference's new entries to preview comment (cherry picked from commit dc56e45)
1 parent 82b8a62 commit c67b75a

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

.github/workflows/preview_comment.yaml

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Post preview links for changed files"
1+
name: 'Preview comment'
22

33
on:
44
pull_request: ~
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
post-preview-links:
15-
name: Post preview links for changed files
15+
name: 'Post preview links for changed files'
1616
runs-on: ubuntu-latest
1717
permissions:
1818
# Needed to manage the comment
@@ -30,15 +30,28 @@ jobs:
3030
file_limit=100
3131
build_url="https://ez-systems-developer-documentation--${{ github.event.pull_request.number }}.com.readthedocs.build/${{inputs.project}}en/${{ github.event.pull_request.number }}/"
3232
33-
change_list=$(git diff --name-only HEAD "origin/$GITHUB_BASE_REF" | grep -E "^docs\/.*\.md$" | sed -E "s|^docs/(.*)\.md$|- [docs/\1.md](${build_url}\1/)|")
34-
change_count=$(echo "$change_list" | wc -l)
33+
md_change_list=$(git diff --name-only HEAD "origin/$GITHUB_BASE_REF" -- docs/ | grep -E "^docs\/.*\.md$" | sed -E "s|^docs/(.*)\.md$|- [docs/\1.md](${build_url}\1/)|")
34+
par_change_list='';
35+
for par_file in $(git diff --diff-filter=A --name-only "origin/$GITHUB_BASE_REF" HEAD -- docs/api/php_api/php_api_reference/ | grep -E '^docs\/.*\.html$'); do
36+
fqcn=$(grep -o 'data-copy-value=".*">Copy FQCN' $par_file | sed -E 's|data-copy-value="(.*)">.*|\1|' | sed 's|\\|\\\\|g')
37+
link=$(echo $par_file | sed -E "s|^docs/(.*\.html)$|- [\`${fqcn}\`](${build_url}\1)|")
38+
par_change_list=$(echo -e "$par_change_list\n$link")
39+
done
40+
par_change_list=$(echo "$par_change_list" | sed '1d')
41+
change_count=$(( $(echo "$md_change_list" | wc -l) + $(echo "$par_change_list" | wc -l) ))
3542
36-
if [[ $change_list -eq '' ]] ; then
37-
comment="Preview of modified Markdown: no Markdown change to preview."
43+
if [[ -z "$md_change_list$par_change_list" ]] ; then
44+
comment="Preview of modified files: no change to preview."
3845
elif [[ $change_count -gt $file_limit ]] ; then
39-
comment="Preview of modified Markdown: Too many files modified in a single PR, preview link list is skipped. ($change_count files &gth; $file_limit)"
46+
comment="Preview of modified files: Too many files modified in a single PR, preview link list is skipped. ($change_count files &gth; $file_limit)"
4047
else
41-
comment="Preview of modified Markdown:\n\n$change_list"
48+
comment="# Preview of modified files"
49+
if [[ -n "$md_change_list" ]]; then
50+
comment="$comment\n\nPreview of modified Markdown:\n\n$md_change_list"
51+
fi
52+
if [[ -n "$par_change_list" ]]; then
53+
comment="$comment\n\nPreview of addition to PHP API Reference:\n\n$par_change_list"
54+
fi
4255
fi
4356
4457
echo -e "$comment" > comment.md
@@ -49,7 +62,7 @@ jobs:
4962
with:
5063
issue-number: ${{ github.event.pull_request.number }}
5164
comment-author: 'github-actions[bot]'
52-
body-includes: 'Preview of modified Markdown'
65+
body-includes: 'Preview of modified files'
5366

5467
- name: Create or update comment
5568
uses: peter-evans/create-or-update-comment@v4

0 commit comments

Comments
 (0)