Skip to content

feat: action to create new PR for post #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/create_new_post_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Create New Post PR
description: Creates a new PR. The PR's body will be used to populate a new post in my blog.

on:
workflow_dispatch:
inputs:
name:
type: string
required: true
description: Name of the branch to create. It will be lowercased and all spaces will be replaced by dashes.

jobs:
create-branch-and-pr:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create new branch
id: create_branch
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
branch_name=$(echo "${{ github.event.inputs.name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
echo "Branch name: ${branch_name}"
git checkout -b "$branch_name"
git push origin "$branch_name"
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT

- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.create_branch.outputs.branch_name }}
base: main
title: posts/${{ steps.create_branch.outputs.branch_name }}
body-path: '${{ github.workspace }}/.github/PULL_REQUEST_TEMPLATE/post.md'
labels: 'post'
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: Create Post from PR
name: Generate post from PR
description: When a PR that has label `post` is merged, this action will generate a new post from the PR's body.

on:
pull_request:
types: [labeled, closed]

jobs:
create_post:
generate_post:
if: ${{ (github.event.pull_request.merged == true && github.event.label.name == 'post') }}
runs-on: ubuntu-latest

Expand All @@ -16,7 +17,8 @@ jobs:
- name: Create post file
id: create_post
run: |
PR_TITLE=$(echo "${{ github.event.pull_request.title }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
PR_TITLE=${{ github.event.pull_request.title }}
PR_TITLE=${PR_TITLE#post/}
DATE=$(date +'%Y-%m-%d')
PR_TITLE="${DATE}-${PR_TITLE}"
PR_BODY=${{ github.event.pull_request.body }}
Expand Down