improved package name regnition for pdc_unretire_package and added condition when it should check bugzilla ticket
This commit is contained in:
parent
7b759ec031
commit
d789a51852
2 changed files with 255 additions and 299 deletions
|
@ -209,9 +209,9 @@ class TestProcessTicket:
|
|||
self.toddler.pagure_io = Mock()
|
||||
self.toddler.koji_session = MagicMock()
|
||||
|
||||
def test_process_ticket_invalid_two_words_package_name(self, caplog):
|
||||
def test_process_ticket_package_name_doesnt_have_required_prefix(self, caplog):
|
||||
"""
|
||||
Assert that package name has two or more words.
|
||||
Assert that ticket will be closed if title doesn't contain required prefix.
|
||||
"""
|
||||
caplog.set_level(logging.INFO)
|
||||
issue = {
|
||||
|
@ -223,38 +223,27 @@ class TestProcessTicket:
|
|||
},
|
||||
"id": 55,
|
||||
}
|
||||
close_msg = (
|
||||
"Unretire can only apply to rpm packages, please add `{0}`"
|
||||
" prefix before the package name"
|
||||
).format(pdc_unretire_packages.RPM_PREFIX)
|
||||
|
||||
with patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_package_url"
|
||||
) as mock_get_package_url:
|
||||
self.toddler.process_ticket(issue)
|
||||
|
||||
mock_get_package_url.assert_not_called()
|
||||
|
||||
assert (
|
||||
caplog.records[-1].message
|
||||
== "Package name 'rubygem-logging lala' has two or more words"
|
||||
)
|
||||
self.toddler.process_ticket(issue)
|
||||
assert caplog.records[-1].message == close_msg
|
||||
self.toddler.pagure_io.close_issue.assert_called_with(
|
||||
issue["id"],
|
||||
namespace=pdc_unretire_packages.PROJECT_NAMESPACE,
|
||||
message="Invalid package name.",
|
||||
message=close_msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_package_url",
|
||||
return_value=None,
|
||||
)
|
||||
def test_process_ticket_package_wasnt_found_on_dist_git(
|
||||
self, get_package_url_mock, caplog
|
||||
):
|
||||
def test_process_ticket_two_packages_requested(self, caplog):
|
||||
"""
|
||||
Assert that package name wasn't found on dist-git
|
||||
Assert that ticket will be closed if in single title two packages were requested.
|
||||
"""
|
||||
caplog.set_level(logging.INFO)
|
||||
issue = {
|
||||
"title": "Unretire rubygem-logging11",
|
||||
"title": "Unretire rpms/rubygem-logging lala rpms/pakca",
|
||||
"content": "",
|
||||
"full_url": "",
|
||||
"user": {
|
||||
|
@ -262,43 +251,90 @@ class TestProcessTicket:
|
|||
},
|
||||
"id": 55,
|
||||
}
|
||||
|
||||
with patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages."
|
||||
"_get_namespace_and_repo"
|
||||
) as get_namespace_and_repo_mock:
|
||||
self.toddler.process_ticket(issue)
|
||||
|
||||
get_namespace_and_repo_mock.assert_not_called()
|
||||
|
||||
assert (
|
||||
caplog.records[-1].message
|
||||
== "Package with this name 'rubygem-logging11' wasn't found on dist-git"
|
||||
close_msg = (
|
||||
"Requester trying to request more than one package in single ticket "
|
||||
"or made a mistake in namespace."
|
||||
)
|
||||
|
||||
self.toddler.process_ticket(issue)
|
||||
assert caplog.records[-1].message == close_msg
|
||||
self.toddler.pagure_io.close_issue.assert_called_with(
|
||||
issue["id"],
|
||||
namespace=pdc_unretire_packages.PROJECT_NAMESPACE,
|
||||
message="Package wasn't found on dist-git",
|
||||
message=close_msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
|
||||
def test_process_ticket_invalid_package_name(self, caplog):
|
||||
"""
|
||||
Assert that ticket will be close if package name contain few `/` symbols.
|
||||
"""
|
||||
caplog.set_level(logging.INFO)
|
||||
issue = {
|
||||
"title": "Unretire rpms/ru/bygem-logging",
|
||||
"content": "",
|
||||
"full_url": "",
|
||||
"user": {
|
||||
"name": "",
|
||||
},
|
||||
"id": 55,
|
||||
}
|
||||
close_msg = (
|
||||
"Something strange happened, your package name might contain `/` symbol, "
|
||||
"correct it and reopen a ticket."
|
||||
)
|
||||
|
||||
self.toddler.process_ticket(issue)
|
||||
assert caplog.records[-1].message == close_msg
|
||||
self.toddler.pagure_io.close_issue.assert_called_with(
|
||||
issue["id"],
|
||||
namespace=pdc_unretire_packages.PROJECT_NAMESPACE,
|
||||
message=close_msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_namespace_and_repo",
|
||||
return_value=("dsadsa", "dsadsa"),
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._is_url_exist",
|
||||
return_value=False,
|
||||
)
|
||||
def test_process_ticket_url_doesnt_exist(self, mock_is_url_exist, caplog):
|
||||
"""
|
||||
Assert that ticket will be closed if url is not exist but other validations were completed.
|
||||
"""
|
||||
caplog.set_level(logging.INFO)
|
||||
issue = {
|
||||
"title": "Unretire rpms/rubygem-logging",
|
||||
"content": "",
|
||||
"full_url": "",
|
||||
"user": {
|
||||
"name": "",
|
||||
},
|
||||
"id": 55,
|
||||
}
|
||||
close_msg = (
|
||||
"Package repository doesnt exist, correct package name and reopen a ticket."
|
||||
)
|
||||
|
||||
self.toddler.process_ticket(issue)
|
||||
assert caplog.records[-1].message == close_msg
|
||||
self.toddler.pagure_io.close_issue.assert_called_with(
|
||||
issue["id"],
|
||||
namespace=pdc_unretire_packages.PROJECT_NAMESPACE,
|
||||
message=close_msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_package_url",
|
||||
return_value="ndsadsa",
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._is_url_exist",
|
||||
return_value=True,
|
||||
)
|
||||
def test_process_ticket_clone_repo_error(
|
||||
self, get_namespace_and_repo_mock, get_url_mock, caplog
|
||||
):
|
||||
def test_process_ticket_clone_repo_error(self, mock_is_url_exist, caplog):
|
||||
"""
|
||||
Assert that remote repo doesn't exist or user don't have a permission.
|
||||
"""
|
||||
caplog.set_level(logging.INFO)
|
||||
issue = {
|
||||
"title": "Unretire rubygem-logging11",
|
||||
"title": "Unretire rpms/rubygem-logging11",
|
||||
"content": "",
|
||||
"full_url": "",
|
||||
"user": {
|
||||
|
@ -306,45 +342,40 @@ class TestProcessTicket:
|
|||
},
|
||||
"id": 55,
|
||||
}
|
||||
message = (
|
||||
"Remote repository doesn't exist or you do not have "
|
||||
"the appropriate permissions to access it."
|
||||
close_msg = (
|
||||
"Remote repository doesn't exist or you do not have the appropriate "
|
||||
"permissions to access it."
|
||||
)
|
||||
# self.toddler.git_repo.side_effect = git.GitCommandError
|
||||
with patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.git.clone_repo",
|
||||
side_effect=git.GitCommandError("some_command"),
|
||||
):
|
||||
self.toddler.process_ticket(issue)
|
||||
|
||||
assert caplog.records[-1].message == message
|
||||
assert caplog.records[-1].message == close_msg
|
||||
self.toddler.pagure_io.close_issue.assert_called_with(
|
||||
issue["id"],
|
||||
namespace=pdc_unretire_packages.PROJECT_NAMESPACE,
|
||||
message=message,
|
||||
message=close_msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_namespace_and_repo",
|
||||
return_value=("dsadsa", "dsadsa"),
|
||||
)
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_package_url",
|
||||
return_value="some_url.git",
|
||||
)
|
||||
@patch("toddlers.plugins.pdc_unretire_packages.git")
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_tags_to_unblock"
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_tags_to_unblock",
|
||||
)
|
||||
def test_process_ticket_package_was_not_verified(
|
||||
self, get_tags_mock, git_mock, get_url_mock, get_ns_repo_mock
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._is_url_exist",
|
||||
return_value=True,
|
||||
)
|
||||
def test_process_ticket_package_not_ready_for_unretirement(
|
||||
self, mock_is_url_exist, mock_get_tags, mock_git
|
||||
):
|
||||
"""
|
||||
Assert that processing will end if package wasn't verified for untretirement.
|
||||
Assert that processing will not continue if package will not be verified.
|
||||
"""
|
||||
issue = {
|
||||
"title": "Unretire rubygem-logging",
|
||||
"title": "Unretire rpms/rubygem-logging11",
|
||||
"content": "",
|
||||
"full_url": "",
|
||||
"user": {
|
||||
|
@ -353,13 +384,12 @@ class TestProcessTicket:
|
|||
"id": 55,
|
||||
}
|
||||
with patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages"
|
||||
"._is_package_ready_for_unretirement",
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages."
|
||||
"_is_package_ready_for_unretirement",
|
||||
return_value=False,
|
||||
):
|
||||
self.toddler.process_ticket(issue)
|
||||
|
||||
get_tags_mock.assert_not_called()
|
||||
mock_get_tags.assert_not_called()
|
||||
|
||||
@patch("toddlers.plugins.pdc_unretire_packages.git")
|
||||
@patch("toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._adjust_eol_pdc")
|
||||
|
@ -379,15 +409,12 @@ class TestProcessTicket:
|
|||
"._is_package_ready_for_unretirement"
|
||||
)
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_namespace_and_repo"
|
||||
)
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._get_package_url"
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._is_url_exist",
|
||||
return_value=True,
|
||||
)
|
||||
def test_process_ticket(
|
||||
self,
|
||||
get_package_url_mock,
|
||||
get_namespace_and_repo_mock,
|
||||
mock_is_url_exist,
|
||||
is_package_ready_mock,
|
||||
get_tags_mock,
|
||||
is_need_to_unblock_mock,
|
||||
|
@ -402,7 +429,7 @@ class TestProcessTicket:
|
|||
caplog.set_level(logging.INFO)
|
||||
|
||||
issue = {
|
||||
"title": "Unretire rubygem-logging",
|
||||
"title": "Unretire rpms/rubygem-logging",
|
||||
"content": "body",
|
||||
"full_url": "some_url",
|
||||
"user": {
|
||||
|
@ -411,22 +438,17 @@ class TestProcessTicket:
|
|||
"id": 55,
|
||||
}
|
||||
|
||||
package_url = "some_url"
|
||||
namespace = "some_namespace"
|
||||
repo = "some_repo"
|
||||
namespace_and_repo = (namespace, repo)
|
||||
namespace = "rpms"
|
||||
repo = "rubygem-logging"
|
||||
tags_to_unblock = ["f37"]
|
||||
revert_message = f"Unretirement request: {issue['full_url']}"
|
||||
|
||||
get_package_url_mock.return_value = package_url
|
||||
get_namespace_and_repo_mock.return_value = namespace_and_repo
|
||||
is_package_ready_mock.return_value = True
|
||||
get_tags_mock.return_value = tags_to_unblock
|
||||
self.toddler.pagure_io.is_project_orphaned.return_value = True
|
||||
|
||||
self.toddler.process_ticket(issue)
|
||||
|
||||
get_namespace_and_repo_mock.assert_called_with(package_url)
|
||||
is_package_ready_mock.assert_called_with(
|
||||
issue_id=issue["id"], issue_body=issue["content"]
|
||||
)
|
||||
|
@ -446,75 +468,6 @@ class TestProcessTicket:
|
|||
assert caplog.records[-1].message == "everything was alright!"
|
||||
|
||||
|
||||
class TestGetPackageUrl:
|
||||
"""
|
||||
Test class for `toddlers.plugin.pdc_unretire_packages.PDCUnretirePackages._get_package_url`
|
||||
method.
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
"""
|
||||
Initialize toddler
|
||||
"""
|
||||
self.toddler = pdc_unretire_packages.PDCUnretirePackages()
|
||||
self.toddler.dist_git_base = "https://src.fedoraproject.org/"
|
||||
|
||||
def test_get_package_url_url_exist_with_namespace(self):
|
||||
"""
|
||||
Assert that get package url works correctly, when package name with namespace.
|
||||
"""
|
||||
package_name = "rpms/rubygem-logging"
|
||||
url = "https://src.fedoraproject.org//" + package_name + ".git"
|
||||
|
||||
assert self.toddler._get_package_url(package_name) == url
|
||||
|
||||
def test_get_package_url_url_exist_without_namespace(self):
|
||||
"""
|
||||
Assert that get package url works correctly, when package name without namespace.
|
||||
"""
|
||||
package_name = "rubygem-logging"
|
||||
url = "https://src.fedoraproject.org//" + "rpms//" + package_name + ".git"
|
||||
|
||||
assert self.toddler._get_package_url(package_name) == url
|
||||
|
||||
def test_get_package_url_url_not_exist(self):
|
||||
"""
|
||||
Assert that get package url works correctly, when package name without namespace.
|
||||
"""
|
||||
package_name = "rubygem-loggin321g"
|
||||
|
||||
assert self.toddler._get_package_url(package_name) is None
|
||||
|
||||
|
||||
class TestGetNamespaceAndRepo:
|
||||
"""
|
||||
Test class for `toddlers.plugin.pdc_unretire_packages.PDCUnretirePackages
|
||||
._get_namespace_and_repo` method.
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
"""
|
||||
Initialize toddler
|
||||
"""
|
||||
self.toddler = pdc_unretire_packages.PDCUnretirePackages()
|
||||
|
||||
def test_get_namespace_and_repo_url_with_suffix(self):
|
||||
"""
|
||||
Assert that get namespace and repo works fine when url contain suffix.
|
||||
"""
|
||||
url = "https://src.fedoraproject.org//" + "rpms/rubygem-logging" + ".git"
|
||||
|
||||
assert self.toddler._get_namespace_and_repo(url) == ("rpms", "rubygem-logging")
|
||||
|
||||
def test_get_namespace_and_repo_url_without_suffix(self):
|
||||
"""
|
||||
Assert that get namespace and repo works fine when url not contain suffix.
|
||||
"""
|
||||
url = "https://src.fedoraproject.org//" + "rpms/rubygem-logging"
|
||||
|
||||
assert self.toddler._get_namespace_and_repo(url) == ("rpms", "rubygem-logging")
|
||||
|
||||
|
||||
class TestIsPackageReadyForUnretirement:
|
||||
"""
|
||||
Test class for `toddlers.plugin.pdc_unretire_packages.PDCUnreturePackages
|
||||
|
@ -562,11 +515,11 @@ class TestIsPackageReadyForUnretirement:
|
|||
"""
|
||||
issue_id = 55
|
||||
issue_body = ""
|
||||
err_msg = "Last commit was made more than 8 weeks ago."
|
||||
err_msg = "Couldn't get a date of the retire commit."
|
||||
|
||||
with patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages"
|
||||
"._verify_last_commit_date_correct",
|
||||
"._verify_bugzilla_need_to_be_checked",
|
||||
side_effect=ValidationError(err_msg),
|
||||
):
|
||||
assert (
|
||||
|
@ -582,51 +535,14 @@ class TestIsPackageReadyForUnretirement:
|
|||
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages."
|
||||
"_verify_last_commit_date_correct"
|
||||
)
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages."
|
||||
"_verify_package_not_retired_for_reason"
|
||||
)
|
||||
def test_is_package_ready_for_unretirement_bugzilla_issue(
|
||||
self, verify_reason_mock, verify_date_mock
|
||||
):
|
||||
"""
|
||||
Assert that package won't be verified if it has some issue on bugzilla.
|
||||
"""
|
||||
issue_id = 55
|
||||
issue_body = ""
|
||||
err_msg = "Last commit was made more than 8 weeks ago."
|
||||
|
||||
with patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages"
|
||||
"._verify_bugzilla_ticket",
|
||||
side_effect=ValidationError(err_msg),
|
||||
):
|
||||
assert (
|
||||
self.toddler._is_package_ready_for_unretirement(issue_id, issue_body)
|
||||
is False
|
||||
)
|
||||
self.toddler.pagure_io.close_issue.assert_called_with(
|
||||
issue_id=issue_id,
|
||||
namespace=pdc_unretire_packages.PROJECT_NAMESPACE,
|
||||
message=err_msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._verify_bugzilla_ticket"
|
||||
)
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages."
|
||||
"_verify_last_commit_date_correct"
|
||||
"_verify_bugzilla_need_to_be_checked"
|
||||
)
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages."
|
||||
"_verify_package_not_retired_for_reason"
|
||||
)
|
||||
def test_is_package_ready_for_unretirement(
|
||||
self, verify_reason_mock, verify_date_mock, verify_bugzilla_mock
|
||||
self, verify_reason_mock, need_to_check_bz_mock
|
||||
):
|
||||
"""
|
||||
Assert that method process correctly.
|
||||
|
@ -639,8 +555,7 @@ class TestIsPackageReadyForUnretirement:
|
|||
is True
|
||||
)
|
||||
verify_reason_mock.assert_called()
|
||||
verify_date_mock.assert_called()
|
||||
verify_bugzilla_mock.assert_called_with(issue_body=issue_body)
|
||||
need_to_check_bz_mock.assert_called_with(issue_body=issue_body)
|
||||
|
||||
|
||||
class TestVerifyPackageNotRetiredForReason:
|
||||
|
@ -678,10 +593,10 @@ class TestVerifyPackageNotRetiredForReason:
|
|||
self.toddler._verify_package_not_retired_for_reason()
|
||||
|
||||
|
||||
class TestVerifyLastCommitDateCorrect:
|
||||
class TestVerifyBugzillaNeedToBeChecked:
|
||||
"""
|
||||
Test class for `toddlers.plugin.pdc_unretire_packages.PDCUnreturePackages
|
||||
._verify_last_commit_date_correct` method.
|
||||
._verify_bugzilla_need_to_be_checked` method.
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
|
@ -691,37 +606,51 @@ class TestVerifyLastCommitDateCorrect:
|
|||
self.toddler = pdc_unretire_packages.PDCUnretirePackages()
|
||||
self.toddler.git_repo = Mock()
|
||||
|
||||
def test_verify_last_commit_date_correct_date_is_none(self):
|
||||
def test_verify_bugzilla_need_to_be_checked_date_is_none(self):
|
||||
"""
|
||||
Assert that method will raise Exception if git won't be able to find a date.
|
||||
"""
|
||||
err_msg = "Couldn't get a date of the retire commit."
|
||||
issue_body = "issue body"
|
||||
|
||||
self.toddler.git_repo.get_last_commit_date.return_value = None
|
||||
|
||||
with pytest.raises(ValidationError, match=err_msg):
|
||||
self.toddler._verify_last_commit_date_correct()
|
||||
self.toddler._verify_bugzilla_need_to_be_checked(issue_body=issue_body)
|
||||
|
||||
def test_verify_last_commit_date_correct_date_not_correct(self):
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._verify_bugzilla_ticket"
|
||||
)
|
||||
def test_verify_bugzilla_need_to_be_checked_need_to_check_bugzilla(
|
||||
self, mock_verify_bz
|
||||
):
|
||||
"""
|
||||
Assert that method will raise Exception if date will be more than 8 weeks ago.
|
||||
Assert that method will call bz check if commit was made more than 8 weeks ago.
|
||||
"""
|
||||
err_msg = "The retire commit was made more than 8 weeks ago."
|
||||
issue_body = "body"
|
||||
|
||||
self.toddler.git_repo.get_last_commit_date.return_value = 0
|
||||
|
||||
with pytest.raises(ValidationError, match=err_msg):
|
||||
self.toddler._verify_last_commit_date_correct()
|
||||
self.toddler._verify_bugzilla_need_to_be_checked(issue_body)
|
||||
mock_verify_bz.assert_called_once()
|
||||
|
||||
def test_verify_last_commit_date_correct(self):
|
||||
@patch(
|
||||
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages._verify_bugzilla_ticket"
|
||||
)
|
||||
def test_verify_bugzilla_need_to_be_checked_no_need_to_check_bugzilla(
|
||||
self, mock_verify_bz
|
||||
):
|
||||
"""
|
||||
Assert that method won't raise any Exceptions if date is correct.
|
||||
Assert that method won't call bz check if commit was made less than 8 weeks ago.
|
||||
"""
|
||||
issue_body = "body"
|
||||
|
||||
commit_date = (datetime.datetime.now() - datetime.timedelta(days=1)).timestamp()
|
||||
|
||||
self.toddler.git_repo.get_last_commit_date.return_value = commit_date
|
||||
|
||||
self.toddler._verify_last_commit_date_correct()
|
||||
self.toddler._verify_bugzilla_need_to_be_checked(issue_body=issue_body)
|
||||
mock_verify_bz.assert_not_called()
|
||||
|
||||
|
||||
class TestVerifyBugzillaTicket:
|
||||
|
@ -1341,6 +1270,41 @@ class TestGetProperEolForBranches:
|
|||
assert self.toddler._get_proper_eol_for_branches(tags_to_unblock) == result
|
||||
|
||||
|
||||
class TestIsUrlExist:
|
||||
"""
|
||||
Test class for `toddlers.plugin.pdc_unretire_packages.PDCUnreturePackages
|
||||
._is_url_exist` method.
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
"""
|
||||
Initialize toddler.
|
||||
"""
|
||||
self.toddler = pdc_unretire_packages.PDCUnretirePackages()
|
||||
|
||||
@patch("requests.get")
|
||||
def test_is_url_exist_exist(self, mock_get_request):
|
||||
"""
|
||||
Assert that method will return True if url exist.
|
||||
"""
|
||||
response = Mock()
|
||||
response.status_code = 200
|
||||
mock_get_request.return_value = response
|
||||
url = "some url that exist"
|
||||
assert self.toddler._is_url_exist(url) is True
|
||||
|
||||
@patch("requests.get")
|
||||
def test_is_url_exist_not_exist(self, mock_get_request):
|
||||
"""
|
||||
Assert that method will return False if url not exist.
|
||||
"""
|
||||
response = Mock()
|
||||
response.status_code = 505
|
||||
mock_get_request.return_value = response
|
||||
url = "some url that not exist"
|
||||
assert self.toddler._is_url_exist(url) is False
|
||||
|
||||
|
||||
class TestMain:
|
||||
"""
|
||||
Test class for `toddlers.plugins.pdc_unretire_packages.main` function.
|
||||
|
|
|
@ -33,6 +33,8 @@ BRANCHES_REGEX = r"f\d{2}"
|
|||
PROJECT_NAMESPACE = "releng/fedora-scm-requests"
|
||||
# Keyword that will be searched for in the issue title
|
||||
UNRETIRE_KEYWORD = "unretire"
|
||||
# RPM package prefix, that will be searched in the issue title
|
||||
RPM_PREFIX = "rpms/"
|
||||
# Forbidden keywords for commit message
|
||||
FORBIDDEN_KEYWORDS_FOR_COMMIT_MESSAGE = ["legal", "license"]
|
||||
# Time difference limit not getting Bugzilla url
|
||||
|
@ -172,55 +174,91 @@ class PDCUnretirePackages(ToddlerBase):
|
|||
issue_opener = issue["user"]["name"]
|
||||
issue_id = issue["id"]
|
||||
|
||||
# improve searching for package name
|
||||
end_of_keyword_in_title_index = (
|
||||
issue_title.lower().index(UNRETIRE_KEYWORD) + len(UNRETIRE_KEYWORD) + 1
|
||||
_log.debug("Verifying that issue title has `{0}` prefix".format(RPM_PREFIX))
|
||||
if RPM_PREFIX not in issue_title.lower():
|
||||
msg = (
|
||||
"Unretire can only apply to rpm packages, please add `{0}`"
|
||||
" prefix before the package name"
|
||||
).format(RPM_PREFIX)
|
||||
_log.info(msg)
|
||||
self.pagure_io.close_issue(
|
||||
issue_id,
|
||||
namespace=PROJECT_NAMESPACE,
|
||||
message=msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
return
|
||||
|
||||
_log.debug("Verifying that just single package is requested in one ticket.")
|
||||
words_in_issue_title = issue_title.split()
|
||||
words_with_prefix = [
|
||||
word.lower()
|
||||
for word in words_in_issue_title
|
||||
if word.lower().startswith(RPM_PREFIX)
|
||||
]
|
||||
if len(words_with_prefix) != 1:
|
||||
msg = (
|
||||
"Requester trying to request more than one package in single ticket "
|
||||
"or made a mistake in namespace."
|
||||
)
|
||||
_log.info(msg)
|
||||
self.pagure_io.close_issue(
|
||||
issue_id,
|
||||
namespace=PROJECT_NAMESPACE,
|
||||
message=msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
return
|
||||
|
||||
pkg_name_with_ns = words_with_prefix[0]
|
||||
pkg_name_and_ns = [word for word in pkg_name_with_ns.split("/") if word != ""]
|
||||
|
||||
_log.debug("Verifying that package name with namespace are correct.")
|
||||
if len(pkg_name_and_ns) != 2:
|
||||
msg = (
|
||||
"Something strange happened, your package name might contain `/` symbol, "
|
||||
"correct it and reopen a ticket."
|
||||
)
|
||||
_log.info(msg)
|
||||
self.pagure_io.close_issue(
|
||||
issue_id,
|
||||
namespace=PROJECT_NAMESPACE,
|
||||
message=msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
return
|
||||
|
||||
namespace = pkg_name_and_ns[0]
|
||||
package_name = pkg_name_and_ns[1]
|
||||
package_url = "{0}/{1}/{2}.git".format(
|
||||
self.dist_git_base, namespace, package_name
|
||||
)
|
||||
|
||||
inaccurate_package_name = issue_title[end_of_keyword_in_title_index:]
|
||||
list_of_words_in_package_name = [
|
||||
word.strip() for word in inaccurate_package_name.split(" ")
|
||||
]
|
||||
|
||||
if len(list_of_words_in_package_name) > 1:
|
||||
_log.info(
|
||||
"Package name '{0}' has two or more words".format(
|
||||
inaccurate_package_name
|
||||
)
|
||||
)
|
||||
_log.debug("Verifying that package repository is actually exist.")
|
||||
if not self._is_url_exist(package_url):
|
||||
msg = "Package repository doesnt exist, correct package name and reopen a ticket."
|
||||
_log.info(msg)
|
||||
self.pagure_io.close_issue(
|
||||
issue_id,
|
||||
namespace=PROJECT_NAMESPACE,
|
||||
message="Invalid package name.",
|
||||
message=msg,
|
||||
reason="Invalid",
|
||||
)
|
||||
return
|
||||
|
||||
inaccurate_package_name = list_of_words_in_package_name[0]
|
||||
cloned_repo_name = "{0}_repo".format(inaccurate_package_name.replace("/", "_"))
|
||||
package_url = self._get_package_url(inaccurate_package_name)
|
||||
|
||||
if not package_url:
|
||||
_log.info(
|
||||
"Package with this name '{0}' wasn't found on dist-git".format(
|
||||
inaccurate_package_name
|
||||
)
|
||||
)
|
||||
self.pagure_io.close_issue(
|
||||
issue_id,
|
||||
namespace=PROJECT_NAMESPACE,
|
||||
message="Package wasn't found on dist-git",
|
||||
reason="Invalid",
|
||||
)
|
||||
return
|
||||
|
||||
namespace, repo = self._get_namespace_and_repo(package_url)
|
||||
folder_name_for_clonned_repo = "{0}_folder".format(package_name)
|
||||
|
||||
_log.info("Creating temporary directory")
|
||||
with tempfile.TemporaryDirectory():
|
||||
_log.info("Cloning repo into dir with name '{0}'".format(cloned_repo_name))
|
||||
_log.info(
|
||||
"Cloning repo into dir with name '{0}'".format(
|
||||
folder_name_for_clonned_repo
|
||||
)
|
||||
)
|
||||
try:
|
||||
self.git_repo = git.clone_repo(package_url, cloned_repo_name)
|
||||
self.git_repo = git.clone_repo(
|
||||
package_url, folder_name_for_clonned_repo
|
||||
)
|
||||
except GitCommandError:
|
||||
message = (
|
||||
"Remote repository doesn't exist or you do not have the appropriate "
|
||||
|
@ -248,64 +286,23 @@ class PDCUnretirePackages(ToddlerBase):
|
|||
self.git_repo.revert_last_commit(message=revert_commit_message)
|
||||
|
||||
_log.info("Unblocking tags on Koji.")
|
||||
if self._is_need_to_unblock_tags_on_koji(tags_to_unblock, repo):
|
||||
self._unblock_tags_on_koji(issue_id, tags_to_unblock, repo)
|
||||
if self._is_need_to_unblock_tags_on_koji(tags_to_unblock, package_name):
|
||||
self._unblock_tags_on_koji(issue_id, tags_to_unblock, package_name)
|
||||
|
||||
_log.info("Verifying package is not orphan.")
|
||||
if self.pagure_io.is_project_orphaned(namespace=namespace, repo=repo):
|
||||
if self.pagure_io.is_project_orphaned(
|
||||
namespace=namespace, repo=package_name
|
||||
):
|
||||
self.pagure_io.assign_maintainer_to_project(
|
||||
namespace=namespace, repo=repo, maintainer_fas=issue_opener
|
||||
namespace=namespace, repo=package_name, maintainer_fas=issue_opener
|
||||
)
|
||||
|
||||
_log.info("Adjusting eol on PDC.")
|
||||
self._adjust_eol_pdc(namespace, repo, tags_to_unblock)
|
||||
self._adjust_eol_pdc(namespace, package_name, tags_to_unblock)
|
||||
|
||||
_log.info("everything was alright!")
|
||||
return
|
||||
|
||||
def _get_package_url(self, package_name: str) -> Optional[str]:
|
||||
"""
|
||||
Return a package url.
|
||||
|
||||
:arg package_name: A package name with or without namespace
|
||||
|
||||
:returns: Package dist-git url or 'not_found' if url doesn't exist.
|
||||
"""
|
||||
package_namespaces = ("rpms/", "modules/", "container/")
|
||||
|
||||
if package_name.startswith(package_namespaces):
|
||||
url = f"{self.dist_git_base}/{package_name}.git"
|
||||
if self._is_url_exist(url):
|
||||
return url
|
||||
else:
|
||||
for namespace in package_namespaces:
|
||||
url = f"{self.dist_git_base}/{namespace}/{package_name}.git"
|
||||
if self._is_url_exist(url):
|
||||
return url
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _get_namespace_and_repo(package_url: str) -> tuple:
|
||||
"""
|
||||
Get namespace and package name from package url of exist package.
|
||||
|
||||
:arg package_url: A package url
|
||||
|
||||
:returns: A tuple with package namespace and package name
|
||||
"""
|
||||
suffix = ".git"
|
||||
if package_url.endswith(suffix):
|
||||
url_without_suffix = package_url[: len(package_url) - len(suffix)]
|
||||
else:
|
||||
url_without_suffix = package_url
|
||||
|
||||
list_of_elements = url_without_suffix.split("/")
|
||||
list_of_elements = [el for el in list_of_elements if el != ""]
|
||||
|
||||
package_name = list_of_elements[-1]
|
||||
namespace = list_of_elements[-2]
|
||||
return namespace, package_name
|
||||
|
||||
def _is_package_ready_for_unretirement(
|
||||
self, issue_id: int, issue_body: str
|
||||
) -> bool:
|
||||
|
@ -321,9 +318,7 @@ class PDCUnretirePackages(ToddlerBase):
|
|||
_log.info("Verifying the reason of retirement.")
|
||||
self._verify_package_not_retired_for_reason()
|
||||
_log.info("Verifying the date of retirement.")
|
||||
self._verify_last_commit_date_correct()
|
||||
_log.info("Verifying bugzilla.")
|
||||
self._verify_bugzilla_ticket(issue_body=issue_body)
|
||||
self._verify_bugzilla_need_to_be_checked(issue_body=issue_body)
|
||||
except ValidationError as error:
|
||||
self.pagure_io.close_issue(
|
||||
issue_id=issue_id,
|
||||
|
@ -352,12 +347,9 @@ class PDCUnretirePackages(ToddlerBase):
|
|||
"Package was retired for a reason: legal of license issue."
|
||||
)
|
||||
|
||||
def _verify_last_commit_date_correct(self):
|
||||
def _verify_bugzilla_need_to_be_checked(self, issue_body):
|
||||
"""
|
||||
Verify that last commit was made less than 8 weeks ago.
|
||||
|
||||
Raises:
|
||||
`toddler.exceptions.ValidationError`: When retirement date wasn't verified.
|
||||
Verify if last commit was made more than 8 weeks ago, need to request a bugzilla ticket.
|
||||
"""
|
||||
_log.info("Verifying that retire commit was made less than 8 weeks ago.")
|
||||
|
||||
|
@ -375,7 +367,7 @@ class PDCUnretirePackages(ToddlerBase):
|
|||
time_diff_in_days = time_diff.days
|
||||
|
||||
if time_diff_in_days > TIME_DIFFERENCE_LIMIT:
|
||||
raise ValidationError("The retire commit was made more than 8 weeks ago.")
|
||||
self._verify_bugzilla_ticket(issue_body=issue_body)
|
||||
|
||||
@staticmethod
|
||||
def _verify_bugzilla_ticket(issue_body: str):
|
||||
|
@ -644,7 +636,7 @@ def _get_arguments(args):
|
|||
|
||||
def _setup_logging(log_level: int) -> None:
|
||||
"""
|
||||
Setup the logging level.
|
||||
Set up the logging level.
|
||||
|
||||
:arg log_level: Log level to set
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue