Skip to content

Commit 735b061

Browse files
committed
Remove 'pull_request_target' trigger
1 parent efeacd7 commit 735b061

2 files changed

Lines changed: 84 additions & 52 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: TODO
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**/*.po"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
generate-pr-comment:
13+
name: TODO
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- uses: actions/checkout@v6
17+
with:
18+
fetch-depth: 2
19+
persist-credentials: false
20+
- name: TODO
21+
uses: actions/setup-python@v7
22+
with:
23+
python-version: "3.13"
24+
cache: "pip"
25+
- name: Instalar dependencias
26+
run: python -m pip install -r requirements-own.txt
27+
- name: TODO
28+
env:
29+
PR_NUMBER: ${{ github.event.pull_request.number }}
30+
run: |
31+
mkdir -p out
32+
git diff -z --name-only --diff-filter=ACMR HEAD^1 HEAD -- '*.po' > out/changed.txt
33+
if [[ ! -s out/changed.txt ]]; then
34+
exit 0
35+
fi
36+
echo "$PR_NUMBER" > out/pr-number
37+
xargs -0 python scripts/list_missing_entries.py --github < out/changed.txt > out/comment.md
38+
- uses: actions/upload-artifact@v5
39+
with:
40+
name: missing-entries
41+
path: |
42+
out/pr-number
43+
out/comment.md
44+
if-no-files-found: ignore
45+
retention-days: 1

‎.github/workflows/pr-comment.yml‎

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,55 @@
11
name: Agrega comentario a PR
22

33
on:
4-
pull_request_target:
4+
workflow_run:
5+
workflows: ["TODO"]
6+
types: [completed]
57

6-
permissions:
7-
contents: read
8+
permissions: {}
89

910
jobs:
10-
define-comment:
11-
name: Entradas sin traducción
11+
write-comment:
1212
runs-on: ubuntu-22.04
13-
outputs:
14-
any_changed: ${{ steps.changed-files.outputs.any_changed }}
15-
comment: ${{ steps.create-pr-comment.outputs.comment }}
13+
if: >-
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion == 'success'
16+
permissions:
17+
actions: read
18+
pull-requests: write
1619
steps:
17-
- uses: actions/checkout@v6
18-
with:
19-
ref: ${{ github.event.pull_request.head.sha }}
20-
persist-credentials: false
21-
- name: Preparar Python v3.13
22-
uses: actions/setup-python@v7
23-
with:
24-
python-version: "3.13"
25-
cache: "pip"
26-
# checkout these files from the base branch to guarantee they haven't been
27-
# modified by the PR
28-
- uses: actions/checkout@v6
29-
with:
30-
path: base-branch
31-
sparse-checkout-cone-mode: false
32-
sparse-checkout: |
33-
requirements-own.txt
34-
scripts/list_missing_entries.py
35-
- name: Instalar dependencias
36-
run: |
37-
python -m pip install -r base-branch/requirements-own.txt
38-
- name: Obtiene lista de archivos con cambios
39-
id: changed-files
40-
uses: tj-actions/changed-files@v47
20+
- uses: actions/download-artifact@v5
21+
continue-on-error: true
4122
with:
42-
files: |
43-
**/*.po
44-
- name: Calcular entradas faltantes
45-
if: steps.changed-files.outputs.any_changed == 'true'
46-
id: create-pr-comment
23+
name: missing-entries
24+
run-id: ${{ github.event.workflow_run.id }}
25+
github-token: ${{ github.token }}
26+
27+
- name: TODO
28+
id: pr
4729
env:
48-
CHANGED_PO_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
30+
GH_TOKEN: ${{ github.token }}
31+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
4932
run: |
50-
{
51-
echo 'comment<<EOF'
52-
python base-branch/scripts/list_missing_entries.py --github $CHANGED_PO_FILES
53-
echo EOF
54-
} >> "$GITHUB_OUTPUT"
33+
if [[ ! -f pr-number ]]; then
34+
echo 'TODO'
35+
exit 0
36+
fi
37+
pr="$(head -n1 pr-number)"
38+
if [[ ! "$pr" =~ ^[0-9]+$ ]]; then
39+
echo 'TODO'
40+
exit 1
41+
fi
42+
actual_sha="$(gh api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .head.sha)"
43+
if [[ "actual_sha" != "$HEAD_SHA" ]]; then
44+
echo 'TODO'
45+
exit 0
46+
fi
47+
echo "pr=$pr" >> "$GITHUB_OUTPUT"
5548
56-
write-comment:
57-
runs-on: ubuntu-22.04
58-
needs: [define-comment]
59-
if: needs.define-comment.outputs.any_changed == 'true'
60-
permissions:
61-
issues: write
62-
pull-requests: write
63-
steps:
6449
- name: Agregar comentario con entradas faltantes
50+
if: steps.pr.outputs.pr != ''
6551
uses: thollander/actions-comment-pull-request@v3
6652
with:
67-
message: ${{ needs.define-comment.outputs.comment }}
53+
file-path: comment.md
54+
pr-number: ${{ steps.pr.outputs.pr }}
6855
comment-tag: missing-entries

0 commit comments

Comments
 (0)