[Note Proposal] Chapter 101 (green spells) #5
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: Process Note Proposals | |
on: | |
issues: | |
types: [opened, edited] | |
env: | |
GH_TOKEN: ${{ github.token }} | |
jobs: | |
process-note-proposal: | |
if: contains(github.event.issue.labels.*.name, 'note-proposal') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Git repository | |
uses: actions/checkout@v2 | |
with: | |
ref: master | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
pip install beautifulsoup4 tqdm ruamel.yaml | |
- name: Parse issue and create branch | |
id: parse_issue | |
run: | | |
echo "Parsing issue..." | |
ISSUE_NUMBER=$(echo "${{ github.event.issue.number }}") | |
BRANCH_NAME="note-proposal-${ISSUE_NUMBER}" | |
ISSUE_DATE=$(echo "${{ github.event.issue.created_at }}" | cut -d'T' -f1) | |
echo "##[set-output name=branch_name;]${BRANCH_NAME}" | |
echo "##[set-output name=issue_date;]${ISSUE_DATE}" | |
# Create/reset feature branch from master | |
git checkout -B ${BRANCH_NAME} | |
- name: Add note to YAML file | |
run: | | |
echo "Adding note to YAML file..." | |
python .github/workflow_scripts/add_note.py "${{ github.event.issue.body }}" "${{ steps.parse_issue.outputs.issue_date }}" "${{ github.event.issue.url }}" | |
- name: Commit and push changes | |
run: | | |
echo "Committing changes..." | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
if git diff --staged --quiet; then | |
echo "No changes to commit" | |
else | |
git commit -m "Add note from issue #${{ github.event.issue.number }}" | |
echo "Force pushing changes..." | |
git push -f origin ${{ steps.parse_issue.outputs.branch_name }} | |
fi | |
- name: Comment on issue with PR link | |
run: | | |
ISSUE_NUMBER=$(echo "${{ github.event.issue.number }}") | |
BRANCH_NAME="note-proposal-${ISSUE_NUMBER}" | |
PR_LINK="https://github.com/${{ github.repository }}/compare/${BRANCH_NAME}?expand=1" | |
COMMENT_BODY="A new branch has been created with your note proposal. You can edit the text of your issue to update the note. You can create a pull request using the following link: ${PR_LINK}" | |
gh api -X POST /repos/${{ github.repository }}/issues/${ISSUE_NUMBER}/comments -f body="${COMMENT_BODY}" |