From 933ba761e20ff436f271495acfee90e6b25b0ea5 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 11 Sep 2024 23:57:49 -0700 Subject: [PATCH] feat(integration): User GitHub Repositories Integration --- .../user-public-repositories/README.md | 34 +++++++++++++++ .../get_public_repositories.py | 43 +++++++++++++++++++ .../user-public-repositories/project.json | 6 +++ .../user-public-repositories/pyproject.toml | 17 ++++++++ 4 files changed, 100 insertions(+) create mode 100644 integrations/user-public-repositories/README.md create mode 100644 integrations/user-public-repositories/get_public_repositories.py create mode 100644 integrations/user-public-repositories/project.json create mode 100644 integrations/user-public-repositories/pyproject.toml diff --git a/integrations/user-public-repositories/README.md b/integrations/user-public-repositories/README.md new file mode 100644 index 00000000..e9f674c0 --- /dev/null +++ b/integrations/user-public-repositories/README.md @@ -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. diff --git a/integrations/user-public-repositories/get_public_repositories.py b/integrations/user-public-repositories/get_public_repositories.py new file mode 100644 index 00000000..0d8804c8 --- /dev/null +++ b/integrations/user-public-repositories/get_public_repositories.py @@ -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) diff --git a/integrations/user-public-repositories/project.json b/integrations/user-public-repositories/project.json new file mode 100644 index 00000000..1ce640c6 --- /dev/null +++ b/integrations/user-public-repositories/project.json @@ -0,0 +1,6 @@ +{ + "title": "GitHub User Public Repository Integration", + "description": "Query all public repositories from a user", + "categories": ["Repository", "GitHub"], + "deltav": true +} \ No newline at end of file diff --git a/integrations/user-public-repositories/pyproject.toml b/integrations/user-public-repositories/pyproject.toml new file mode 100644 index 00000000..b69b5881 --- /dev/null +++ b/integrations/user-public-repositories/pyproject.toml @@ -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"