Skip to content

Commit

Permalink
Merge pull request #43 from AztecProtocol/mt/support-redo-typo-prs
Browse files Browse the repository at this point in the history
copy workflows from aztec packages
  • Loading branch information
just-mitch authored Nov 25, 2024
2 parents 0ddf508 + 3a6d271 commit 724774c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/redo-typo-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Redo Typo PR

on:
workflow_dispatch:
inputs:
pr_number:
description: "The PR number to redo"
required: true
type: string

pull_request_target:
types: [labeled]
branches:
- master
paths-ignore:
- "**/README.md"

jobs:
redo-typo-pr:
if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'redo-typo-pr')
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}

- name: Authenticate with GitHub CLI
run: |
echo "${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}" | gh auth login --with-token
- name: Set git configure for commits
run: |
# Identify ourselves, needed to commit
git config --global user.name AztecBot
git config --global user.email [email protected]
- name: Determine PR number
id: determine-pr-number
run: echo "PR_NUMBER=${{ github.event.inputs.pr_number || github.event.pull_request.number }}" >> $GITHUB_ENV

- name: Run repo-typo-pr script
run: ./scripts/redo-typo-pr ${{ env.PR_NUMBER }}
37 changes: 37 additions & 0 deletions scripts/redo-typo-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -eux

# Configuration
ORIGINAL_PR_NUMBER=$1
REPO='AztecProtocol/engineering-designs'
NEW_BRANCH="chore/typo-redo-$ORIGINAL_PR_NUMBER"
AUTHOR=`gh pr view $ORIGINAL_PR_NUMBER --json author --jq '.author.login'`

# Step 1: Checkout the PR locally
echo "Checking out PR #$ORIGINAL_PR_NUMBER"
gh pr checkout $ORIGINAL_PR_NUMBER --branch "typo-pr-branch"

# Step 2: Create squash commit on main
echo "Squashing PR branch onto main"
git checkout main
git merge "typo-pr-branch" --squash

# Step 3: Commit squash commit to new branch
echo "Creating new local branch $NEW_BRANCH"
git checkout -b $NEW_BRANCH
git commit -a --author="AztecBot <[email protected]>" -m "chore: redo typo PR"

# Step 4: Push the new branch to GitHub
echo "Pushing new branch $NEW_BRANCH to GitHub"
git push origin $NEW_BRANCH

# Step 5: create a new pull request
echo "Creating a new pull request for $NEW_BRANCH"
gh pr create --base main --head $NEW_BRANCH --title "chore: redo typo PR by $AUTHOR" --body "Thanks $AUTHOR for https://github.com/$REPO/pull/$ORIGINAL_PR_NUMBER. Our policy is to redo typo changes to dissuade metric farming. This is an automated script."

# Step 6: Close the original PR
echo "Closing original PR #$ORIGINAL_PR_NUMBER"
gh pr close $ORIGINAL_PR_NUMBER

echo "Script completed."

0 comments on commit 724774c

Please sign in to comment.