Skip to content

Commit

Permalink
✨ New Smart Github Action: replicator (#10)
Browse files Browse the repository at this point in the history
I've successfully created the new Smart Github Action named "replicator"
as per your request. Here's what has been done:

1. **Action Metadata File (`action.yaml`)**: A new action metadata file
for "replicator" has been created, defining the necessary inputs such as
`template-path`, `result-path`, and `characteristics` for the action to
function.

2. **Action Code File (`replicator.py`)**: The Python script for the
"replicator" action has been set up. It's designed to read the specified
template, create a new file or code snippet based on the characteristics
provided, and save it at the specified result path.

3. **Workflow File (`replicator.yaml`)**: A new workflow has been added
to the `.github/workflows` directory, allowing the action to be
triggered manually (`workflow_dispatch`). This workflow requires inputs
for the template path, result path, and characteristics of the result,
aligning with the action's design.

These components together fulfill the task description you provided,
enabling the creation of new files or code snippets based on existing
templates with specified characteristics.

---------

Co-authored-by: PR Pilot <bot@pr-pilot.ai>
Co-authored-by: Marco Lamina <mlamina09@gmail.com>
  • Loading branch information
3 people authored Apr 14, 2024
1 parent 3066059 commit c8a6ae9
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/replicator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Replicator

# Triggers the workflow manually
on:
workflow_dispatch:
inputs:
template:
description: 'Description of what should be replicated'
required: true
characteristics:
description: 'Characteristics of the result, described in natural language'
required: true

jobs:
replicate:
runs-on: ubuntu-latest
steps:
- name: Replicate Template
uses: PR-Pilot-AI/smart-actions/replicator@v1
with:
# API key for PR Pilot must be defined as a secret in the repository
api-key: ${{ secrets.PR_PILOT_API_KEY }}

# Inputs for the replicator action
template: ${{ github.event.inputs.template }}
characteristics: ${{ github.event.inputs.characteristics }}
51 changes: 51 additions & 0 deletions replicator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Replicator Action

The `replicator` action is designed to automate the process of creating new files or code snippets based on existing templates with specified characteristics. This action can significantly streamline your development process by allowing for the quick replication of code or file structures with minimal manual intervention.

## Workflow Ideas

- **Copy Writing Style** Apply the writing style of one document to another document
- **Component Copy Cat** Create a new component / module similar to an existing one
- **Idea Generator** Let AI look at existing codes and generate 1 new Github issue per idea

## Usage

To use the `replicator` action in your project, you'll need to include it in your GitHub workflow files. Specify the template, result path, and characteristics of the result to configure the action for your specific needs.

### Inputs

- `template`: (Required) A description of the code / text / files you want replicated
- `characteristics`: (Required) Characteristics of the result, described in natural language.
- `sdk-version`: (Optional) Specifies the PR Pilot SDK version to use. Default is `1.0.3`.
- `api-key`: (Required) Your API key for PR Pilot.

### Example Workflow

Here is an example that generates a new action based on the code of an existing action.

```yaml
name: Smart Action Copy Cat

on:
workflow_dispatch:
inputs:
template:
description: 'Path(s) to the action(s) to be replicated'
required: true
characteristics:
description: 'Characteristics of the new action, described in natural language'
required: true

jobs:
replicate:
runs-on: ubuntu-latest
steps:
- name: Replicate Smart Action
uses: PR-Pilot-AI/smart-actions/replicator@v1
with:
# API key for PR Pilot must be defined as a secret in the repository
api-key: ${{ secrets.PR_PILOT_API_KEY }}
# Inputs for the replicator action
template: ${{ github.event.inputs.template }}
characteristics: ${{ github.event.inputs.characteristics }}
```
33 changes: 33 additions & 0 deletions replicator/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Replicator'
description: 'Take something existing and replicate it with different characteristics'
inputs:
template:
description: 'Path to the template file or code snippet to replicate'
required: true
characteristics:
description: 'Characteristics of the result, described in natural language'
required: true
sdk-version:
description: 'PR Pilot SDK version to use'
required: false
default: '1.0.3'
api-key:
description: 'API key for PR Pilot'
required: true
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: python -m pip install --upgrade pip && pip install pr-pilot==${{ inputs.sdk-version }}
shell: bash
- name: Run script
run: python ${{ github.action_path }}/replicator.py
shell: bash
env:
TEMPLATE: ${{ inputs.template }}
CHARACTERISTICS: ${{ inputs.characteristics }}
PR_PILOT_API_KEY: ${{ inputs.api-key }}
28 changes: 28 additions & 0 deletions replicator/replicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os

from pr_pilot.util import create_task

template = os.getenv("TEMPLATE")
characteristics = os.getenv("CHARACTERISTICS")
repo = os.getenv("GITHUB_REPOSITORY")

prompt = f"""
The user wants you to take existing file/code/text and replicate it with different characteristics.
What to replicate:
```
{template}
```
Read and understand it, then replicate it with the following characteristics:
```
{characteristics}
```
"""
print(prompt)

task = create_task(repo, prompt)
dashboard_url = f"https://app.pr-pilot.ai/dashboard/tasks/{str(task.id)}/"
print(f"Replicator is running, monitor the task here: {dashboard_url}")
print(f"::set-output name=task-link::{dashboard_url}")

0 comments on commit c8a6ae9

Please sign in to comment.