This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
Dispatch para activar el bot #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Dispatch para activar el bot | |
on: | |
issue_comment: | |
types: | |
- created | |
- edited | |
jobs: | |
activate-bot: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Verificar comando de activación | |
id: check-command | |
run: | | |
if [[ $(echo "${{ github.event.comment.body }}" | grep -E '/continuar') ]]; then | |
echo "::set-output name=activate::true" | |
fi | |
- name: Ejecutar bot si se activa | |
if: steps.check-command.outputs.activate == 'true' | |
run: | | |
# Recopilar los datos del usuario desde la conversación del Issue | |
repositoryURL=$(jq -r '.comment.body' ${{ steps.wait-for-user-response.outputs.response-file }} | grep -oP 'repositoryURL:\s*\K[^\n]*') | |
language=$(jq -r '.comment.body' ${{ steps.wait-for-user-response.outputs.response-file }} | grep -oP 'language:\s*\K[^\n]*') | |
symbol=$(jq -r '.comment.body' ${{ steps.wait-for-user-response.outputs.response-file }} | grep -oP 'symbol:\s*\K[^\n]*') | |
year=$(jq -r '.comment.body' ${{ steps.wait-for-user-response.outputs.response-file }} | grep -oP 'year:\s*\K[^\n]*') | |
# Descargar todos los archivos del repositorio y crear ZIP | |
git clone $repositoryURL repo | |
repo_name=$(basename $repositoryURL) | |
cd repo | |
git archive -o temp-files/repo_files.zip HEAD | |
# Subir el archivo ZIP a GitHub | |
response=$(curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/zip" \ | |
--data-binary @repo_files.zip \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/attachments") | |
# Extraer la URL del archivo cargado | |
attachment_url=$(echo "$response" | jq -r .url) | |
# Agregar un comentario con el enlace al archivo | |
comment="Aquí tienes el archivo ZIP: $attachment_url" | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \ | |
-d "{ | |
\"body\": \"$comment\" | |
}" |