forked from clan/clan-core
matrix-bot: Fix incorrect caching of already pinged maintainers
This commit is contained in:
parent
044cf3923e
commit
c33b3b4807
|
@ -13,7 +13,7 @@ from matrix_bot.matrix import MatrixData
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
curr_dir = Path(__file__).parent
|
||||
data_dir = curr_dir / "data"
|
||||
data_dir = Path(os.getcwd()) / "data"
|
||||
|
||||
|
||||
def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
|
||||
|
|
|
@ -6,8 +6,6 @@ import aiohttp
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
curr_dir = Path(__file__).parent
|
||||
|
||||
from nio import AsyncClient, ClientConfig, ProfileGetAvatarResponse, RoomMessageText
|
||||
|
||||
from .changelog_bot import changelog_bot
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
import datetime
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -51,18 +52,20 @@ async def review_requested_bot(
|
|||
pulls = await fetch_pull_requests(gitea, http, limit=50, state=PullState.ALL)
|
||||
|
||||
# Read the last updated pull request
|
||||
last_updated_path = data_dir / "last_review_run.json"
|
||||
last_updated = read_locked_file(last_updated_path)
|
||||
ping_hist_path = data_dir / "last_review_run.json"
|
||||
ping_hist = read_locked_file(ping_hist_path)
|
||||
|
||||
# Check if the pull request is mergeable and needs review
|
||||
# and if the pull request is newer than the last updated pull request
|
||||
for pull in pulls:
|
||||
requested_reviewers = pull["requested_reviewers"]
|
||||
pid = str(pull["id"])
|
||||
if requested_reviewers and pull["mergeable"]:
|
||||
if last_updated == {}:
|
||||
last_updated = pull
|
||||
elif pull["updated_at"] < last_updated["updated_at"]:
|
||||
last_updated = pull
|
||||
last_time_updated = ping_hist.get(pid, {}).get(
|
||||
"updated_at", datetime.datetime.min.isoformat()
|
||||
)
|
||||
if ping_hist == {} or pull["updated_at"] > last_time_updated:
|
||||
ping_hist[pid] = pull
|
||||
else:
|
||||
continue
|
||||
|
||||
|
@ -79,7 +82,7 @@ async def review_requested_bot(
|
|||
await send_message(client, room, message, user_ids=ping_users)
|
||||
|
||||
# Write the new last updated pull request
|
||||
write_locked_file(last_updated_path, last_updated)
|
||||
write_locked_file(ping_hist_path, ping_hist)
|
||||
|
||||
# Time taken
|
||||
tend = time.time()
|
||||
|
|
Loading…
Reference in New Issue
Block a user