Skip to content

Issue to PR Automation #35

Issue to PR Automation

Issue to PR Automation #35

Workflow file for this run

name: Issue to PR Automation
on:
issues:
types: [opened]
jobs:
create_pr:
if: contains(toJson(github.event.issue.labels), '"prompt"')
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Git Config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Extract Issue Data
id: extract_data
uses: actions/github-script@v6
with:
script: |
const issueBody = context.payload.issue.body;
const issueTitle = context.payload.issue.title;
const lines = issueBody.split('\n');
function extractSection(header) {
const sectionLines = [];
let inSection = false;
for (const line of lines) {
if (line.trim().toLowerCase() === `### ${header.toLowerCase()}`) {
inSection = true;
continue;
}
if (inSection && line.startsWith('### ')) {
break;
}
if (inSection) {
sectionLines.push(line);
}
}
return sectionLines.join('\n').trim();
}
const author = extractSection('Author');
const tags = extractSection('Tags');
const promptContent = extractSection('Prompt');
// Base64 encode the prompt content
const promptContentB64 = Buffer.from(promptContent, 'utf-8').toString('base64');
// Set outputs
core.setOutput('PROMPT_NAME', issueTitle);
core.setOutput('AUTHOR', author);
core.setOutput('TAGS', tags);
core.setOutput('PROMPT_CONTENT_B64', promptContentB64);
- name: Debug Extracted Data
run: |
echo "Prompt Name: ${{ steps.extract_data.outputs.PROMPT_NAME }}"
echo "Author: ${{ steps.extract_data.outputs.AUTHOR }}"
echo "Tags: ${{ steps.extract_data.outputs.TAGS }}"
echo "Prompt Content:"
echo "${{ steps.extract_data.outputs.PROMPT_CONTENT_B64 }}" | base64 --decode
- name: Create File from Issue
run: |
#!/bin/bash
set -e
# Retrieve variables
PROMPT_NAME="${{ steps.extract_data.outputs.PROMPT_NAME }}"
AUTHOR="${{ steps.extract_data.outputs.AUTHOR }}"
TAGS="${{ steps.extract_data.outputs.TAGS }}"
PROMPT_CONTENT_B64="${{ steps.extract_data.outputs.PROMPT_CONTENT_B64 }}"
# Sanitize prompt name to create a valid file name
FILE_NAME="$(echo "$PROMPT_NAME" | tr '[:upper:]' '[:lower:]' \
| sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g')"
FILE_PATH="aida-prompts/_prompts/${FILE_NAME}.md"
echo "Creating file at $FILE_PATH"
mkdir -p "$(dirname "$FILE_PATH")"
# Write the front matter to the file
{
echo "---"
echo "title: \"$PROMPT_NAME\""
echo "author: \"$AUTHOR\""
echo "tags: [${TAGS}]"
echo "---"
echo ""
} > "$FILE_PATH"
# Append the prompt content by decoding it directly to the file
echo "$PROMPT_CONTENT_B64" | base64 --decode >> "$FILE_PATH"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Add prompt '${{ steps.extract_data.outputs.PROMPT_NAME }}' from Issue #${{ github.event.issue.number }}"
committer: 'GitHub <[email protected]>'
author: 'Your Name <[email protected]>' # Replace with your name and email
title: "Add Prompt: ${{ steps.extract_data.outputs.PROMPT_NAME }}"
body: |
Adds a new prompt from Issue #${{ github.event.issue.number }}.
Automatically generated by GitHub Actions.
branch: "issue-${{ github.event.issue.number }}"
base: main
delete-branch: false
overwrite-existing: true