Add milestone and close message to bugs in close_bugs.py

Change-Id: If6ac7febb12136507ee43d39d261aa226a3d091a
This commit is contained in:
Marios Andreou 2021-02-17 19:28:17 +02:00
parent 7594837480
commit f25af27e8c

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# Originally from https://gitlab.cee.redhat.com/whayutin/launchpad_bugs/-/blob/master/launchpad_close_old_bugs.py
import argparse
import json
import os
@ -10,12 +9,27 @@ from launchpadlib.launchpad import Launchpad
cachedir = "{}/.launchpadlib/cache/".format(os.path.expanduser('~'))
LP_CACHE_DIR = os.path.expanduser('~/.launchpadlib/cache')
def get_bugs(status, tag=None, previous_days=None):
def no_creds():
print("No active credentials")
sys.exit(1)
def get_bugs(status, tag=None, previous_days=None, milestone=None):
# launchpad = Launchpad.login_anonymously(
# 'OOOQ Ruck Rover', 'production', cachedir, version='devel')
launchpad = Launchpad.login_with('lKfbPKz0qdwdjVLjtnTF', 'production')
project = launchpad.projects['tripleo']
# launchpad = Launchpad.login_with('lKfbPKz0qdwdjVLjtnTF', 'production')
lp = Launchpad.login_with(
application_name='tripleo-bugs',
service_root='production',
launchpadlib_dir=LP_CACHE_DIR,
credential_save_failed=no_creds,
version='devel',
)
project = lp.projects['tripleo']
target_milestone = project.getMilestone(name=milestone)
# Filter by Status and Tag
if tag is not None and previous_days is None:
@ -26,7 +40,9 @@ def get_bugs(status, tag=None, previous_days=None):
# Filter by Status and Number of Days
elif tag is None and previous_days is not None:
days_to_search = datetime.utcnow() - timedelta(days=int(previous_days))
bugs = project.searchTasks(status=status, created_before=days_to_search)
bugs = project.searchTasks(
status=status, created_before=days_to_search, milestone=target_milestone
)
# Filter by Tag, Status and Number of Days
elif tag is not None and previous_days is not None:
days_to_search = datetime.utcnow() - timedelta(days=int(previous_days))
@ -59,12 +75,23 @@ def print_as_csv(bug_tasks):
.replace("\\", ""),
)
)
print("Total: %s bugs" % (len(bug_tasks)))
CLOSE_MESSAGE = (
"This is an automated action. Bug status has been set to "
"'Incomplete' and target milestone has been removed "
"due to inactivity. If you disagree please "
"re-set these values and reach out to us on OFTC #tripleo"
)
def close_bug(bug_tasks):
if bug_tasks:
for bug_task in bug_tasks:
bug_task.status = "Incomplete"
bug_task.milestone = None
bug_task.bug.newMessage(content=CLOSE_MESSAGE)
bug_task.lp_save()
print(bug_task.bug.id)
@ -82,13 +109,12 @@ def main():
default=['New', 'Triaged', 'In Progress', 'Confirmed', 'Fix Committed'],
),
parser.add_argument('--previous_days', default=365)
parser.add_argument('--milestone')
args = parser.parse_args()
# print_as_csv(get_bugs(args.status,
# args.tag,
# args.previous_days))
print_as_csv(get_bugs(args.status, args.tag, args.previous_days, args.milestone))
close_bug(get_bugs(args.status, args.tag, args.previous_days))
close_bug(get_bugs(args.status, args.tag, args.previous_days, args.milestone))
if __name__ == '__main__':