|
10 | 10 | from dotenv import load_dotenv |
11 | 11 | from discord.ext import commands, tasks |
12 | 12 |
|
13 | | -from redmine.model import TicketNote, Ticket, NamedId |
| 13 | +from redmine.model import TicketNote, Ticket, NamedId, Team |
14 | 14 | from redmine import synctime |
15 | 15 | from redmine.redmine import Client |
16 | 16 |
|
|
20 | 20 | log = logging.getLogger(__name__) |
21 | 21 |
|
22 | 22 |
|
23 | | -# _TRACKER_MAPPING = { |
24 | | -# "External-Comms-Intake": "admin-team", |
25 | | -# "Admin": "admin-team", |
26 | | -# "Comms": "outreach", |
27 | | -# "Infra-Config": "routing-and-infrastructure", |
28 | | -# "Infra-Field": "installs", |
29 | | -# "Software-Dev": "network-software", |
30 | | -# "Research": "uw-research-nsf", |
31 | | -# } |
32 | 23 | CHANNEL_MAPPING = { |
33 | | - "support": "External-Comms-Intake", |
| 24 | + "intake": "External-Comms-Intake", |
34 | 25 | "admin-team": "Admin", |
35 | 26 | "outreach": "Comms", |
36 | 27 | "routing-and-infrastructure": "Infra-Config", |
|
40 | 31 | } |
41 | 32 |
|
42 | 33 | TEAM_MAPPING = { |
43 | | - #"support": "External-Comms-Intake", ## FIXME - intake is a tracker, not a team? worry later |
| 34 | + "intake": "intake-team", |
44 | 35 | "admin-team": "admin-team", |
45 | 36 | "outreach": "comms-team", |
46 | 37 | "routing-and-infrastructure": "infra-config-team", |
47 | 38 | "installs": "infra-field-team", |
48 | 39 | "network-software": "software-dev-team", |
49 | | - "uw-research-nsf": "research-team", |
| 40 | + "uw-research-nsf": "uw-research-nsf-team", |
50 | 41 | } |
51 | 42 |
|
52 | 43 | # utility method to get a list of (one) ticket from the title of the channel, or empty list |
@@ -375,12 +366,35 @@ async def notify_expiring_tickets(self): |
375 | 366 | await self.expiration_notification(ticket) |
376 | 367 |
|
377 | 368 |
|
378 | | - def expire_expired_tickets(self): |
379 | | - expired = self.redmine.ticket_mgr.expired_tickets() |
380 | | - for ticket in expired: |
| 369 | + def group_for_tracker(self, tracker: NamedId) -> Team: |
| 370 | + """For a tracker, look up a team""" |
| 371 | + for channel_name, tracker_name in CHANNEL_MAPPING.items(): |
| 372 | + if tracker.name == tracker_name: |
| 373 | + # lookup team from channel |
| 374 | + team_name = TEAM_MAPPING.get(channel_name, None) |
| 375 | + if team_name: |
| 376 | + team = self.redmine.user_mgr.get_team_by_name(team_name) |
| 377 | + if team: |
| 378 | + return team |
| 379 | + else: |
| 380 | + log.error(f"Unable to find team for {tracker} and {team_name}") |
| 381 | + return None |
| 382 | + else: |
| 383 | + log.error(f"Unable to find channel mapping for {tracker} and {channel_name}") |
| 384 | + return None |
| 385 | + |
| 386 | + # fallthru: not found |
| 387 | + log.error(f"Unable to find channel for {tracker}") |
| 388 | + return None |
| 389 | + |
| 390 | + |
| 391 | + def recycle_tickets(self): |
| 392 | + recycle_list = self.redmine.ticket_mgr.tickets_to_recycle() # older than max age |
| 393 | + for ticket in recycle_list: |
381 | 394 | # notification to discord, or just note provided by expire? |
382 | 395 | # - for now, add note to ticket with expire info, and allow sync. |
383 | | - self.redmine.ticket_mgr.expire(ticket) |
| 396 | + new_owner = self.group_for_tracker(ticket.tracker) |
| 397 | + self.redmine.ticket_mgr.recycle(ticket, new_owner) |
384 | 398 |
|
385 | 399 |
|
386 | 400 | @commands.slash_command(name="notify", description="Force ticket notifications") |
|
0 commit comments