[New Project Title]: Image Gen #3
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: Update Project List on Issue Close | |
on: | |
issues: | |
types: [closed] | |
jobs: | |
update-project-list: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
issues: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Extract project details from issue | |
id: extract_issue | |
run: | | |
ISSUE_NUMBER="${{ github.event.issue.number }}" | |
echo "Fetching issue #$ISSUE_NUMBER" | |
ISSUE_JSON=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER") | |
PROJECT_NAME=$(echo "$ISSUE_JSON" | jq -r '.title' | sed 's/\[Project Submission\]: //') | |
PROJECT_DESC=$(echo "$ISSUE_JSON" | jq -r '.body' | grep -A100 '### Project Description' | tail -n +2 | sed '/^### /Q') | |
PROJECT_URL=$(echo "$ISSUE_JSON" | jq -o 'https://[^\s"]*' | head -1) | |
CONTACT=$(echo "$ISSUE_JSON" | jq -r '.body' | grep -A100 '### Contact Information' | tail -n +2 | sed '/^### /Q') | |
if [ -z "$PROJECT_NAME" ] || [ -z "$PROJECT_DESC" ]; then | |
echo "Error extracting project details. Skipping." | |
exit 1 | |
fi | |
echo "Project Name: $PROJECT_NAME" | |
echo "Project Description: $PROJECT_DESC" | |
echo "Project URL: $PROJECT_URL" | |
echo "Contact: $CONTACT" | |
NEW_ENTRY=$(jq -n --arg name "$PROJECT_NAME" --arg desc "$PROJECT_DESC" --arg url "$PROJECT_URL" --arg contact "$CONTACT" \ | |
'{name: $name, description: $desc, url: $url, contact: $contact}') | |
echo "$NEW_ENTRY" > new_project.json | |
- name: Ensure projects.json exists | |
run: | | |
if [ ! -f projects.json ]; then | |
echo "[]"> projects.json | |
fi | |
- name: Update projects.json | |
run: | | |
jq --slurpfile new new_project.json '. + $new' projects.json > temp.json && mv temp.json projects.json | |
- name: Commit and Push Changes | |
env: | |
GH_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
git config --global user.name "GitHub Actions Bot" | |
git config --global user.email "actions@github.com" | |
git add projects.json | |
git commit -m "Updated projects list from issue #${{ github.event.issue.number }}" || echo "No changes to commit" | |
git push https://x-access-token:${PAT_TOKEN}@github.com/${{ github.repository }}.git main |