|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # |
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 |
4 | 4 | # for files that need translation updates. |
5 | 5 | # |
6 | 6 | # How it works: |
7 | 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 |
| 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 |
9 | 10 | # - If not, creates one listing the FR files to update |
10 | 11 | # |
11 | 12 | # Why 7 days: the action runs daily, so 7 days gives us 6 days of margin. |
12 | 13 | # 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. |
14 | 16 | # |
15 | 17 | set -euo pipefail |
16 | 18 |
|
@@ -128,4 +130,124 @@ while read -r PR; do |
128 | 130 | done < /tmp/prs.jsonl |
129 | 131 |
|
130 | 132 | 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