|
| 1 | +# Client-GitHub for Eliza Framework |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `client-github` module is a component of the Eliza framework designed to interact with GitHub repositories. It provides functionalities to clone repositories, manage branches, create pull requests, and maintain file-based knowledge for Eliza agents. |
| 6 | + |
| 7 | +This client leverages GitHub's REST API via the `@octokit/rest` library and includes robust error handling and configuration validation. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Repository Management**: Clone, pull, and switch branches |
| 12 | +- **File Processing**: Generate agent memories from repository files |
| 13 | +- **Pull Request Management**: Create and manage pull requests programmatically |
| 14 | +- **Commit Operations**: Stage, commit, and push files with ease |
| 15 | +- **Knowledge Base Integration**: Convert repository content into agent memories |
| 16 | +- **Branch Management**: Flexible branch switching and creation |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +Install the package as part of the Eliza framework: |
| 21 | +bash |
| 22 | +pnpm add @elizaos/client-github |
| 23 | + |
| 24 | +## Configuration |
| 25 | + |
| 26 | +The GitHub client requires the following environment variables: |
| 27 | + |
| 28 | +| Variable | Description | Required | |
| 29 | +|-------------------|------------------------------------|----------| |
| 30 | +| `GITHUB_OWNER` | Owner of the GitHub repository | Yes | |
| 31 | +| `GITHUB_REPO` | Repository name | Yes | |
| 32 | +| `GITHUB_BRANCH` | Target branch (default: `main`) | Yes | |
| 33 | +| `GITHUB_PATH` | Path to focus on within the repo | Yes | |
| 34 | +| `GITHUB_API_TOKEN`| GitHub API token for authentication| Yes | |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +### Initialization |
| 39 | +typescript:packages/client-github/README.md |
| 40 | +import { GitHubClientInterface } from "@elizaos/client-github"; |
| 41 | +// Initialize the client |
| 42 | +const client = await GitHubClientInterface.start(runtime); |
| 43 | + |
| 44 | +### Creating Memories |
| 45 | + |
| 46 | +```typescript |
| 47 | +// Convert repository files to agent memories |
| 48 | +await client.createMemoriesFromFiles(); |
| 49 | + |
| 50 | +typescript |
| 51 | +// Convert repository files to agent memories |
| 52 | +await client.createMemoriesFromFiles(); |
| 53 | +``` |
| 54 | + |
| 55 | +### Creating Pull Requests |
| 56 | + |
| 57 | +```typescript |
| 58 | +await client.createPullRequest( |
| 59 | + "Feature: Add new functionality", |
| 60 | + "feature/new-feature", |
| 61 | + [ |
| 62 | + { |
| 63 | + path: "src/feature.ts", |
| 64 | + content: "// New feature implementation" |
| 65 | + } |
| 66 | + ], |
| 67 | + "Implements new functionality with tests" |
| 68 | +); |
| 69 | + |
| 70 | + |
| 71 | +typescript |
| 72 | +await client.createPullRequest( |
| 73 | +"Feature: Add new functionality", |
| 74 | +"feature/new-feature", |
| 75 | +[ |
| 76 | +{ |
| 77 | +path: "src/feature.ts", |
| 78 | +content: "// New feature implementation" |
| 79 | +} |
| 80 | +], |
| 81 | +"Implements new functionality with tests" |
| 82 | +); |
| 83 | +``` |
| 84 | + |
| 85 | +### Direct Commits |
| 86 | + |
| 87 | +```typescript |
| 88 | +await client.createCommit( |
| 89 | + "Update configuration", |
| 90 | + [ |
| 91 | + { |
| 92 | + path: "config.json", |
| 93 | + content: JSON.stringify(config, null, 2) |
| 94 | + } |
| 95 | + ] |
| 96 | +); |
| 97 | + |
| 98 | + |
| 99 | +``` |
| 100 | + |
| 101 | +## API Reference |
| 102 | + |
| 103 | +### GitHubClientInterface |
| 104 | + |
| 105 | +- `start(runtime: IAgentRuntime)`: Initialize the client |
| 106 | +- `stop(runtime: IAgentRuntime)`: Clean up resources |
| 107 | + |
| 108 | +### GitHubClient |
| 109 | + |
| 110 | +- `initialize()`: Set up repository and configuration |
| 111 | +- `createMemoriesFromFiles()`: Generate agent memories |
| 112 | +- `createPullRequest(title: string, branch: string, files: Array<{path: string, content: string}>, description?: string)`: Create PR |
| 113 | +- `createCommit(message: string, files: Array<{path: string, content: string}>)`: Direct commit |
| 114 | + |
| 115 | +## Scripts |
| 116 | + |
| 117 | +```bash |
| 118 | +# Build the project |
| 119 | +pnpm run build |
| 120 | + |
| 121 | +# Development with watch mode |
| 122 | +pnpm run dev |
| 123 | + |
| 124 | +# Lint the codebase |
| 125 | +pnpm run lint |
| 126 | +``` |
| 127 | + |
| 128 | +## Dependencies |
| 129 | + |
| 130 | +- `@elizaos/core`: ^0.1.7-alpha.2 |
| 131 | +- `@octokit/rest`: ^20.1.1 |
| 132 | +- `@octokit/types`: ^12.6.0 |
| 133 | +- `glob`: ^10.4.5 |
| 134 | +- `simple-git`: ^3.27.0 |
| 135 | + |
| 136 | +## Development Dependencies |
| 137 | + |
| 138 | +- `@types/glob`: ^8.1.0 |
| 139 | +- `tsup`: ^8.3.5 |
| 140 | + |
| 141 | +## Contribution |
| 142 | + |
| 143 | +Contributions are welcome! Please ensure all code adheres to the framework's standards and passes linting checks. |
| 144 | + |
| 145 | +## License |
| 146 | + |
| 147 | +This project is licensed under the MIT License. See the LICENSE file for details. |
0 commit comments