Skip to content

Commit dd849f2

Browse files
committed
Track direct commits to doc-en master, not just merged PRs
About 15% of doc-en changes are pushed directly to master without a pull request. These were invisible to the tracking workflow. Add a second pass that fetches all commits on master from the last 7 days, filters out those already covered by a merged PR, and creates sync issues for the remaining direct commits.
1 parent fccd586 commit dd849f2

1 file changed

Lines changed: 126 additions & 4 deletions

File tree

.github/scripts/track-en-changes.sh

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
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:
77
# - 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
8+
# - Fetches commits pushed directly to master (not via a PR)
9+
# - For each change, checks if a matching issue already exists in doc-fr
910
# - If not, creates one listing the FR files to update
1011
#
1112
# Why 7 days: the action runs daily, so 7 days gives us 6 days of margin.
1213
# 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.
14+
# Duplicates are prevented by searching for the PR number or commit SHA
15+
# in existing issue titles.
1416
#
1517
set -euo pipefail
1618

@@ -128,4 +130,124 @@ while read -r PR; do
128130
done < /tmp/prs.jsonl
129131

130132
echo ""
131-
echo "Done. Created: $CREATED, Skipped (already exist): $SKIPPED"
133+
echo "=== Checking direct commits on master ==="
134+
135+
# Fetch commits on master from the last 7 days (paginate if needed)
136+
PAGE=1
137+
ALL_SHAS=""
138+
while :; do
139+
BATCH=$(gh api "repos/php/doc-en/commits?sha=master&since=$SINCE&per_page=100&page=$PAGE" \
140+
--jq '.[].sha' 2>/dev/null || true)
141+
COUNT=$(echo "$BATCH" | grep -c . 2>/dev/null || echo "0")
142+
if [ -n "$BATCH" ]; then
143+
ALL_SHAS="$ALL_SHAS"$'\n'"$BATCH"
144+
fi
145+
echo " Page $PAGE: $COUNT commit(s)"
146+
if [ "$COUNT" -lt 100 ]; then
147+
break
148+
fi
149+
PAGE=$((PAGE + 1))
150+
done
151+
152+
echo "$ALL_SHAS" | sed '/^$/d' > /tmp/commits.txt
153+
TOTAL_COMMITS=$(wc -l < /tmp/commits.txt)
154+
echo "Total: $TOTAL_COMMITS commit(s) on master in the last 7 days"
155+
156+
DIRECT=0
157+
158+
while read -r SHA; do
159+
[ -z "$SHA" ] && continue
160+
161+
# Check if this commit is associated with a PR
162+
PR_COUNT=$(gh api "repos/php/doc-en/commits/$SHA/pulls" --jq 'length' 2>/dev/null || echo "0")
163+
if [ "$PR_COUNT" != "0" ]; then
164+
continue
165+
fi
166+
167+
DIRECT=$((DIRECT + 1))
168+
169+
# Get commit info
170+
COMMIT_MSG=$(gh api "repos/php/doc-en/commits/$SHA" \
171+
--jq '.commit.message | split("\n")[0]' 2>/dev/null)
172+
COMMIT_DATE=$(gh api "repos/php/doc-en/commits/$SHA" \
173+
--jq '.commit.author.date' 2>/dev/null | cut -dT -f1)
174+
COMMIT_AUTHOR=$(gh api "repos/php/doc-en/commits/$SHA" \
175+
--jq '.author.login // .commit.author.name' 2>/dev/null)
176+
SHORT_SHA=${SHA:0:7}
177+
178+
echo ""
179+
echo "Direct commit $SHORT_SHA by $COMMIT_AUTHOR: $COMMIT_MSG"
180+
181+
# Skip commits marked with [skip-revcheck]
182+
if echo "$COMMIT_MSG" | grep -qi '\[skip-revcheck\]'; then
183+
echo " -> [skip-revcheck], skipping."
184+
SKIPPED=$((SKIPPED + 1))
185+
continue
186+
fi
187+
188+
# Deduplication: search for the commit SHA in existing issues
189+
EXISTING=$(gh issue list --repo "$GH_REPO" --search "\"$SHORT_SHA\"" \
190+
--state all --json number --jq 'length')
191+
if [ "$EXISTING" -gt 0 ]; then
192+
echo " -> Issue already exists, skipping."
193+
SKIPPED=$((SKIPPED + 1))
194+
continue
195+
fi
196+
197+
# Get files changed in this commit
198+
FILES=$(gh api "repos/php/doc-en/commits/$SHA" \
199+
--jq '.files[].filename' 2>/dev/null || true)
200+
201+
if [ -z "$FILES" ]; then
202+
echo " -> No files found, skipping."
203+
continue
204+
fi
205+
206+
# Categorize files
207+
UPDATE_LIST=""
208+
NEW_LIST=""
209+
210+
while IFS= read -r FILE; do
211+
if [[ "$FILE" == */versions.xml ]]; then
212+
continue
213+
fi
214+
if [ -f "$FILE" ]; then
215+
UPDATE_LIST="${UPDATE_LIST}- \`${FILE}\`"$'\n'
216+
elif [[ "$FILE" == *.xml ]]; then
217+
NEW_LIST="${NEW_LIST}- \`${FILE}\`"$'\n'
218+
fi
219+
done <<< "$FILES"
220+
221+
# Skip if no FR-relevant files
222+
if [ -z "$UPDATE_LIST" ] && [ -z "$NEW_LIST" ]; then
223+
echo " -> No FR-relevant files, skipping."
224+
continue
225+
fi
226+
227+
# Build issue body
228+
BODY="Commit: [\`$SHORT_SHA\`](https://github.com/php/doc-en/commit/$SHA) by @$COMMIT_AUTHOR ($COMMIT_DATE)"$'\n'
229+
230+
if [ -n "$UPDATE_LIST" ]; then
231+
BODY+=$'\n'"**Fichiers FR à mettre à jour**"$'\n'
232+
BODY+="$UPDATE_LIST"
233+
fi
234+
235+
if [ -n "$NEW_LIST" ]; then
236+
BODY+=$'\n'"**Nouveaux fichiers EN (pas encore traduits)**"$'\n'
237+
BODY+="$NEW_LIST"
238+
fi
239+
240+
# Create the issue
241+
ISSUE_TITLE="[Sync EN] $COMMIT_MSG"
242+
echo "$BODY" | gh issue create \
243+
--repo "$GH_REPO" \
244+
--title "$ISSUE_TITLE" \
245+
--label "sync-en" \
246+
--body-file -
247+
248+
echo " -> Issue created."
249+
CREATED=$((CREATED + 1))
250+
done < /tmp/commits.txt
251+
252+
echo ""
253+
echo "Done. Created: $CREATED, Skipped: $SKIPPED, Direct commits found: $DIRECT"

0 commit comments

Comments
 (0)