feat: extend create-issues with --regex and --file (#19)
* feat: create-issues allows reading from file * feat: create-issues allows regex for repo names * docs: extend create-issues
This commit is contained in:
		
							parent
							
								
									db402cbb1d
								
							
						
					
					
						commit
						58cd7ba4a1
					
				|  | @ -64,7 +64,12 @@ Example: `python3 -m joint_teapot create_channels_for_groups --prefix p1 -suffix | ||||||
| 
 | 
 | ||||||
| ### `create-issues` | ### `create-issues` | ||||||
| 
 | 
 | ||||||
| create issues on gitea | create issues on gitea. Specify a list of repos (use `--regex` to match against list of patterns), a title, and a body (use `--file` to read from file), in this order. | ||||||
|  | 
 | ||||||
|  | Examples (run both with `python3 -m joint_teapot create-issues`): | ||||||
|  | 
 | ||||||
|  | - `pgroup-08 pgroup-17 "Hurry up" "You are running out of time"` will create an issue in these two pgroups. | ||||||
|  | - `--regex "^pgroup" "Final submission" --file "./issues/final-submission.md"` will create an issue in all pgroups, with body content read from said file. | ||||||
| 
 | 
 | ||||||
| ### `create-personal-repos` | ### `create-personal-repos` | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -58,8 +58,14 @@ def clone_all_repos() -> None: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @app.command("create-issues", help="create issues on gitea") | @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( | ||||||
|     tea.pot.create_issue_for_repos(repo_names, title, body) |     repo_names: List[str], | ||||||
|  |     title: str, | ||||||
|  |     body: str = Argument(..., help="issue body, or, if --from-file is set, filepath to issue body"), | ||||||
|  |     from_file: bool = Option(False, "--file/--body"), | ||||||
|  |     use_regex: bool = Option(False, "--regex", help="repo_names takes list of regexes if set"), | ||||||
|  | ) -> None: | ||||||
|  |     tea.pot.create_issue_for_repos(repo_names, title, body, from_file, use_regex) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @app.command("create-milestones", help="create milestones on gitea") | @app.command("create-milestones", help="create milestones on gitea") | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| import functools | import functools | ||||||
|  | import re | ||||||
| from datetime import datetime | from datetime import datetime | ||||||
| from typing import Any, Callable, Dict, List, Optional, TypeVar | from typing import Any, Callable, Dict, List, Optional, TypeVar | ||||||
| 
 | 
 | ||||||
|  | @ -113,10 +114,43 @@ class Teapot: | ||||||
|             self.git.repo_clean_and_checkout(repo_name, "master") |             self.git.repo_clean_and_checkout(repo_name, "master") | ||||||
| 
 | 
 | ||||||
|     def create_issue_for_repos( |     def create_issue_for_repos( | ||||||
|         self, repo_names: List[str], title: str, body: str |         self, | ||||||
|  |         repo_names: List[str], | ||||||
|  |         title: str, | ||||||
|  |         body: str, | ||||||
|  |         from_file: bool = False, | ||||||
|  |         use_regex: bool = False, | ||||||
|     ) -> None: |     ) -> None: | ||||||
|         for repo_name in repo_names: |         if from_file: | ||||||
|             self.gitea.create_issue(repo_name, title, body) |             try: | ||||||
|  |                 f = open(body) | ||||||
|  |                 content = f.read() | ||||||
|  |                 f.close() | ||||||
|  |             except FileNotFoundError: | ||||||
|  |                 logger.error(f"file {body} not found") | ||||||
|  |                 return | ||||||
|  |             except Exception as e: | ||||||
|  |                 logger.exception("Error occurred when opening file {body}:") | ||||||
|  |                 logger.error(e) | ||||||
|  |                 return | ||||||
|  |         else: | ||||||
|  |             content = body | ||||||
|  | 
 | ||||||
|  |         affected_repos = [] | ||||||
|  |         if use_regex: | ||||||
|  |             all_repos = self.gitea.get_all_repo_names() | ||||||
|  |             for pattern in repo_names: | ||||||
|  |                 affected_repos.extend([ | ||||||
|  |                     repo | ||||||
|  |                     for repo in all_repos | ||||||
|  |                     if re.search(pattern, repo) is not None | ||||||
|  |                 ]) | ||||||
|  |         else: | ||||||
|  |             affected_repos = repo_names | ||||||
|  | 
 | ||||||
|  |         for repo_name in affected_repos: | ||||||
|  |             self.gitea.create_issue(repo_name, title, content) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|     def create_milestone_for_repos( |     def create_milestone_for_repos( | ||||||
|         self, repo_names: List[str], title: str, description: str, due_on: datetime |         self, repo_names: List[str], title: str, description: str, due_on: datetime | ||||||
|  |  | ||||||
|  | @ -328,7 +328,7 @@ class Gitea: | ||||||
|         assignees = [] |         assignees = [] | ||||||
|         if assign_every_collaborators: |         if assign_every_collaborators: | ||||||
|             assignees = [ |             assignees = [ | ||||||
|                 item.username |                 item.login | ||||||
|                 for item in list_all( |                 for item in list_all( | ||||||
|                     self.repository_api.repo_list_collaborators, |                     self.repository_api.repo_list_collaborators, | ||||||
|                     self.org_name, |                     self.org_name, | ||||||
|  | @ -340,6 +340,7 @@ class Gitea: | ||||||
|             repo_name, |             repo_name, | ||||||
|             body={"title": title, "body": body, "assignees": assignees}, |             body={"title": title, "body": body, "assignees": assignees}, | ||||||
|         ) |         ) | ||||||
|  |         logger.info(f"Created issue \"{title}\" in {repo_name}") | ||||||
| 
 | 
 | ||||||
|     def create_milestone( |     def create_milestone( | ||||||
|         self, |         self, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Frederick
						Frederick