Ajout des messages de commits pour le redminebot, corrige un crash (closes #6115)
This commit is contained in:
parent
1ad446df9f
commit
0b4241a883
@ -56,14 +56,14 @@ class Project:
|
|||||||
self.redmine_latest = datetime.now(tz=timezone.utc)
|
self.redmine_latest = datetime.now(tz=timezone.utc)
|
||||||
|
|
||||||
def generate_messages(self) -> Generator[str, None, None]:
|
def generate_messages(self) -> Generator[str, None, None]:
|
||||||
|
print("Generating messages for project", self.name)
|
||||||
now = datetime.now(tz=timezone.utc)
|
now = datetime.now(tz=timezone.utc)
|
||||||
if now < self.redmine_next:
|
if now < self.redmine_next:
|
||||||
return
|
return
|
||||||
|
|
||||||
latest_new = self.redmine_latest
|
latest_new = self.redmine_latest
|
||||||
self.redmine_next = self.redmine_next + timedelta(seconds=10)
|
self.redmine_next = self.redmine_next + timedelta(seconds=10)
|
||||||
redmine = feedparser.parse(f"http://agir.april.org/projects/{self.name}/activity.atom?show_issues=1")
|
redmine = feedparser.parse(f"https://agir.april.org/projects/{self.name}/activity.atom?show_issues=1&show_changesets=1")
|
||||||
|
|
||||||
for i in reversed(range(len(redmine.entries))):
|
for i in reversed(range(len(redmine.entries))):
|
||||||
redmine_entry = redmine.entries[i]
|
redmine_entry = redmine.entries[i]
|
||||||
entry_updated = parse_redmine_datetime(redmine_entry.updated)
|
entry_updated = parse_redmine_datetime(redmine_entry.updated)
|
||||||
@ -134,11 +134,11 @@ class Bot:
|
|||||||
if not PASSWORD.strip() and REGISTERED is True:
|
if not PASSWORD.strip() and REGISTERED is True:
|
||||||
self.send_privmsg("NickServ", f"IDENTIFY {self.bot_nick} {PASSWORD}")
|
self.send_privmsg("NickServ", f"IDENTIFY {self.bot_nick} {PASSWORD}")
|
||||||
|
|
||||||
def add_project(self, project: str) -> None:
|
def add_project(self, project: Project) -> None:
|
||||||
self.send_raw("JOIN {} \n".format(project.channel)) # Joins channel
|
self.send_raw("JOIN {} \n".format(project.channel)) # Joins channel
|
||||||
self.projects.append(project)
|
self.projects.append(project)
|
||||||
|
|
||||||
def get_project(self, name: str) -> str:
|
def get_project(self, name: str) -> Project | None:
|
||||||
for project in self.projects:
|
for project in self.projects:
|
||||||
if name[0] != '#' and project.name == name:
|
if name[0] != '#' and project.name == name:
|
||||||
return project
|
return project
|
||||||
@ -185,9 +185,13 @@ class Bot:
|
|||||||
if not project:
|
if not project:
|
||||||
LOGGER.error("Cannot find project for channel %s", channel_name)
|
LOGGER.error("Cannot find project for channel %s", channel_name)
|
||||||
return
|
return
|
||||||
|
print(project)
|
||||||
|
|
||||||
for message in project.redmine():
|
try:
|
||||||
self.send_privmsg(project.channel, message)
|
for message in project.generate_messages():
|
||||||
|
self.send_privmsg(project.channel, message)
|
||||||
|
except Exception as e:
|
||||||
|
LOGGER.error("Error while checking project %s updates: %s", project.name, e)
|
||||||
|
|
||||||
# Parses messages and responds to them appropriately.
|
# Parses messages and responds to them appropriately.
|
||||||
def message_response(self, irc_msg: str, actor: str, channel: str) -> None:
|
def message_response(self, irc_msg: str, actor: str, channel: str) -> None:
|
||||||
@ -242,6 +246,7 @@ def main() -> None:
|
|||||||
LOGGER.info("redmine bot starting…")
|
LOGGER.info("redmine bot starting…")
|
||||||
redmine_bot = Bot(DEFAULT_SERVER, DEFAULT_NICKNAME)
|
redmine_bot = Bot(DEFAULT_SERVER, DEFAULT_NICKNAME)
|
||||||
redmine_bot.connect()
|
redmine_bot.connect()
|
||||||
|
LOGGER.info("redmine bot connected")
|
||||||
if PROJECT_ID_1 and PROJECT_CHANNEL_1:
|
if PROJECT_ID_1 and PROJECT_CHANNEL_1:
|
||||||
redmine_bot.add_project(Project(PROJECT_ID_1, PROJECT_CHANNEL_1))
|
redmine_bot.add_project(Project(PROJECT_ID_1, PROJECT_CHANNEL_1))
|
||||||
if PROJECT_ID_2 and PROJECT_CHANNEL_2:
|
if PROJECT_ID_2 and PROJECT_CHANNEL_2:
|
||||||
|
Loading…
Reference in New Issue
Block a user