forked from JOJ/Joint-Teapot
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69e097e04b | |||
| f4fb5eae05 | |||
| 3a511660bb | |||
| 9fc7649696 | |||
| e160023cbf | |||
| 99d889ee12 | |||
| f755fb44f6 | |||
| 94d3f993b2 | |||
| aa33dcc2f1 | |||
| e24545324d | |||
| 3dc6667716 | |||
| 5b6c61af6d | |||
| 8264152022 | |||
| 992f450004 | |||
| 5478052c23 |
|
|
@ -1,41 +1,41 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- id: requirements-txt-fixer
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: "v1.4.1"
|
||||
rev: "v1.18.2"
|
||||
hooks:
|
||||
- id: mypy
|
||||
additional_dependencies:
|
||||
- pydantic
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.9.0
|
||||
rev: v3.20.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
- repo: https://github.com/hadialqattan/pycln
|
||||
rev: v2.4.0
|
||||
rev: v2.5.0
|
||||
hooks:
|
||||
- id: pycln
|
||||
args: [-a]
|
||||
- repo: https://github.com/PyCQA/bandit
|
||||
rev: '1.7.5'
|
||||
rev: '1.8.6'
|
||||
hooks:
|
||||
- id: bandit
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.12.0
|
||||
rev: 6.0.1
|
||||
hooks:
|
||||
- id: isort
|
||||
args: ["--profile", "black", "--filter-files"]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.7.0
|
||||
rev: 25.9.0
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||
rev: v1.5.1
|
||||
rev: v1.5.5
|
||||
hooks:
|
||||
- id: remove-crlf
|
||||
- id: remove-tabs
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
|||
from time import sleep
|
||||
from typing import TYPE_CHECKING, List, Optional
|
||||
|
||||
# from filelock import FileLock
|
||||
from filelock import FileLock
|
||||
from git import Repo
|
||||
from typer import Argument, Exit, Option, Typer, echo
|
||||
|
||||
|
|
@ -392,8 +392,7 @@ def joj3_all_env(
|
|||
f"try to acquire lock, file path: {lock_file_path}, "
|
||||
+ f"timeout: {settings.joj3_lock_file_timeout}"
|
||||
)
|
||||
if True: # disable the file lock temporarily
|
||||
# with FileLock(lock_file_path, timeout=settings.joj3_lock_file_timeout).acquire():
|
||||
with FileLock(lock_file_path, timeout=settings.joj3_lock_file_timeout).acquire():
|
||||
logger.info("file lock acquired")
|
||||
retry_interval = 1
|
||||
git_push_ok = False
|
||||
|
|
@ -533,6 +532,16 @@ def joj3_check_env(
|
|||
logger.info("joj3-check-env done")
|
||||
|
||||
|
||||
@app.command("joj3-check-gitea-token")
|
||||
def joj3_check_gitea_token(
|
||||
env_path: str = Argument("", help="path to .env file")
|
||||
) -> None:
|
||||
app.pretty_exceptions_enable = False
|
||||
set_settings(Settings(_env_file=env_path))
|
||||
set_logger(settings.stderr_log_level)
|
||||
tea.pot.gitea.organization_api.org_list_repos(settings.gitea_org_name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
app()
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Settings(BaseSettings):
|
|||
joj_sid: str = ""
|
||||
|
||||
# joj3
|
||||
joj3_lock_file_path: str = ".git/teapot.lock"
|
||||
joj3_lock_file_path: str = ".git/teapot-joj3-all-env.lock"
|
||||
joj3_lock_file_timeout: int = 30
|
||||
|
||||
# moss
|
||||
|
|
|
|||
|
|
@ -386,11 +386,13 @@ class Teapot:
|
|||
time_windows.append(since)
|
||||
valid_items.append((name, max_count, time_period, since))
|
||||
logger.info(f"valid items: {valid_items}, time windows: {time_windows}")
|
||||
all_commits = []
|
||||
matched_commits = []
|
||||
all_commits_length = 0
|
||||
if time_windows:
|
||||
earliest_since = min(time_windows).strftime("%Y-%m-%dT%H:%M:%S")
|
||||
commits = repo.iter_commits(paths=scoreboard_filename, since=earliest_since)
|
||||
for commit in commits:
|
||||
all_commits_length += 1
|
||||
lines = commit.message.strip().splitlines()
|
||||
if not lines:
|
||||
continue
|
||||
|
|
@ -408,17 +410,19 @@ class Teapot:
|
|||
commit_groups = (
|
||||
groups_line[len("groups: ") :].split(",") if groups_line else []
|
||||
)
|
||||
all_commits.append(
|
||||
matched_commits.append(
|
||||
{
|
||||
"time": commit.committed_datetime,
|
||||
"groups": [g.strip() for g in commit_groups],
|
||||
}
|
||||
)
|
||||
logger.info(f"all commits length: {len(all_commits)}")
|
||||
logger.info(
|
||||
f"matched commits length: {len(matched_commits)}, all commits length: {all_commits_length}"
|
||||
)
|
||||
for name, max_count, time_period, since in valid_items:
|
||||
submit_count = 0
|
||||
time_limit = now - timedelta(hours=time_period)
|
||||
for commit in all_commits:
|
||||
for commit in matched_commits:
|
||||
if commit["time"] < time_limit:
|
||||
continue
|
||||
if name:
|
||||
|
|
|
|||
|
|
@ -38,10 +38,7 @@ def set_logger(
|
|||
) -> None:
|
||||
logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True)
|
||||
logger.remove()
|
||||
logger.add(
|
||||
stderr,
|
||||
level=stderr_log_level,
|
||||
)
|
||||
logger.add(stderr, level=stderr_log_level, colorize=stderr.isatty())
|
||||
logger.add(settings.log_file_path, level="DEBUG")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -90,28 +90,23 @@ class Git:
|
|||
retry_interval = 2
|
||||
while retry_interval and auto_retry:
|
||||
try:
|
||||
current_branch = ""
|
||||
if repo.head.is_detached:
|
||||
current_branch = repo.head.commit.hexsha
|
||||
else:
|
||||
current_branch = repo.active_branch.name
|
||||
if clean_git_lock:
|
||||
lock_files = [
|
||||
"index.lock",
|
||||
"HEAD.lock",
|
||||
"fetch-pack.lock",
|
||||
"logs/HEAD.lock",
|
||||
"packed-refs.lock",
|
||||
"config.lock",
|
||||
f"refs/heads/{current_branch}.lock",
|
||||
f"refs/remotes/origin/{current_branch}.lock",
|
||||
f"refs/heads/{checkout_dest}.lock",
|
||||
f"refs/remotes/origin/{checkout_dest}.lock",
|
||||
]
|
||||
for lock_file in lock_files:
|
||||
lock_path = os.path.join(repo_dir, ".git", lock_file)
|
||||
if os.path.exists(lock_path):
|
||||
os.remove(lock_path)
|
||||
locks_removed_count = 0
|
||||
for root, _, files in os.walk(os.path.join(repo_dir, ".git")):
|
||||
for filename in files:
|
||||
if filename.endswith(".lock"):
|
||||
lock_file_path = os.path.join(root, filename)
|
||||
if (
|
||||
os.path.relpath(lock_file_path, repo_dir)
|
||||
== settings.joj3_lock_file_path
|
||||
):
|
||||
continue
|
||||
try:
|
||||
os.remove(lock_file_path)
|
||||
locks_removed_count += 1
|
||||
except OSError as e:
|
||||
logger.warning(f"Error removing lock file: {e}")
|
||||
logger.info(f"Removed {locks_removed_count} lock files")
|
||||
repo.git.fetch("--tags", "--all", "-f")
|
||||
repo.git.reset("--hard", reset_target)
|
||||
repo.git.clean("-d", "-f", "-x")
|
||||
|
|
|
|||
|
|
@ -494,6 +494,7 @@ class Gitea:
|
|||
self.repository_api.user_current_delete_subscription(
|
||||
self.org_name, repo.name
|
||||
)
|
||||
logger.info(f"Unwatched {repo.name}")
|
||||
|
||||
def get_all_teams(self) -> Dict[str, List[str]]:
|
||||
res: Dict[str, List[str]] = {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user