Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add custom github auth using metadata #1109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions python/composio/tools/local/filetool/actions/git_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ def git_reset_cmd(commit_id: str) -> str:
return " && ".join(reset_commands)


def git_clone_cmd(repo: str, commit_id: str) -> str:
def git_clone_cmd(repo: str, commit_id: str, github_access_token: str) -> str:
"""Commands to clone github repository."""
# repo is in the format of "composiohq/composio" or "django/django"
repo_name = repo.split("/")[-1]
github_access_token = os.environ.get("GITHUB_ACCESS_TOKEN", "").strip()

if not github_access_token and os.environ.get("ALLOW_CLONE_WITHOUT_REPO") != "true":
raise RuntimeError("Cannot clone github repository without github access token")
Expand Down Expand Up @@ -108,10 +107,16 @@ def execute(self, request: GitCloneRequest, metadata: t.Dict) -> GitCloneRespons
if request.destination:
filemanager.chdir(request.destination)

github_access_token = os.environ.get(
"GITHUB_ACCESS_TOKEN", ""
).strip() or metadata.get("token", "")

command = (
git_reset_cmd(request.commit_id)
if request.just_reset
else git_clone_cmd(request.repo_name, request.commit_id)
else git_clone_cmd(
request.repo_name, request.commit_id, github_access_token
)
)
current_dir = filemanager.current_dir()
if pathlib.Path(current_dir, ".git").exists() and not request.just_reset:
Expand Down
Loading