Skip to content

Commit

Permalink
feat(integration): User GitHub Repositories Integration (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanguven authored Oct 7, 2024
1 parent 45097c5 commit 6421252
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
34 changes: 34 additions & 0 deletions integrations/user-public-repositories/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Public Repository Fetching Agent

This uAgent queries all public repositories of a given GitHub username, ordered from most to least recently contributed to.

## Overview:

This is a DeltaV compatible agent connected to the agentverse. The agent has one field, `username`, which is the username of the GitHub account to query public repositories from.

## Prerequisites

- Python version > 3.10
- Agentverse account

## Steps to Use the Integration

### Set Up Agent on Agentverse

1. Create an account and login to [Agentverse](https://agentverse.ai).
2. Click the `New Agent` button, and select the `Blank Agent` template.
3. Copy the content from `get_public_repositories.py` into the `agent.py` file on the agentverse code editor.
4. Click `Start` to run the agent.

### Register the Agent as a Function

1. While the agent is running on the Agentverse, select on the `Deploy` tab and click the `New Function` button to create a new DeltaV function.
2. Enter a name and description for the function, as well as a description for the field(s) listed.
3. (Optional) Test the newly formed function on DeltaV by turning on advanced settings, and select `My Functions` from the function group dropdown.
4. Deploy the function to DeltaV by clicking `Publish`.

### Access the Agent on DeltaV

1. Login to [DeltaV](https://deltav.agentverse.ai/home) using your Google account or Fetch Wallet.
2. Enter a query related to fetching the repositories of a specific user.
3. Choose the function and provide the requested field.
43 changes: 43 additions & 0 deletions integrations/user-public-repositories/get_public_repositories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import requests

from uagents import Context, Protocol, Model
from ai_engine import UAgentResponse, UAgentResponseType

class Username(Model):
username: str

github_user_protocol = Protocol("GitHub User Protocol")

def fetch_user_repositories(username):
url = f"https://api.github.com/users/{username}/repos"

try:
response = requests.get(url)
response.raise_for_status()
repositories = response.json()

# sort repositories by 'most recently contributed to'
sorted_repositories = sorted(repositories, key=lambda repo: repo['pushed_at'], reverse=True)

repo_names = [(repo['name'], repo['description'] or "No description provided") for repo in sorted_repositories]

repository_names = []
for name, description in repo_names:
repository_names.append(f"{name}: {description}")
response = '\n'.join(repository_names)
return response

except requests.exceptions.HTTPError as err:
print(f"HTTP error occurred: {err}")
except Exception as err:
print(f"An error occurred: {err}")



@github_user_protocol.on_message(model=Username, replies={UAgentResponse})
async def get_repository_names(ctx: Context, sender: str, msg: Username):
ctx.logger.info("Querying all public repositories for " + msg.username)
repositories = fetch_user_repositories(msg.username)
await ctx.send(sender, UAgentResponse(message=repositories, type=UAgentResponseType.FINAL))

agent.include(github_user_protocol, publish_manifest=True)
6 changes: 6 additions & 0 deletions integrations/user-public-repositories/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "GitHub User Public Repository Integration",
"description": "Query all public repositories from a user",
"categories": ["Repository", "GitHub"],
"deltav": true
}
17 changes: 17 additions & 0 deletions integrations/user-public-repositories/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "github-user-repository-uagent-integration"
version = "0.1.0"
description = "Query all public repositories from a user"
authors = ["Jonathan"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.10,<3.13"
uagents-ai-engine = "^0.5.0"
requests = "^2.32.3"
uagents = "^0.15.2"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 6421252

Please sign in to comment.