in libmozdata/patchanalysis.py [0:0]
def uplift_info(bug, channel):
if isinstance(bug, numbers.Number):
bug_id = bug
bug = {}
def bughandler(found_bug):
bug.update(found_bug)
def commenthandler(found_bug, bugid):
bug["comments"] = found_bug["comments"]
def historyhandler(found_bug):
bug["history"] = found_bug["history"]
def attachmenthandler(attachments, bugid):
bug["attachments"] = attachments
INCLUDE_FIELDS = ["id"]
ATTACHMENT_INCLUDE_FIELDS = ["flags"]
COMMENT_INCLUDE_FIELDS = ["id", "text", "author", "time"]
Bugzilla(
bug_id,
INCLUDE_FIELDS,
bughandler=bughandler,
commenthandler=commenthandler,
comment_include_fields=COMMENT_INCLUDE_FIELDS,
historyhandler=historyhandler,
attachmenthandler=attachmenthandler,
attachment_include_fields=ATTACHMENT_INCLUDE_FIELDS,
).get_data().wait()
# Default structure
info = {
"uplift_accepted": False,
"uplift_comment": None,
"uplift_author": None,
"uplift_reviewer": None,
"landing_delta": timedelta(),
"response_delta": timedelta(),
"release_delta": timedelta(),
}
approval_flag = "approval-mozilla-" + channel
app_flags = [
flag
for a in bug["attachments"]
for flag in a["flags"]
if flag["name"] == approval_flag
]
status = [flag["status"] for flag in app_flags]
uplift_reviewers = [flag["setter"] for flag in app_flags]
uplift_accepted = any(filter(lambda s: s == "+", status))
uplift_rejected = any(filter(lambda s: s == "-", status))
assert not (
uplift_accepted and uplift_rejected
), "Uplift either accepted or rejected."
info["uplift_accepted"] = uplift_accepted
# Add reviewer from last flag set
if len(uplift_reviewers):
info["uplift_reviewer"] = get_user_details(uplift_reviewers[-1])
# Delta between uplift request and uplift acceptation/rejection.
uplift_request = Bugzilla.get_history_matches(
bug["history"], {"added": approval_flag + "?", "field_name": "flagtypes.name"}
)
uplift_pattern = re.compile(r"Approval Request")
if len(uplift_request):
uplift_request_date = utils.get_date_ymd(uplift_request[-1]["when"])
else:
uplift_request_date = 0
warnings.warn(
"Bug " + str(bug["id"]) + " doesn't have a uplift request date.",
stacklevel=2,
)
sign = "+" if uplift_accepted else "-"
uplift_response = Bugzilla.get_history_matches(
bug["history"], {"added": approval_flag + sign, "field_name": "flagtypes.name"}
)
if uplift_response:
uplift_response_date = utils.get_date_ymd(uplift_response[-1]["when"])
if uplift_request_date == 0:
uplift_request_date = uplift_response_date
info["response_delta"] = uplift_response_date - uplift_request_date
# Sometimes a patch is approved for uplift without a request.
# assert info['response_delta'] >= timedelta(), "Delta between uplift request date and response should be at least 0"
# Search the uplift request comment
for comment in bug["comments"]:
for match in uplift_pattern.finditer(comment["text"]):
# Use first one only
info["uplift_author"] = get_user_details(comment["author"])
info["uplift_comment"] = comment
break
if info["uplift_comment"] and info["uplift_author"]:
break
# Landing dates per useful channels
channels = ["nightly", "aurora", "beta", "release", "esr"]
landing_comments = Bugzilla.get_landing_comments(bug["comments"], channels)
landings = dict(zip(channels, [None] * len(channels)))
for c in landing_comments:
channel = c["channel"]
dt = utils.get_date_ymd(c["comment"]["time"])
if landings[channel] is None or landings[channel] < dt:
landings[channel] = dt
info["landings"] = landings
# Delta between patch landing on central and uplift request
landing_nightly = landings.get("nightly")
if landing_nightly and uplift_request_date != 0:
info["landing_delta"] = uplift_request_date - landing_nightly
# Sometimes the request is done earlier than landing on nightly.
# assert bug_data['landing_delta'] > timedelta()
# Delta between uplift request and next merge date.
if uplift_request_date != 0:
release_date = versions.getCloserRelease(uplift_request_date)[1]
info["release_delta"] = release_date - uplift_request_date
assert (
info["release_delta"] > timedelta()
), "Delta between uplift request date and next release should be at least 0"
return info