Skip to content

Instantly share code, notes, and snippets.

@sewera
Created February 22, 2023 17:50
Show Gist options
  • Save sewera/f9241f4bbc7f73f27b6dde99cc896672 to your computer and use it in GitHub Desktop.
Save sewera/f9241f4bbc7f73f27b6dde99cc896672 to your computer and use it in GitHub Desktop.
Issue to note Github Action
name: Issue to note
concurrency: issue-to-note
on:
issues:
types: [opened, edited]
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Get issue creator
id: get-issue-creator
run: echo "creator=${{ github.event.issue.user.login }}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
if: steps.get-issue-creator.outputs.creator == 'sewera'
- name: Get creation date
id: get-creation-date
if: steps.get-issue-creator.outputs.creator == 'sewera'
run: TIMESTAMP="${{ github.event.issue.created_at }}"; echo "date=${TIMESTAMP:0:10}" >> $GITHUB_OUTPUT
- name: Create a Markdown file
id: create-md-file
if: steps.get-issue-creator.outputs.creator == 'sewera'
shell: bash
run: |
# Extract data
INBOX_DIR="./inbox"
TITLE="${{ github.event.issue.title }}"
FILENAME=$(echo "${TITLE}" | sed -E 's/-/ /g' | sed -E 's/[[:punct:]]//g' | sed -E 's/[[:space:]]/-/g' | tr '[:upper:]' '[:lower:]')
# Create md file
mkdir -p "${INBOX_DIR}"
cat <<'EOF' > "${INBOX_DIR}/${FILENAME}.md"
# ${{ github.event.issue.title }}
${{ github.event.issue.body }}
---
Created ${{ steps.get-creation-date.outputs.date }}
EOF
- name: Push the changes to zettelkasten repository
if: steps.get-issue-creator.outputs.creator == 'sewera'
shell: bash
run: |
REMOTE=https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
BRANCH=master
git config user.email "code+github.actions.bot@sewera.dev"
git config user.name "Blazej Sewera (Github Actions Bot)"
git pull "${REMOTE}"
git checkout "${BRANCH}"
git add -A
git status
git commit -m "feat(inbox): add '${{ github.event.issue.title }}' from issue"
git push "${REMOTE}" "${BRANCH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment