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

[MRG] refactor the github login #216

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions mle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,13 @@ def new(name):
if not api_key:
console.log("API key is required. Aborted.")
return

elif platform == 'MistralAI':
api_key = questionary.password("What is your MistralAI API key?").ask()
if not api_key:
console.log("API key is required. Aborted.")
return

elif platform == 'DeepSeek':
api_key = questionary.password("What is your DeepSeek API key?").ask()
if not api_key:
Expand All @@ -232,8 +233,10 @@ def new(name):
yaml.dump({
'platform': platform,
'api_key': api_key,
'search_key': search_api_key
'search_key': search_api_key,
'integration': {},
}, outfile, default_flow_style=False)

# init the memory
Memory(project_dir)

Expand All @@ -257,13 +260,11 @@ def integrate(reset):
).ask()

if platform == "GitHub":
from mle.integration.github import github_login
if not reset and config.get("integration").get("github"):
print("GitHub is already integrated.")
else:
token = questionary.password(
"What is your GitHub token? (https://github.com/settings/tokens)"
).ask()

token = github_login()
config["integration"]["github"] = {
"token": token
}
Expand Down
2 changes: 1 addition & 1 deletion mle/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .github import GitHubIntegration
from .github import GitHubIntegration, github_login
from .google_calendar import GoogleCalendarIntegration, google_calendar_login
from .kaggle import KaggleIntegration, kaggle_login
11 changes: 11 additions & 0 deletions mle/integration/github.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import os
import base64
import requests
import questionary
from fnmatch import fnmatch
from datetime import datetime, timezone, timedelta


def github_login():
"""
GitHub login by API token.
:returns: API key.
"""
token = questionary.password(
"What is your GitHub token? (https://github.com/settings/tokens)").ask()
return token


class GitHubIntegration:
BASE_URL = "https://api.github.com"

Expand Down
32 changes: 10 additions & 22 deletions mle/workflow/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mle.model import load_model
from mle.agents import SummaryAgent, ReportAgent
from mle.utils.system import get_config, write_config, check_config
from mle.integration import GoogleCalendarIntegration
from mle.integration import GoogleCalendarIntegration, github_login


def ask_data(data_str: str):
Expand All @@ -24,26 +24,6 @@ def ask_data(data_str: str):
return f"[green]Dataset:[/green] {data_str}"


def ask_github_token():
"""
Ask the user to integrate GitHub.
:return: the GitHub token.
"""
config = get_config() or {}
if "integration" not in config.keys():
config["integration"] = {}

if "github" not in config["integration"].keys():
token = questionary.password(
"What is your GitHub token? (https://github.com/settings/tokens)"
).ask()

config["integration"]["github"] = {"token": token}
write_config(config)

return config["integration"]["github"]["token"]


def report(
work_dir: str,
github_repo: str,
Expand All @@ -68,6 +48,14 @@ def report(
events = None
if check_config(console):
config = get_config()
if github_token is None:
if "github" in config.get("integration", {}).keys():
github_token = config["integration"]["github"].get("token")
else:
github_token = github_login()
config["integration"]["github"] = {"token": github_token}
write_config(config)

if "google_calendar" in config.get("integration", {}).keys():
google_token = pickle.loads(config["integration"]["google_calendar"].get("token"))
google_calendar = GoogleCalendarIntegration(google_token)
Expand All @@ -77,7 +65,7 @@ def report(
model,
github_repo=github_repo,
username=github_username,
github_token=github_token or ask_github_token(),
github_token=github_token,
)
reporter = ReportAgent(model, console)

Expand Down
Loading