mirror of
https://github.com/coleam00/Archon.git
synced 2026-01-01 20:28:43 -05:00
The New Archon (Beta) - The Operating System for AI Coding Assistants!
This commit is contained in:
34
original_archon/agent-resources/tools/get_github_file.py
Normal file
34
original_archon/agent-resources/tools/get_github_file.py
Normal file
@@ -0,0 +1,34 @@
|
||||
@github_agent.tool
|
||||
async def get_file_content(ctx: RunContext[GitHubDeps], github_url: str, file_path: str) -> str:
|
||||
"""Get the content of a specific file from the GitHub repository.
|
||||
|
||||
Args:
|
||||
ctx: The context.
|
||||
github_url: The GitHub repository URL.
|
||||
file_path: Path to the file within the repository.
|
||||
|
||||
Returns:
|
||||
str: File content as a string.
|
||||
"""
|
||||
match = re.search(r'github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$', github_url)
|
||||
if not match:
|
||||
return "Invalid GitHub URL format"
|
||||
|
||||
owner, repo = match.groups()
|
||||
headers = {'Authorization': f'token {ctx.deps.github_token}'} if ctx.deps.github_token else {}
|
||||
|
||||
response = await ctx.deps.client.get(
|
||||
f'https://raw.githubusercontent.com/{owner}/{repo}/main/{file_path}',
|
||||
headers=headers
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
# Try with master branch if main fails
|
||||
response = await ctx.deps.client.get(
|
||||
f'https://raw.githubusercontent.com/{owner}/{repo}/master/{file_path}',
|
||||
headers=headers
|
||||
)
|
||||
if response.status_code != 200:
|
||||
return f"Failed to get file content: {response.text}"
|
||||
|
||||
return response.text
|
||||
Reference in New Issue
Block a user