Skip to content

Commit f178ce3

Browse files
committed
Track all commits on doc-en master, not just merged PRs
Replace the PR-based approach with a single pass over all commits on master. No commit is filtered out based on PR association.
1 parent fccd586 commit f178ce3

1 file changed

Lines changed: 58 additions & 36 deletions

File tree

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
#!/usr/bin/env bash
22
#
3-
# Track merged PRs in php/doc-en and create issues in doc-fr
3+
# Track changes in php/doc-en and create issues in doc-fr
44
# for files that need translation updates.
55
#
66
# How it works:
7-
# - Fetches PRs merged in doc-en during the last 7 days
8-
# - For each PR, checks if a matching issue already exists in doc-fr
7+
# - Fetches all commits on doc-en master from the last 7 days
8+
# - For each commit, checks if a matching issue already exists in doc-fr
99
# - If not, creates one listing the FR files to update
1010
#
1111
# Why 7 days: the action runs daily, so 7 days gives us 6 days of margin.
1212
# Even if the action fails for a whole week, nothing is missed.
13-
# Duplicates are prevented by searching for the PR number in existing issue titles.
13+
# Duplicates are prevented by searching for the commit SHA (or associated PR
14+
# number for backward compat) in existing issue titles.
1415
#
1516
set -euo pipefail
1617

1718
SINCE=$(date -u -d '7 days ago' '+%Y-%m-%dT%H:%M:%SZ')
18-
echo "Checking doc-en PRs merged since $SINCE"
19+
echo "Checking doc-en commits on master since $SINCE"
1920

20-
# Fetch merged PRs from the last 7 days (max 100 per page, paginate if needed)
21+
# Fetch all commits on master from the last 7 days (paginate if needed)
2122
PAGE=1
22-
ALL_PRS="[]"
23+
ALL_SHAS=""
2324
while :; do
24-
BATCH=$(gh api "repos/php/doc-en/pulls?state=closed&sort=updated&direction=desc&per_page=100&page=$PAGE" \
25-
--jq "[.[] | select(.merged_at != null and .merged_at >= \"$SINCE\")]")
26-
COUNT=$(echo "$BATCH" | jq 'length')
27-
ALL_PRS=$(echo "$ALL_PRS $BATCH" | jq -s 'add')
28-
echo " Page $PAGE: $COUNT merged PR(s)"
25+
BATCH=$(gh api "repos/php/doc-en/commits?sha=master&since=$SINCE&per_page=100&page=$PAGE" \
26+
--jq '.[].sha' 2>/dev/null || true)
27+
COUNT=$(echo "$BATCH" | grep -c . 2>/dev/null || echo "0")
28+
if [ -n "$BATCH" ]; then
29+
ALL_SHAS="$ALL_SHAS"$'\n'"$BATCH"
30+
fi
31+
echo " Page $PAGE: $COUNT commit(s)"
2932
if [ "$COUNT" -lt 100 ]; then
3033
break
3134
fi
3235
PAGE=$((PAGE + 1))
3336
done
3437

35-
TOTAL=$(echo "$ALL_PRS" | jq 'length')
36-
echo "Total: $TOTAL merged PR(s) in the last 7 days"
38+
echo "$ALL_SHAS" | sed '/^$/d' > /tmp/commits.txt
39+
TOTAL=$(wc -l < /tmp/commits.txt)
40+
echo "Total: $TOTAL commit(s) on master in the last 7 days"
3741

3842
if [ "$TOTAL" -eq 0 ]; then
3943
echo "Nothing to do."
@@ -43,37 +47,52 @@ fi
4347
CREATED=0
4448
SKIPPED=0
4549

46-
# Process each PR (write to temp file to avoid broken pipe with while loop)
47-
echo "$ALL_PRS" | jq -c '.[]' > /tmp/prs.jsonl
50+
while read -r SHA; do
51+
[ -z "$SHA" ] && continue
52+
53+
SHORT_SHA=${SHA:0:7}
4854

49-
while read -r PR; do
50-
PR_NUMBER=$(echo "$PR" | jq -r '.number')
51-
PR_TITLE=$(echo "$PR" | jq -r '.title')
52-
PR_MERGED_AT=$(echo "$PR" | jq -r '.merged_at')
53-
PR_MERGE_DATE=$(echo "$PR_MERGED_AT" | cut -dT -f1)
55+
# Get commit info (single API call)
56+
COMMIT_DATA=$(gh api "repos/php/doc-en/commits/$SHA" \
57+
--jq '{msg: (.commit.message | split("\n")[0]), date: .commit.author.date, author: (.author.login // .commit.author.name), files: [.files[].filename]}' 2>/dev/null)
58+
COMMIT_MSG=$(echo "$COMMIT_DATA" | jq -r '.msg')
59+
COMMIT_DATE=$(echo "$COMMIT_DATA" | jq -r '.date' | cut -dT -f1)
60+
COMMIT_AUTHOR=$(echo "$COMMIT_DATA" | jq -r '.author')
5461

5562
echo ""
56-
echo "PR #$PR_NUMBER: $PR_TITLE"
63+
echo "Commit $SHORT_SHA by $COMMIT_AUTHOR: $COMMIT_MSG"
5764

58-
# Skip PRs marked with [skip-revcheck] (no translation update needed)
59-
if echo "$PR_TITLE" | grep -qi '\[skip-revcheck\]'; then
65+
# Skip commits marked with [skip-revcheck]
66+
if echo "$COMMIT_MSG" | grep -qi '\[skip-revcheck\]'; then
6067
echo " -> [skip-revcheck], skipping."
6168
SKIPPED=$((SKIPPED + 1))
6269
continue
6370
fi
6471

65-
# Deduplication: search for the doc-en PR URL in existing issues
66-
EXISTING=$(gh issue list --repo "$GH_REPO" --search "\"doc-en/pull/$PR_NUMBER\"" \
72+
# Deduplication: search for the full commit SHA in existing issues
73+
EXISTING=$(gh issue list --repo "$GH_REPO" --search "\"$SHA\"" \
6774
--state all --json number --jq 'length')
6875
if [ "$EXISTING" -gt 0 ]; then
69-
echo " -> Issue already exists, skipping."
76+
echo " -> Issue already exists (by SHA), skipping."
7077
SKIPPED=$((SKIPPED + 1))
7178
continue
7279
fi
7380

74-
# Get files changed in this PR
75-
FILES=$(gh api "repos/php/doc-en/pulls/$PR_NUMBER/files?per_page=100" \
76-
--jq '.[].filename' 2>/dev/null || true)
81+
# Backward compat: if commit is associated with a PR, also check by PR number
82+
PR_NUMBER=$(gh api "repos/php/doc-en/commits/$SHA/pulls" \
83+
--jq '.[0].number // empty' 2>/dev/null || true)
84+
if [ -n "$PR_NUMBER" ]; then
85+
EXISTING=$(gh issue list --repo "$GH_REPO" --search "\"doc-en/pull/$PR_NUMBER\"" \
86+
--state all --json number --jq 'length')
87+
if [ "$EXISTING" -gt 0 ]; then
88+
echo " -> Issue already exists (by PR #$PR_NUMBER), skipping."
89+
SKIPPED=$((SKIPPED + 1))
90+
continue
91+
fi
92+
fi
93+
94+
# Get files changed in this commit
95+
FILES=$(echo "$COMMIT_DATA" | jq -r '.files[]')
7796

7897
if [ -z "$FILES" ]; then
7998
echo " -> No files found, skipping."
@@ -85,7 +104,6 @@ while read -r PR; do
85104
NEW_LIST=""
86105

87106
while IFS= read -r FILE; do
88-
# Skip files that should not be translated (e.g. versions.xml)
89107
if [[ "$FILE" == */versions.xml ]]; then
90108
continue
91109
fi
@@ -102,8 +120,12 @@ while read -r PR; do
102120
continue
103121
fi
104122

105-
# Build issue body
106-
BODY="PR: \`https://github.com/php/doc-en/pull/$PR_NUMBER\` ($PR_MERGE_DATE)"$'\n'
123+
# Build issue body (plain text, no links or mentions)
124+
if [ -n "$PR_NUMBER" ]; then
125+
BODY="PR: \`doc-en#$PR_NUMBER\` ($COMMIT_DATE)"$'\n'
126+
else
127+
BODY="Commit: \`$SHORT_SHA\` ($COMMIT_DATE)"$'\n'
128+
fi
107129

108130
if [ -n "$UPDATE_LIST" ]; then
109131
BODY+=$'\n'"**Fichiers FR à mettre à jour**"$'\n'
@@ -116,7 +138,7 @@ while read -r PR; do
116138
fi
117139

118140
# Create the issue
119-
ISSUE_TITLE="[Sync EN] $PR_TITLE"
141+
ISSUE_TITLE="[Sync EN] $COMMIT_MSG"
120142
echo "$BODY" | gh issue create \
121143
--repo "$GH_REPO" \
122144
--title "$ISSUE_TITLE" \
@@ -125,7 +147,7 @@ while read -r PR; do
125147

126148
echo " -> Issue created."
127149
CREATED=$((CREATED + 1))
128-
done < /tmp/prs.jsonl
150+
done < /tmp/commits.txt
129151

130152
echo ""
131-
echo "Done. Created: $CREATED, Skipped (already exist): $SKIPPED"
153+
echo "Done. Created: $CREATED, Skipped: $SKIPPED"

0 commit comments

Comments
 (0)