feat: more helps
This commit is contained in:
		
							parent
							
								
									3a6399ea1c
								
							
						
					
					
						commit
						48cbf4871d
					
				|  | @ -11,37 +11,49 @@ app = Typer(add_completion=False) | ||||||
| teapot = Teapot() | 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: | def create_personal_repos_for_all_canvas_students() -> None: | ||||||
|     teapot.create_personal_repos_for_all_canvas_students() |     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: | def create_teams_and_repos_by_canvas_groups() -> None: | ||||||
|     teapot.create_teams_and_repos_by_canvas_groups() |     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: | def get_public_key_of_all_canvas_students() -> None: | ||||||
|     echo(teapot.get_public_key_of_all_canvas_students()) |     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: | def archieve_all_repos() -> None: | ||||||
|     teapot.archieve_all_repos() |     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: | def create_issue_for_repos(repo_names: List[str], title: str, body: str) -> None: | ||||||
|     teapot.create_issue_for_repos(repo_names, title, body) |     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: | def check_exist_issue_by_title(repo_names: List[str], title: str) -> None: | ||||||
|     echo(teapot.check_exist_issue_by_title(repo_names, title)) |     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( | def checkout_to_repos_by_release_name( | ||||||
|     repo_names: List[str], release_name: str, due: datetime = datetime(3000, 1, 1) |     repo_names: List[str], release_name: str, due: datetime = datetime(3000, 1, 1) | ||||||
| ) -> None: | ) -> None: | ||||||
|  |  | ||||||
|  | @ -28,6 +28,9 @@ class Teapot: | ||||||
|             self._git = Git() |             self._git = Git() | ||||||
|         return self._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]: |     def create_personal_repos_for_all_canvas_students(self) -> List[str]: | ||||||
|         return self.gitea.create_personal_repos_for_canvas_students( |         return self.gitea.create_personal_repos_for_canvas_students( | ||||||
|             self.canvas.students |             self.canvas.students | ||||||
|  |  | ||||||
|  | @ -1,7 +1,12 @@ | ||||||
| import os | import os | ||||||
|  | import sys | ||||||
| 
 | 
 | ||||||
|  | current_path = sys.path[0] | ||||||
|  | sys.path.remove(current_path) | ||||||
| from git import Repo | from git import Repo | ||||||
| 
 | 
 | ||||||
|  | sys.path.insert(0, current_path) | ||||||
|  | 
 | ||||||
| from joint_teapot.config import settings | from joint_teapot.config import settings | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -47,12 +47,14 @@ class Gitea: | ||||||
|     def _get_team_id_by_name(self, name: str) -> int: |     def _get_team_id_by_name(self, name: str) -> int: | ||||||
|         res = self.organization_api.team_search(self.org_name, q=str(name), limit=1) |         res = self.organization_api.team_search(self.org_name, q=str(name), limit=1) | ||||||
|         if len(res["data"]) == 0: |         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"] |         return res["data"][0]["id"] | ||||||
| 
 | 
 | ||||||
|     @lru_cache() |     @lru_cache() | ||||||
|     def _get_username_by_canvas_student(self, student: User) -> str: |     def _get_username_by_canvas_student(self, student: User) -> str: | ||||||
|         res = self.user_api.user_search(q=student.sis_login_id, limit=1) |         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"] |         return res["data"][0]["username"] | ||||||
| 
 | 
 | ||||||
|     def add_canvas_students_to_teams( |     def add_canvas_students_to_teams( | ||||||
|  | @ -61,8 +63,11 @@ class Gitea: | ||||||
|         for team_name in team_names: |         for team_name in team_names: | ||||||
|             team_id = self._get_team_id_by_name(team_name) |             team_id = self._get_team_id_by_name(team_name) | ||||||
|             for student in students: |             for student in students: | ||||||
|  |                 try: | ||||||
|                     username = self._get_username_by_canvas_student(student) |                     username = self._get_username_by_canvas_student(student) | ||||||
|                     self.organization_api.org_add_team_member(team_id, username) |                     self.organization_api.org_add_team_member(team_id, username) | ||||||
|  |                 except Exception as e: | ||||||
|  |                     print(e) | ||||||
| 
 | 
 | ||||||
|     def create_personal_repos_for_canvas_students( |     def create_personal_repos_for_canvas_students( | ||||||
|         self, |         self, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user