2019-09-19 18:01:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2019-09-19 18:01:47 +00:00
|
|
|
class Description:
|
2022-03-22 16:39:58 +00:00
|
|
|
"""Parsed description representation"""
|
|
|
|
|
2019-09-19 18:01:47 +00:00
|
|
|
MAP_CATEGORY_TO_LABEL = {
|
2022-03-22 16:39:58 +00:00
|
|
|
"New Feature": "pr-feature",
|
|
|
|
"Bug Fix": "pr-bugfix",
|
|
|
|
"Improvement": "pr-improvement",
|
|
|
|
"Performance Improvement": "pr-performance",
|
2019-09-19 18:01:47 +00:00
|
|
|
# 'Backward Incompatible Change': doesn't match anything
|
2022-03-22 16:39:58 +00:00
|
|
|
"Build/Testing/Packaging Improvement": "pr-build",
|
|
|
|
"Non-significant (changelog entry is not needed)": "pr-non-significant",
|
|
|
|
"Non-significant (changelog entry is not required)": "pr-non-significant",
|
|
|
|
"Non-significant": "pr-non-significant",
|
|
|
|
"Documentation (changelog entry is not required)": "pr-documentation",
|
2019-09-19 18:01:47 +00:00
|
|
|
# 'Other': doesn't match anything
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, pull_request):
|
|
|
|
self.label_name = str()
|
|
|
|
self.legal = False
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
self._parse(pull_request["bodyText"])
|
2019-09-19 18:01:47 +00:00
|
|
|
|
|
|
|
def _parse(self, text):
|
|
|
|
lines = text.splitlines()
|
|
|
|
next_category = False
|
|
|
|
category = str()
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
stripped = line.strip()
|
|
|
|
|
|
|
|
if not stripped:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if next_category:
|
|
|
|
category = stripped
|
|
|
|
next_category = False
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
if (
|
|
|
|
stripped
|
|
|
|
== "I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en"
|
|
|
|
):
|
2019-09-19 18:01:47 +00:00
|
|
|
self.legal = True
|
|
|
|
|
2020-03-16 15:27:07 +00:00
|
|
|
category_headers = (
|
2022-03-22 16:39:58 +00:00
|
|
|
"Category (leave one):",
|
|
|
|
"Changelog category (leave one):",
|
|
|
|
"Changelog category:",
|
|
|
|
"Category:",
|
2020-03-16 15:27:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if stripped in category_headers:
|
2019-09-19 18:01:47 +00:00
|
|
|
next_category = True
|
|
|
|
|
|
|
|
if category in Description.MAP_CATEGORY_TO_LABEL:
|
|
|
|
self.label_name = Description.MAP_CATEGORY_TO_LABEL[category]
|
2020-03-16 15:27:07 +00:00
|
|
|
else:
|
|
|
|
if not category:
|
2022-03-22 16:39:58 +00:00
|
|
|
print("Cannot find category in pr description")
|
2020-03-16 15:27:07 +00:00
|
|
|
else:
|
2022-03-22 16:39:58 +00:00
|
|
|
print(("Unknown category: " + category))
|