-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(integration): GitHub GraphQL lookup of user contributions to non…
…-user owned repositories (#532)
- Loading branch information
Showing
5 changed files
with
1,445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 `username` and `token` fields. `username` refers to the case sensative GitHub account username. `token` can be obtained by following [github's guide](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens). | ||
|
||
## 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 `git_fetch_user_contributed_repos.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 contributions made by a github user. | ||
3. Choose the function and provide the requested field. |
46 changes: 46 additions & 0 deletions
46
integrations/community/github_contributions/git_fetch_user_contributated_repos.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import requests | ||
from ai_engine import UAgentResponse, UAgentResponseType | ||
from uagents import Context, Protocol, Model | ||
|
||
class Github_User_Query(Model): | ||
username: str | ||
token: str | ||
|
||
github_contribution_protocol = Protocol("Github User Contribution Protocol") | ||
|
||
async def fetch_github_user_contributions(username, token): | ||
url = "https://api.github.com/graphql" | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
} | ||
query = f"""{{ | ||
user(login:"{username}") {{ | ||
repositoriesContributedTo(contributionTypes:COMMIT, first:100) {{ | ||
nodes {{ | ||
name | ||
}} | ||
}} | ||
}} | ||
}}""" | ||
|
||
response = requests.post(url, headers=headers, json={"query": query}) | ||
|
||
try: | ||
return list(map(lambda x: x["name"], response.json()["data"]["user"]["repositoriesContributedTo"]["nodes"])) | ||
except: | ||
return [] | ||
|
||
@github_contribution_protocol.on_message(model=Github_User_Query, replies={UAgentResponse}) | ||
async def get_repo_names(ctx: Context, sender: str, msg: Github_User_Query): | ||
ctx.logger.info(f"Fetching user contributions for {msg.username}") | ||
|
||
repos = await fetch_github_user_contributions(msg.username, msg.token) | ||
|
||
if len(repos) == 0: | ||
rsp = f"{msg.username} has not contributed to any external repositories or we encountered an issue." | ||
else: | ||
repoStr = "\n".join(repos) | ||
rsp = f"{msg.username} has contributed {len(repos)} external repositories:\n{repoStr}" | ||
await ctx.send(sender, UAgentResponse(message=rsp, type=UAgentResponseType.FINAL)) | ||
|
||
agent.include(github_contribution_protocol, publish_manifest=True) |
Oops, something went wrong.