-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (54 loc) · 2.15 KB
/
auto-pr.yml
File metadata and controls
64 lines (54 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Create Pull Request
on:
push:
branches:
- 'feature/**'
- 'bugfix/**'
jobs:
create_pull_request:
runs-on: ubuntu-latest
steps:
# Paso 1: Descargar el código.
# fetch-depth: 0 es crucial para tener todo el historial y evitar problemas.
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Paso 2: Crear el Pull Request usando la CLI oficial de GitHub
- name: Create Pull Request
env:
# El token de GitHub se pasa como una variable de entorno segura.
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# 1. Define a todo el equipo en una lista (array de bash)
ALL_REVIEWERS=("Frasquito3" "LucaTvl" "NiconiKimg" "carlex74")
# 2. Obtén el autor del PR desde las variables de GitHub
PR_AUTHOR="${{ github.actor }}"
# 3. Construye la lista final de revisores, excluyendo al autor
FINAL_REVIEWERS=""
for reviewer in "${ALL_REVIEWERS[@]}"; do
if [[ "$reviewer" != "$PR_AUTHOR" ]]; then
# Si la lista final no está vacía, añade una coma primero
if [[ -n "$FINAL_REVIEWERS" ]]; then
FINAL_REVIEWERS+=",${reviewer}"
else
FINAL_REVIEWERS+="${reviewer}"
fi
fi
done
echo "Autor del PR: ${PR_AUTHOR}"
echo "Revisores finales asignados: ${FINAL_REVIEWERS}"
# Le decimos a la CLI que la rama base es 'develop'
BASE_BRANCH="develop"
# Obtenemos el nombre de nuestra rama feature (ej: 'feature/mi-trabajo')
HEAD_BRANCH="${{ github.ref_name }}"
# Creamos un título y cuerpo para el PR
TITLE="PR: Merge ${HEAD_BRANCH} into ${BASE_BRANCH}"
BODY="Pull Request automático creado para la rama \`${HEAD_BRANCH}\`. Por favor, revisar."
gh pr create \
--base "${BASE_BRANCH}" \
--head "${HEAD_BRANCH}" \
--title "${TITLE}" \
--body "${BODY}" \
--reviewer "${FINAL_REVIEWERS}" \
--label 'automated-pr,needs-review'