feat: more helps

This commit is contained in:
张泊明518370910136 2021-09-14 18:15:15 +08:00
parent 3a6399ea1c
commit 48cbf4871d
No known key found for this signature in database
GPG Key ID: FBEF5DE8B9F4C629
4 changed files with 35 additions and 10 deletions

View File

@ -11,37 +11,49 @@ app = Typer(add_completion=False)
teapot = Teapot()
@app.command("create-personal")
@app.command(
"invite-to-teams", help="invite all canvas students to gitea teams by team name"
)
def add_all_canvas_students_to_teams(team_names: List[str]) -> None:
teapot.add_all_canvas_students_to_teams(team_names)
@app.command(
"create-personal", help="create personal repos on gitea for all canvas students"
)
def create_personal_repos_for_all_canvas_students() -> None:
teapot.create_personal_repos_for_all_canvas_students()
@app.command("create-teams")
@app.command("create-teams", help="create teams on gitea by canvas groups")
def create_teams_and_repos_by_canvas_groups() -> None:
teapot.create_teams_and_repos_by_canvas_groups()
@app.command("get-public-keys")
@app.command("get-public-keys", help="get all public keys on gitea")
def get_public_key_of_all_canvas_students() -> None:
echo(teapot.get_public_key_of_all_canvas_students())
@app.command("archieve")
@app.command("archieve", help="clone all gitea repos to local")
def archieve_all_repos() -> None:
teapot.archieve_all_repos()
@app.command("create-issues")
@app.command("create-issues", help="create issues on gitea")
def create_issue_for_repos(repo_names: List[str], title: str, body: str) -> None:
teapot.create_issue_for_repos(repo_names, title, body)
@app.command("check-issues")
@app.command("check-issues", help="check the existence of issue by title on gitea")
def check_exist_issue_by_title(repo_names: List[str], title: str) -> None:
echo(teapot.check_exist_issue_by_title(repo_names, title))
@app.command("get-release")
@app.command(
"get-release",
help="checkout git repo to git tag fetched from gitea by release name, with due date",
)
def checkout_to_repos_by_release_name(
repo_names: List[str], release_name: str, due: datetime = datetime(3000, 1, 1)
) -> None:

View File

@ -28,6 +28,9 @@ class Teapot:
self._git = Git()
return self._git
def add_all_canvas_students_to_teams(self, team_names: List[str]) -> None:
return self.gitea.add_canvas_students_to_teams(self.canvas.students, team_names)
def create_personal_repos_for_all_canvas_students(self) -> List[str]:
return self.gitea.create_personal_repos_for_canvas_students(
self.canvas.students

View File

@ -1,7 +1,12 @@
import os
import sys
current_path = sys.path[0]
sys.path.remove(current_path)
from git import Repo
sys.path.insert(0, current_path)
from joint_teapot.config import settings

View File

@ -47,12 +47,14 @@ class Gitea:
def _get_team_id_by_name(self, name: str) -> int:
res = self.organization_api.team_search(self.org_name, q=str(name), limit=1)
if len(res["data"]) == 0:
raise Exception("Team not found by name")
raise Exception(f"Team not found by name {name}")
return res["data"][0]["id"]
@lru_cache()
def _get_username_by_canvas_student(self, student: User) -> str:
res = self.user_api.user_search(q=student.sis_login_id, limit=1)
if len(res["data"]) == 0:
raise Exception(f"User not found by canvas student {student}")
return res["data"][0]["username"]
def add_canvas_students_to_teams(
@ -61,8 +63,11 @@ class Gitea:
for team_name in team_names:
team_id = self._get_team_id_by_name(team_name)
for student in students:
try:
username = self._get_username_by_canvas_student(student)
self.organization_api.org_add_team_member(team_id, username)
except Exception as e:
print(e)
def create_personal_repos_for_canvas_students(
self,