Skip to content
Open
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
43 changes: 43 additions & 0 deletions template-files/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Automerge

on:
pull_request:
types:
- opened
- reopened
- ready_for_review
- synchronize
- labeled
- unlabeled
pull_request_review:
types:
- submitted
check_suite:
types:
- completed
status: {}
workflow_dispatch:
repository_dispatch:
types:
- automerge-pull-request

permissions:
contents: write
pull-requests: write

jobs:
automerge:
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Merge pull requests
uses: pascalgn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERGE_LABELS: automerge
MERGE_REMOVE_LABELS: automerge
MERGE_METHOD: squash
MERGE_DELETE_BRANCH: "true"
MERGE_COMMIT_MESSAGE: pull-request-title
UPDATE_LABELS: automerge
109 changes: 109 additions & 0 deletions template-files/create-automerge-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Create Automerge PR

on:
workflow_dispatch:
inputs:
head:
description: The branch to merge into the base branch
required: true
base:
description: The base branch to merge into
required: false
default: main
title:
description: The pull request title
required: false
body:
description: The pull request body
required: false
labels:
description: Comma separated list of labels to apply
required: false
default: automerge
repository_dispatch:
types:
- create-automerge-pr

permissions:
contents: write
pull-requests: write

jobs:
create-pr:
runs-on: ubuntu-latest
env:
HEAD_BRANCH: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.head || github.event.client_payload.head }}
BASE_BRANCH: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.base || github.event.client_payload.base || 'main' }}
PR_TITLE: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.title || github.event.client_payload.title || '' }}
PR_BODY: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.body || github.event.client_payload.body || '' }}
PR_LABELS: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.labels || github.event.client_payload.labels || 'automerge' }}
steps:
- name: Validate input
uses: actions/github-script@v7
with:
script: |
if (!process.env.HEAD_BRANCH) {
core.setFailed('A head branch must be provided via workflow inputs or repository_dispatch payload.');
}
- name: Create pull request
id: create_pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const head = process.env.HEAD_BRANCH;
const base = process.env.BASE_BRANCH;
const title = process.env.PR_TITLE || `Automated update from ${head}`;
const body = process.env.PR_BODY || 'This pull request was created automatically.';

try {
const response = await github.rest.pulls.create({ owner, repo, head, base, title, body });
core.setOutput('pull_number', response.data.number.toString());
core.setOutput('html_url', response.data.html_url);
} catch (error) {
if (error.status === 422) {
core.info('A matching pull request already exists or the branch is unavailable. Skipping creation.');
core.setOutput('skipped', 'true');
return;
}
throw error;
}
- name: Add labels
if: steps.create_pr.outputs.skipped != 'true'
uses: actions/github-script@v7
env:
PULL_NUMBER: ${{ steps.create_pr.outputs.pull_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = (process.env.PR_LABELS || '').split(',').map(label => label.trim()).filter(Boolean);
if (!labels.length) {
core.info('No labels provided. Skipping label application.');
return;
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(process.env.PULL_NUMBER),
labels,
});
- name: Dispatch automerge workflow
if: steps.create_pr.outputs.skipped != 'true'
uses: actions/github-script@v7
env:
PULL_NUMBER: ${{ steps.create_pr.outputs.pull_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: 'automerge-pull-request',
client_payload: {
pull_number: Number(process.env.PULL_NUMBER),
},
});
core.info(`Triggered automerge workflow for pull request #${process.env.PULL_NUMBER}.`);