diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml new file mode 100644 index 0000000..691aaec --- /dev/null +++ b/.github/workflows/test-action.yml @@ -0,0 +1,34 @@ +name: Test Action + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test-action: + name: Test create PR on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + steps: + - name: Checkout the repo + uses: actions/checkout@v4.1.1 + + - name: Create Pull Request + id: create_pr + uses: ./ + with: + title: 'Automated Pull Request' + sourceBranch: ${{ github.ref_name }} + targetBranch: 'main' + body: 'This is an automated pull request.' + labels: 'automated,pr' + assignees: 'octocat' + + - name: Output PR URL + run: echo "The PR URL is ${{ steps.create_pr.outputs.PRURL }}" diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2d5e9c --- /dev/null +++ b/README.md @@ -0,0 +1,68 @@ +# Remote Branch Action + +[![Test Action](https://github.com/JosiahSiegel/reliable-pull-request-action/actions/workflows/test-action.yml/badge.svg)](https://github.com/JosiahSiegel/reliable-pull-request-action/actions/workflows/test-action.yml) + +## Synopsis + +1. Create a pull request on a GitHub repository using existing branches. +2. [actions/checkout](https://github.com/actions/checkout) determins the active repo. + +## Usage + +```yml +jobs: + create-pr: + name: Test create PR on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + steps: + - name: Checkout the repo + uses: actions/checkout@v4.1.1 + + - name: Create Pull Request + id: create_pr + uses: josiahsiegel/reliable-pull-request-action@v1.0.0 + with: + title: 'Automated Pull Request' + sourceBranch: ${{ github.ref_name }} + targetBranch: 'main' + body: 'This is an automated pull request.' + labels: 'automated,pr' + assignees: 'octocat' + + - name: Output PR URL + run: echo "The PR URL is ${{ steps.create_pr.outputs.PRURL }}" +``` + +## Inputs + +```yml +inputs: + title: + description: 'Pull Request Title' + required: true + sourceBranch: + description: 'Source Branch Name' + required: true + targetBranch: + description: 'Target Branch Name' + required: true + body: + description: 'Pull Request Body' + required: false + labels: + description: 'Labels (comma-separated)' + required: false + assignees: + description: 'Assignees (comma-separated)' + required: false +``` + +## Outputs +```yml +outputs: + PRURL: + description: 'The URL of the created pull request' +``` \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..573a91a --- /dev/null +++ b/action.yml @@ -0,0 +1,40 @@ +name: Reliable Pull Request Action +description: Creates a pull request on a GitHub repository using existing branches +branding: + icon: 'git-pull-request' + color: 'blue' +inputs: + title: + description: 'Pull Request Title' + required: true + sourceBranch: + description: 'Source Branch Name' + required: true + targetBranch: + description: 'Target Branch Name' + required: true + body: + description: 'Pull Request Body' + required: false + labels: + description: 'Labels (comma-separated)' + required: false + assignees: + description: 'Assignees (comma-separated)' + required: false +outputs: + PRURL: + description: 'The URL of the created pull request' +runs: + using: 'composite' + steps: + - name: Create Pull Request + shell: bash + run: bash create-pr.sh + env: + INPUT_TITLE: ${{ inputs.title }} + INPUT_SOURCEBRANCH: ${{ inputs.sourceBranch }} + INPUT_TARGETBRANCH: ${{ inputs.targetBranch }} + INPUT_BODY: ${{ inputs.body }} + INPUT_LABELS: ${{ inputs.labels }} + INPUT_ASSIGNEES: ${{ inputs.assignees }} diff --git a/create-pr.sh b/create-pr.sh new file mode 100644 index 0000000..00aa801 --- /dev/null +++ b/create-pr.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Create Pull Request and capture the output +PR_OUTPUT=$(gh pr create \ + --title "$INPUT_TITLE" \ + --body "$INPUT_BODY" \ + --base "$INPUT_TARGETBRANCH" \ + --head "$INPUT_SOURCEBRANCH" \ + --label "$INPUT_LABELS" \ + --assignee "$INPUT_ASSIGNEES") + +# Extract PR URL from the output +PR_URL=$(echo "$PR_OUTPUT" | grep -o 'https://github.com/[^ ]*') + +# Set the PR URL as the output +echo "::set-output name=PRURL::$PR_URL"