forked from packaging/fedpkg
Migrate SCM requests from Pagure to Forgejo
Signed-off-by: Patrik Polakovič <patrik@alphamail.org>
This commit is contained in:
parent
59a87875c0
commit
326fb9c82b
10 changed files with 379 additions and 293 deletions
|
|
@ -61,8 +61,8 @@ url = https://bodhi.stg.fedoraproject.org/
|
|||
# Use production Bugzilla for read-only data
|
||||
url = https://bugzilla.redhat.com/
|
||||
|
||||
[fedpkg-stage.pagure]
|
||||
url = https://stg.pagure.io/
|
||||
[fedpkg-stage.forgejo]
|
||||
url = https://forge.stg.fedoraproject.org/
|
||||
|
||||
[fedpkg-stage.greenwave]
|
||||
url = https://greenwave.stg.fedoraproject.org/
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ url = https://bodhi.fedoraproject.org/
|
|||
[fedpkg.bugzilla]
|
||||
url = https://bugzilla.redhat.com/
|
||||
|
||||
[fedpkg.pagure]
|
||||
url = https://pagure.io/
|
||||
token =
|
||||
[fedpkg.forgejo]
|
||||
url = https://forge.fedoraproject.org/
|
||||
token =
|
||||
|
||||
[fedpkg.greenwave]
|
||||
url = https://greenwave.fedoraproject.org/
|
||||
|
|
|
|||
110
fedpkg/cli.py
110
fedpkg/cli.py
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
|
||||
import argparse
|
||||
import io
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
|
|
@ -57,7 +56,7 @@ from fedpkg.utils import (
|
|||
get_stream_branches,
|
||||
guess_package_type,
|
||||
is_epel,
|
||||
new_pagure_issue,
|
||||
new_forgejo_issue,
|
||||
sl_list_to_dict,
|
||||
verify_sls,
|
||||
)
|
||||
|
|
@ -152,7 +151,7 @@ class fedpkgClient(cliClient):
|
|||
self.register_do_fork()
|
||||
self.register_override()
|
||||
self.register_set_distgit_token()
|
||||
self.register_set_pagure_token()
|
||||
self.register_set_forgejo_token()
|
||||
self.register_do_disable_monitoring()
|
||||
self.register_request_unretirement()
|
||||
self.register_new_package()
|
||||
|
|
@ -326,27 +325,27 @@ class fedpkgClient(cliClient):
|
|||
return None
|
||||
|
||||
def _common_api_key_description(self):
|
||||
pagure_section = '{0}.pagure'.format(self.name)
|
||||
pagure_url = config_get_safely(self.config, pagure_section, 'url')
|
||||
pagure_url_parsed = urlparse(pagure_url).netloc
|
||||
forgejo_section = '{0}.forgejo'.format(self.name)
|
||||
forgejo_url = config_get_safely(self.config, forgejo_section, 'url')
|
||||
forgejo_url_parsed = urlparse(forgejo_url).netloc
|
||||
|
||||
return '''
|
||||
Before the operation, you need to generate a pagure.io API token at:
|
||||
https://{1}/settings/token/new
|
||||
Before the operation, you need to generate a Forgejo API token at:
|
||||
https://{1}/user/settings/applications
|
||||
|
||||
ACL required:
|
||||
"Create a new ticket"
|
||||
"write:issue"
|
||||
|
||||
Update your token with the following command:
|
||||
{0} set-pagure-token
|
||||
{0} set-forgejo-token
|
||||
|
||||
Command saves token to {0} config file:
|
||||
~/.config/rpkg/{0}.conf
|
||||
|
||||
For example:
|
||||
[{0}.pagure]
|
||||
[{0}.forgejo]
|
||||
token = <api_key_here>
|
||||
'''.format(self.name, pagure_url_parsed)
|
||||
'''.format(self.name, forgejo_url_parsed)
|
||||
|
||||
def register_request_repo(self):
|
||||
help_msg = 'Request a new dist-git repository'
|
||||
|
|
@ -552,8 +551,7 @@ class fedpkgClient(cliClient):
|
|||
request_branch_parser.add_argument(
|
||||
'--no-auto-module', default=False, action='store_true',
|
||||
help='If requesting an rpm arbitrary branch, do not '
|
||||
'also request a new matching module. See '
|
||||
'https://pagure.io/fedrepo_req/issue/129'
|
||||
'also request a new matching module.'
|
||||
)
|
||||
request_branch_parser.add_argument(
|
||||
'--all-releases', default=False, action='store_true',
|
||||
|
|
@ -742,21 +740,31 @@ class fedpkgClient(cliClient):
|
|||
|
||||
parser.set_defaults(command=self.set_distgit_token)
|
||||
|
||||
def register_set_pagure_token(self):
|
||||
pagure_section = '{0}.pagure'.format(self.name)
|
||||
pagure_url = config_get_safely(self.config, pagure_section, 'url')
|
||||
def register_set_forgejo_token(self):
|
||||
forgejo_section = '{0}.forgejo'.format(self.name)
|
||||
forgejo_url = config_get_safely(self.config, forgejo_section, 'url')
|
||||
help_msg = \
|
||||
'Updates the fedpkg.pagure API token in ~/.config/rpkg/{0}.conf file.\n\n\
|
||||
Tokens are of length 64 and contain only uppercase and numerical values.\n\
|
||||
The new API token. Can be generated at: \n\
|
||||
https://{1}/settings/token/new'\
|
||||
.format(self.name, urlparse(pagure_url).netloc)
|
||||
'Updates the fedpkg.forgejo API token in ~/.config/rpkg/{0}.conf file.\n\n\
|
||||
The new API token can be generated at: \n\
|
||||
https://{1}/user/settings/applications'\
|
||||
.format(self.name, urlparse(forgejo_url).netloc)
|
||||
|
||||
parser = self.subparsers.add_parser(
|
||||
'set-forgejo-token',
|
||||
help=help_msg,
|
||||
description=help_msg)
|
||||
|
||||
parser.set_defaults(command=self.set_forgejo_token)
|
||||
|
||||
def register_set_pagure_token(self):
|
||||
help_msg = (
|
||||
'Deprecated: Pagure tokens are no longer needed.\n'
|
||||
'Use "set-forgejo-token" instead.'
|
||||
)
|
||||
parser = self.subparsers.add_parser(
|
||||
'set-pagure-token',
|
||||
help=help_msg,
|
||||
description=help_msg)
|
||||
|
||||
parser.set_defaults(command=self.set_pagure_token)
|
||||
|
||||
def register_override(self):
|
||||
|
|
@ -1344,11 +1352,11 @@ class fedpkgClient(cliClient):
|
|||
ticket_body = '```\n{0}\n```'.format(ticket_body)
|
||||
ticket_title = 'New Repo for "{0}/{1}"'.format(ns, repo_name)
|
||||
|
||||
pagure_section = '{0}.pagure'.format(name)
|
||||
pagure_url = config_get_safely(config, pagure_section, 'url')
|
||||
pagure_token = config_get_safely(config, pagure_section, 'token')
|
||||
print(new_pagure_issue(
|
||||
logger, pagure_url, pagure_token, ticket_title, ticket_body, name))
|
||||
forgejo_section = '{0}.forgejo'.format(name)
|
||||
forgejo_url = config_get_safely(config, forgejo_section, 'url')
|
||||
forgejo_token = config_get_safely(config, forgejo_section, 'token')
|
||||
print(new_forgejo_issue(
|
||||
logger, forgejo_url, forgejo_token, ticket_title, ticket_body, name))
|
||||
|
||||
def request_branch(self):
|
||||
if self.args.repo_name_for_branch:
|
||||
|
|
@ -1394,8 +1402,8 @@ class fedpkgClient(cliClient):
|
|||
value of `self.cmd.repo_name`.
|
||||
:param ns: The repository namespace string, i.e. 'rpms' or 'modules'.
|
||||
Typically takes the value of `self.cmd.ns`.
|
||||
:param no_git_branch: A boolean flag. If True, the SCM admins should
|
||||
create the git branch in PDC, but not in pagure.io.
|
||||
:param no_git_branch: A boolean flag. If True, the branch will not be
|
||||
created in the dist-git repository.
|
||||
:param no_auto_module: A boolean flag. If True, requests for
|
||||
non-standard branches should not automatically result in additional
|
||||
requests for matching modules.
|
||||
|
|
@ -1473,9 +1481,10 @@ class fedpkgClient(cliClient):
|
|||
sl_dict = sl_list_to_dict(service_levels)
|
||||
verify_sls(sl_dict)
|
||||
|
||||
pagure_section = '{0}.pagure'.format(name)
|
||||
pagure_url = config_get_safely(config, pagure_section, 'url')
|
||||
pagure_token = config_get_safely(config, pagure_section, 'token')
|
||||
forgejo_section = '{0}.forgejo'.format(name)
|
||||
forgejo_url = config_get_safely(config, forgejo_section, 'url')
|
||||
forgejo_token = config_get_safely(config, forgejo_section, 'token')
|
||||
|
||||
if all_releases:
|
||||
release_branches = list(itertools.chain(
|
||||
*list(get_release_branches(bodhi_url).values())))
|
||||
|
|
@ -1507,8 +1516,8 @@ class fedpkgClient(cliClient):
|
|||
namespace=ns,
|
||||
repo_name=repo_name
|
||||
):
|
||||
print(new_pagure_issue(
|
||||
logger, pagure_url, pagure_token, ticket_title, ticket_body,
|
||||
print(new_forgejo_issue(
|
||||
logger, forgejo_url, forgejo_token, ticket_title, ticket_body,
|
||||
name))
|
||||
else:
|
||||
logger.warning('Requested branch "{0}" already exists. '
|
||||
|
|
@ -1667,9 +1676,9 @@ class fedpkgClient(cliClient):
|
|||
bz_client.get_review_bug(bug_id, ns, repo_name)
|
||||
|
||||
# Ticket creation
|
||||
pagure_section = '{0}.pagure'.format(name)
|
||||
pagure_url = config_get_safely(config, pagure_section, 'url')
|
||||
pagure_token = config_get_safely(config, pagure_section, 'token')
|
||||
forgejo_section = '{0}.forgejo'.format(name)
|
||||
forgejo_url = config_get_safely(config, forgejo_section, 'url')
|
||||
forgejo_token = config_get_safely(config, forgejo_section, 'token')
|
||||
|
||||
ticket_body = {
|
||||
'action': 'unretirement',
|
||||
|
|
@ -1685,10 +1694,10 @@ class fedpkgClient(cliClient):
|
|||
ticket_title = 'Unretire {0}'.format(repo_name)
|
||||
|
||||
print(
|
||||
new_pagure_issue(
|
||||
new_forgejo_issue(
|
||||
logger=logger,
|
||||
url=pagure_url,
|
||||
token=pagure_token,
|
||||
url=forgejo_url,
|
||||
token=forgejo_token,
|
||||
title=ticket_title,
|
||||
body=ticket_body,
|
||||
cli_name=name,
|
||||
|
|
@ -1932,20 +1941,29 @@ class fedpkgClient(cliClient):
|
|||
print('EPEL: {0}'.format(_join(releases['epel'])))
|
||||
|
||||
def _check_token(self, token, token_type):
|
||||
|
||||
if token is None or token == "":
|
||||
self.log.error("ERROR: No input.")
|
||||
return False
|
||||
|
||||
match = re.search(r'^\s*[A-Z0-9]{64}\s*$', token)
|
||||
if token_type == "forgejo": # noqa: S105
|
||||
match = re.search(r'^\s*[a-f0-9]{40}\s*$', token)
|
||||
else:
|
||||
match = re.search(r'^\s*[A-Z0-9]{64}\s*$', token)
|
||||
|
||||
if match is None:
|
||||
self.log.error("ERROR: Token is not properly formatted.")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
def set_forgejo_token(self):
|
||||
super(fedpkgClient, self)._set_token("forgejo")
|
||||
|
||||
def set_pagure_token(self):
|
||||
super(fedpkgClient, self)._set_token("pagure")
|
||||
self.log.info(
|
||||
'Pagure tokens are no longer needed for SCM requests.\n'
|
||||
'Please use "set-forgejo-token" instead:\n\n'
|
||||
'\t{0} set-forgejo-token\n'.format(self.name))
|
||||
|
||||
def set_distgit_token(self):
|
||||
super(fedpkgClient, self)._set_token("distgit")
|
||||
|
|
|
|||
|
|
@ -57,63 +57,55 @@ def query_bodhi(server_url, timeout=60):
|
|||
return branches
|
||||
|
||||
|
||||
def new_pagure_issue(logger, url, token, title, body, cli_name):
|
||||
def new_forgejo_issue(logger, url, token, title, body, cli_name):
|
||||
"""
|
||||
Posts a new Pagure issue
|
||||
Posts a new Forgejo issue
|
||||
:param logger: A logger object
|
||||
:param url: a string of the URL to Pagure
|
||||
:param token: a string of the Pagure API token that has rights to create
|
||||
:param url: a string of the URL to Forgejo
|
||||
:param token: a string of the Forgejo API token that has rights to create
|
||||
a ticket
|
||||
:param title: a string of the issue's title
|
||||
:param body: a string of the issue's body
|
||||
:return: a string of the URL to the created issue in the UI
|
||||
"""
|
||||
api_url = '{0}/api/0'.format(url.rstrip('/'))
|
||||
new_issue_url = '{0}/releng/fedora-scm-requests/new_issue'.format(api_url)
|
||||
api_url = "{0}/api/v1/repos/releng/fedora-scm-requests/issues".format(url.rstrip("/"))
|
||||
|
||||
headers = {
|
||||
'Authorization': 'token {0}'.format(token),
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
"Authorization": "token {0}".format(token),
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
payload = json.dumps({
|
||||
'title': title,
|
||||
'issue_content': body
|
||||
})
|
||||
payload = json.dumps({"title": title, "body": body})
|
||||
try:
|
||||
rv = requests.post(
|
||||
new_issue_url, headers=headers, data=payload, timeout=60)
|
||||
rv = requests.post(api_url, headers=headers, data=payload, timeout=60)
|
||||
except ConnectionError as error:
|
||||
error_msg = ('The connection to Pagure failed while trying to '
|
||||
'create a new issue. The error was: {0}'.format(
|
||||
str(error)))
|
||||
error_msg = (
|
||||
"The connection to Forgejo failed while trying to "
|
||||
"create a new issue. The error was: {0}".format(str(error))
|
||||
)
|
||||
raise rpkgError(error_msg)
|
||||
|
||||
base_error_msg = ('The following error occurred while creating a new '
|
||||
'issue in Pagure: {0}')
|
||||
base_error_msg = "The following error occurred while creating a new issue in Forgejo: {0}"
|
||||
|
||||
try:
|
||||
# Extract response error text (and debug data)
|
||||
rv_json = rv.json()
|
||||
logger.debug("Pagure API response: '{0}'".format(rv_json))
|
||||
rv_error = rv_json.get('error')
|
||||
logger.debug("Forgejo API response: '{0}'".format(rv_json))
|
||||
rv_error = rv_json.get("message") or rv.text
|
||||
except (ValueError, AttributeError):
|
||||
rv_error = rv.text
|
||||
|
||||
if not rv.ok:
|
||||
# Lets see if the API returned an error message in JSON that we can
|
||||
# show the user
|
||||
# show hint for expired token
|
||||
if re.search(r"Invalid or expired token", rv_error, re.IGNORECASE):
|
||||
base_error_msg += '\nFor invalid or expired tokens please ' \
|
||||
'set a new token in your user configuration by running:' \
|
||||
'\n\n\t{0} set-pagure-token\n\n' \
|
||||
'The command is interactive; enter the new token when ' \
|
||||
'prompted.\n'.format(cli_name)
|
||||
if re.search(r"token is required", rv_error, re.IGNORECASE):
|
||||
base_error_msg += (
|
||||
"\nPlease set a valid token in your user configuration by running:"
|
||||
"\n\n\t{0} set-forgejo-token\n\n"
|
||||
"The command is interactive; enter the new token when prompted."
|
||||
).format(cli_name)
|
||||
raise rpkgError(base_error_msg.format(rv_error))
|
||||
|
||||
return '{0}/releng/fedora-scm-requests/issue/{1}'.format(
|
||||
url.rstrip('/'), rv.json()['issue']['id'])
|
||||
return "{0}/releng/fedora-scm-requests/issues/{1}".format(
|
||||
url.rstrip("/"), rv_json["number"]
|
||||
)
|
||||
|
||||
|
||||
def do_fork(logger, base_url, token, repo_name, namespace, cli_name):
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ url = https://bodhi.stg.example.com
|
|||
[fedpkg-stage.bugzilla]
|
||||
url = https://bugzilla.stg.example.com
|
||||
|
||||
[fedpkg-stage.pagure]
|
||||
url = https://pagure.stg.example.com/
|
||||
[fedpkg-stage.forgejo]
|
||||
url = https://forge.stg.example.com/
|
||||
token = TOKEN
|
||||
|
||||
[fedpkg-stage.distgit]
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ url = https://bodhi.example.org
|
|||
[fedpkg.bugzilla]
|
||||
url = https://bugzilla.example.com
|
||||
|
||||
[fedpkg.pagure]
|
||||
url = https://pagure.example.com/
|
||||
[fedpkg.forgejo]
|
||||
url = https://forge.example.com/
|
||||
|
||||
[fedpkg.distgit]
|
||||
apibaseurl = https://src.example.com
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
[fedpkg-stage.pagure]
|
||||
[fedpkg-stage.forgejo]
|
||||
token = iamnotsecret
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
[fedpkg.pagure]
|
||||
[fedpkg.forgejo]
|
||||
token = iamnotsecret
|
||||
|
|
|
|||
419
test/test_cli.py
419
test/test_cli.py
|
|
@ -529,7 +529,7 @@ class TestRequestRepo(CliTestCase):
|
|||
mock_bz.getbug.return_value = self.mock_bug
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
fedpkg.cli.does_package_exist_in_anitya = Mock(return_value=True)
|
||||
|
||||
|
|
@ -557,11 +557,11 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
|
|
@ -571,7 +571,7 @@ class TestRequestRepo(CliTestCase):
|
|||
mock_bz.getbug.return_value = self.mock_bug
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
fedpkg.cli.does_package_exist_in_anitya = Mock(return_value=True)
|
||||
|
||||
|
|
@ -600,11 +600,11 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
|
|
@ -616,7 +616,7 @@ class TestRequestRepo(CliTestCase):
|
|||
mock_bz.getbug.return_value = self.mock_bug
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
fedpkg.cli.does_package_exist_in_anitya = Mock(return_value=True)
|
||||
|
||||
|
|
@ -644,11 +644,11 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
|
|
@ -660,7 +660,7 @@ class TestRequestRepo(CliTestCase):
|
|||
mock_bz.getbug.return_value = self.mock_bug
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
fedpkg.cli.does_package_exist_in_anitya = Mock(return_value=True)
|
||||
|
||||
|
|
@ -691,11 +691,11 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
|
|
@ -706,7 +706,7 @@ class TestRequestRepo(CliTestCase):
|
|||
mock_bz.getbug.return_value = self.mock_bug
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
|
|
@ -732,11 +732,11 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
|
|
@ -745,7 +745,7 @@ class TestRequestRepo(CliTestCase):
|
|||
"""Tests a request-repo call with the exception flag"""
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
fedpkg.cli.does_package_exist_in_anitya = Mock(return_value=True)
|
||||
|
||||
|
|
@ -773,11 +773,11 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
# Since it is an exception, Bugzilla will not have been queried
|
||||
mock_bz.getbug.assert_not_called()
|
||||
|
|
@ -791,7 +791,7 @@ class TestRequestRepo(CliTestCase):
|
|||
mock_bz.getbug.return_value = self.mock_bug
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
fedpkg.cli.does_package_exist_in_anitya = Mock(return_value=False)
|
||||
|
||||
|
|
@ -948,22 +948,22 @@ class TestRequestRepo(CliTestCase):
|
|||
self.assertEqual(str(error), expected_error)
|
||||
|
||||
@patch('requests.post')
|
||||
def test_request_repo_pagure_error(self, mock_request_post, mock_bz):
|
||||
"""Tests a standard request-repo call when the Pagure API call fails"""
|
||||
def test_request_repo_forgejo_error(self, mock_request_post, mock_bz):
|
||||
"""Tests a standard request-repo call when the Forgejo API call fails"""
|
||||
mock_bz.getbug.return_value = self.mock_bug
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
'request-repo', 'nethack', '1441813']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = False
|
||||
mock_rv.json.return_value = {'error': 'some error'}
|
||||
mock_rv.json.return_value = {'message': 'some error'}
|
||||
mock_request_post.return_value = mock_rv
|
||||
try:
|
||||
cli.request_repo()
|
||||
assert False, 'rpkgError not raised'
|
||||
except rpkgError as error:
|
||||
expected_error = ('The following error occurred while creating a '
|
||||
'new issue in Pagure: some error')
|
||||
'new issue in Forgejo: some error')
|
||||
self.assertEqual(str(error), expected_error)
|
||||
|
||||
def test_request_repo_no_bug(self, mock_bz):
|
||||
|
|
@ -995,7 +995,7 @@ class TestRequestRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertIn('initial_commit', actual_issue_content)
|
||||
self.assertFalse(actual_issue_content['initial_commit'])
|
||||
|
||||
|
|
@ -1030,7 +1030,7 @@ class TestRequestBranch(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
# Checkout the f27 branch
|
||||
|
|
@ -1053,11 +1053,11 @@ class TestRequestBranch(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.get')
|
||||
|
|
@ -1103,7 +1103,7 @@ class TestRequestBranch(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
|
|
@ -1123,11 +1123,11 @@ class TestRequestBranch(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.get')
|
||||
|
|
@ -1142,7 +1142,7 @@ class TestRequestBranch(CliTestCase):
|
|||
'epel': ['el6', 'epel7', 'epel8']}
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
mock_rv = Mock()
|
||||
|
|
@ -1171,12 +1171,12 @@ class TestRequestBranch(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.get')
|
||||
|
|
@ -1195,7 +1195,7 @@ class TestRequestBranch(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
|
|
@ -1214,11 +1214,11 @@ class TestRequestBranch(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.get')
|
||||
|
|
@ -1237,7 +1237,7 @@ class TestRequestBranch(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
cli = self.get_cli(cli_cmd)
|
||||
|
|
@ -1253,11 +1253,11 @@ class TestRequestBranch(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
|
|
@ -1300,7 +1300,7 @@ class TestRequestBranch(CliTestCase):
|
|||
for idx in range(2, 5):
|
||||
mock_rv_post = Mock()
|
||||
mock_rv_post.ok = True
|
||||
mock_rv_post.json.return_value = {'issue': {'id': idx}}
|
||||
mock_rv_post.json.return_value = {'number': idx}
|
||||
responses.append(mock_rv_post)
|
||||
mock_request_post.side_effect = responses
|
||||
|
||||
|
|
@ -1316,12 +1316,12 @@ class TestRequestBranch(CliTestCase):
|
|||
# Three bugs are filed. One for the rpm branch, and one for a new
|
||||
# module repo, and one for the matching module branch.
|
||||
expected_output = (
|
||||
'https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2\n'
|
||||
'https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/3\n'
|
||||
'https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/4'
|
||||
'https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2\n'
|
||||
'https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/3\n'
|
||||
'https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/4'
|
||||
)
|
||||
self.assertMultiLineEqual(output, expected_output)
|
||||
|
||||
|
|
@ -1339,7 +1339,7 @@ class TestRequestBranch(CliTestCase):
|
|||
}
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertDictEqual(expected_issue_content, actual_issue_content)
|
||||
|
||||
# Check for the module repo request..
|
||||
|
|
@ -1359,7 +1359,7 @@ class TestRequestBranch(CliTestCase):
|
|||
}
|
||||
post_data = mock_request_post.call_args_list[1][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertDictEqual(expected_issue_content, actual_issue_content)
|
||||
|
||||
# Check for module branch..
|
||||
|
|
@ -1376,7 +1376,7 @@ class TestRequestBranch(CliTestCase):
|
|||
}
|
||||
post_data = mock_request_post.call_args_list[2][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertDictEqual(expected_issue_content, actual_issue_content)
|
||||
|
||||
@patch('requests.get')
|
||||
|
|
@ -1400,7 +1400,7 @@ class TestRequestBranch(CliTestCase):
|
|||
for i in range(1, 4):
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': i}}
|
||||
mock_rv.json.return_value = {'number': i}
|
||||
post_side_effect.append(mock_rv)
|
||||
mock_request_post.side_effect = post_side_effect
|
||||
|
||||
|
|
@ -1422,14 +1422,14 @@ class TestRequestBranch(CliTestCase):
|
|||
}
|
||||
post_data = mock_request_post.call_args_list[i][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = """\
|
||||
https://pagure.stg.example.com/releng/fedora-scm-requests/issue/1
|
||||
https://pagure.stg.example.com/releng/fedora-scm-requests/issue/2
|
||||
https://pagure.stg.example.com/releng/fedora-scm-requests/issue/3"""
|
||||
https://forge.stg.example.com/releng/fedora-scm-requests/issues/1
|
||||
https://forge.stg.example.com/releng/fedora-scm-requests/issues/2
|
||||
https://forge.stg.example.com/releng/fedora-scm-requests/issues/3"""
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
def test_request_branch_invalid_use_of_all_releases(self):
|
||||
|
|
@ -1591,7 +1591,7 @@ https://pagure.stg.example.com/releng/fedora-scm-requests/issue/3"""
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 2}}
|
||||
mock_rv.json.return_value = {'number': 2}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
|
|
@ -1609,11 +1609,11 @@ https://pagure.stg.example.com/releng/fedora-scm-requests/issue/3"""
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/2')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
|
||||
|
|
@ -1645,7 +1645,7 @@ class TestRequestTestsRepo(CliTestCase):
|
|||
# mock the request.post to Pagure
|
||||
mock_post_rv = Mock()
|
||||
mock_post_rv.ok = True
|
||||
mock_post_rv.json.return_value = {'issue': {'id': 1}}
|
||||
mock_post_rv.json.return_value = {'number': 1}
|
||||
mock_request_post.return_value = mock_post_rv
|
||||
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
|
|
@ -1671,12 +1671,12 @@ class TestRequestTestsRepo(CliTestCase):
|
|||
# Get the data that was submitted to Pagure
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/1')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/1')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.get')
|
||||
|
|
@ -2492,123 +2492,206 @@ class TestRetire(CliTestCase):
|
|||
self.retire_release("epel8", None)
|
||||
|
||||
|
||||
class TestSetToken(CliTestCase):
|
||||
class TestSetForgejoToken(CliTestCase):
|
||||
"""
|
||||
Test the set-x-token cli command. Pagure / Distgit have the same tests.
|
||||
Test the set-forgejo-token cli command.
|
||||
Forgejo tokens are 40-character lowercase hex (SHA1 format).
|
||||
"""
|
||||
|
||||
def get_cli(self, cli_cmd, name='fedpkg', cfg=None):
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
return self.new_cli(name=name, cfg=cfg)
|
||||
|
||||
# Test: using lowercase characters rather than upper-case.
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_mixed_lowercase_numerical(self, mock_getpass):
|
||||
def test_token_input_mixed_uppercase_numerical_rejected(self, mock_getpass,
|
||||
mock_write):
|
||||
"""Mixed uppercase and numerical characters should be rejected."""
|
||||
UPPERCASE_TOKEN = "".join(["A" for _ in range(40)])
|
||||
NUMERICAL_TOKEN = "".join([str(i % 10) for i in range(40)])
|
||||
|
||||
LOWERCASE_TOKEN = "".join(["x" for _ in range(64)])
|
||||
NUMERICAL_TOKEN = "".join([str(i % 10) for i in range(64)])
|
||||
MIXED_UPPERCASE_NUMERICAL_TOKEN = ""
|
||||
for i in range(20):
|
||||
MIXED_UPPERCASE_NUMERICAL_TOKEN += UPPERCASE_TOKEN[i]
|
||||
MIXED_UPPERCASE_NUMERICAL_TOKEN += NUMERICAL_TOKEN[i]
|
||||
mock_getpass.return_value = MIXED_UPPERCASE_NUMERICAL_TOKEN
|
||||
|
||||
MIXED_LOWERCASE_NUMERICAL_TOKEN = ""
|
||||
for i in range(32):
|
||||
MIXED_LOWERCASE_NUMERICAL_TOKEN += LOWERCASE_TOKEN[i]
|
||||
MIXED_LOWERCASE_NUMERICAL_TOKEN += NUMERICAL_TOKEN[i]
|
||||
mock_getpass.return_value = MIXED_LOWERCASE_NUMERICAL_TOKEN
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-pagure-token']
|
||||
cli_cmd = ['fedpkg', 'set-forgejo-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
|
||||
try:
|
||||
cli.set_pagure_token()
|
||||
except rpkgError as error:
|
||||
expected_error = "ERROR: Token is not properly formatted."
|
||||
self.assertEqual(error, expected_error)
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
# Test: no input, none input.
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_none(self, mock_getpass):
|
||||
|
||||
cli_cmd = ["fedpkg", "set-pagure-token"]
|
||||
def test_token_input_none(self, mock_getpass, mock_write):
|
||||
"""None input should be rejected."""
|
||||
cli_cmd = ["fedpkg", "set-forgejo-token"]
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = None
|
||||
|
||||
try:
|
||||
cli.set_pagure_token()
|
||||
except rpkgError as error:
|
||||
expected_error = "ERROR: No input."
|
||||
self.assertEqual(error, expected_error)
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
"""
|
||||
EXAMPLE:
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
'--name', 'nethack', 'request-branch', 'f27',
|
||||
'--all-releases']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
expected_error = \
|
||||
'You cannot specify a branch with the "--all-releases" option'
|
||||
try:
|
||||
cli.request_branch()
|
||||
assert False, 'rpkgError not raised'
|
||||
except rpkgError as error:
|
||||
self.assertEqual(str(error), expected_error)
|
||||
"""
|
||||
|
||||
# Test: input is only lowercase.
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_lowercase(self, mock_getpass):
|
||||
|
||||
LOWERCASE_TOKEN = "".join(["x" for _ in range(64)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-pagure-token']
|
||||
def test_token_input_empty_string(self, mock_getpass, mock_write):
|
||||
"""Empty string input should be rejected."""
|
||||
cli_cmd = ["fedpkg", "set-forgejo-token"]
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = LOWERCASE_TOKEN
|
||||
mock_getpass.return_value = ""
|
||||
|
||||
try:
|
||||
cli.set_pagure_token()
|
||||
except rpkgError as error:
|
||||
expected_error = "ERROR: Token is not properly formatted."
|
||||
self.assertEqual(error, expected_error)
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_too_short(self, mock_getpass):
|
||||
def test_token_input_non_hex_rejected(self, mock_getpass, mock_write):
|
||||
"""Non-hex characters (g-z) should be rejected."""
|
||||
NON_HEX_TOKEN = "".join(["x" for _ in range(40)])
|
||||
|
||||
SHORT_TOKEN = "".join(['x' for _ in range(63)])
|
||||
cli_cmd = ['fedpkg', 'set-forgejo-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = NON_HEX_TOKEN
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-pagure-token']
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_uppercase_rejected(self, mock_getpass, mock_write):
|
||||
"""Uppercase characters should be rejected."""
|
||||
UPPERCASE_TOKEN = "".join(["A" for _ in range(40)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-forgejo-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = UPPERCASE_TOKEN
|
||||
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_too_short(self, mock_getpass, mock_write):
|
||||
"""Tokens shorter than 40 characters should be rejected."""
|
||||
SHORT_TOKEN = "".join(['a' for _ in range(39)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-forgejo-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = SHORT_TOKEN
|
||||
|
||||
try:
|
||||
cli.set_pagure_token()
|
||||
except rpkgError as error:
|
||||
expected_error = "ERROR: Token is not properly formatted."
|
||||
self.assertEqual(error, expected_error)
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_too_long(self, mock_getpass):
|
||||
def test_token_input_too_long(self, mock_getpass, mock_write):
|
||||
"""Tokens longer than 40 characters should be rejected."""
|
||||
LONG_TOKEN = "".join(['a' for _ in range(41)])
|
||||
|
||||
LONG_TOKEN = "".join(['x' for _ in range(65)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-pagure-token']
|
||||
cli_cmd = ['fedpkg', 'set-forgejo-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = LONG_TOKEN
|
||||
|
||||
try:
|
||||
cli.set_pagure_token()
|
||||
except rpkgError as error:
|
||||
expected_error = "ERROR: Token is not properly formatted."
|
||||
self.assertEqual(error, expected_error)
|
||||
cli.set_forgejo_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('getpass.getpass')
|
||||
def test_token_readable_only_by_user(self, mock_getpass):
|
||||
"""Config file with token should have restricted permissions (0600)."""
|
||||
TOKEN = "".join(['a' for _ in range(40)])
|
||||
|
||||
TOKEN = "".join(['X' for _ in range(64)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-pagure-token']
|
||||
cli_cmd = ['fedpkg', 'set-forgejo-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = TOKEN
|
||||
|
||||
old_umask = os.umask(0)
|
||||
cli.set_pagure_token()
|
||||
cli.set_forgejo_token()
|
||||
os.umask(old_umask)
|
||||
|
||||
PATH = os.path.join(os.path.expanduser('~'),
|
||||
'.config',
|
||||
'rpkg',
|
||||
'{0}.conf'.format(cli.name))
|
||||
self.assertEqual(os.stat(PATH).st_mode & 0o077, 0)
|
||||
|
||||
|
||||
class TestSetDistgitToken(CliTestCase):
|
||||
"""
|
||||
Test the set-distgit-token cli command.
|
||||
Distgit tokens are 64-character uppercase alphanumeric.
|
||||
"""
|
||||
|
||||
def get_cli(self, cli_cmd, name='fedpkg', cfg=None):
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
return self.new_cli(name=name, cfg=cfg)
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_lowercase_rejected(self, mock_getpass, mock_write):
|
||||
LOWERCASE_TOKEN = "".join(["x" for _ in range(64)])
|
||||
mock_getpass.return_value = LOWERCASE_TOKEN
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-distgit-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
|
||||
cli.set_distgit_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_none(self, mock_getpass, mock_write):
|
||||
cli_cmd = ["fedpkg", "set-distgit-token"]
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = None
|
||||
|
||||
cli.set_distgit_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_empty_string(self, mock_getpass, mock_write):
|
||||
cli_cmd = ["fedpkg", "set-distgit-token"]
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = ""
|
||||
|
||||
cli.set_distgit_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_too_short(self, mock_getpass, mock_write):
|
||||
SHORT_TOKEN = "".join(['A' for _ in range(63)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-distgit-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = SHORT_TOKEN
|
||||
|
||||
cli.set_distgit_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('configparser.ConfigParser.write')
|
||||
@patch('getpass.getpass')
|
||||
def test_token_input_too_long(self, mock_getpass, mock_write):
|
||||
LONG_TOKEN = "".join(['A' for _ in range(65)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-distgit-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = LONG_TOKEN
|
||||
|
||||
cli.set_distgit_token()
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch('getpass.getpass')
|
||||
def test_token_readable_only_by_user(self, mock_getpass):
|
||||
TOKEN = "".join(['A' for _ in range(64)])
|
||||
|
||||
cli_cmd = ['fedpkg', 'set-distgit-token']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
mock_getpass.return_value = TOKEN
|
||||
|
||||
old_umask = os.umask(0)
|
||||
cli.set_distgit_token()
|
||||
os.umask(old_umask)
|
||||
|
||||
PATH = os.path.join(os.path.expanduser('~'),
|
||||
|
|
@ -2648,7 +2731,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
commit_time = (datetime.now() - timedelta(days=1)).timestamp()
|
||||
|
|
@ -2674,11 +2757,11 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/41')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/41')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch("fedpkg.cli.get_release_branches")
|
||||
|
|
@ -2693,7 +2776,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
expected_error = (
|
||||
|
|
@ -2728,7 +2811,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
commit_time = (datetime.now() - timedelta(days=60)).timestamp()
|
||||
|
|
@ -2771,7 +2854,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
commit_time = (datetime.now() - timedelta(days=60)).timestamp()
|
||||
|
|
@ -2798,11 +2881,11 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/41')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/41')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch("fedpkg.bugzilla.BugzillaClient.get_review_bug")
|
||||
|
|
@ -2823,7 +2906,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
commit_time = (datetime.now() - timedelta(days=60)).timestamp()
|
||||
|
|
@ -2851,11 +2934,11 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/41')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/41')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch("fedpkg.cli.get_pagure_branches")
|
||||
|
|
@ -2875,7 +2958,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
commit_time = (datetime.now() - timedelta(days=1)).timestamp()
|
||||
|
|
@ -2901,11 +2984,11 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected_output = ('https://pagure.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issue/41')
|
||||
expected_output = ('https://forge.stg.example.com/releng/'
|
||||
'fedora-scm-requests/issues/41')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch("fedpkg.cli.get_pagure_branches")
|
||||
|
|
@ -2925,7 +3008,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
mock_rv = Mock()
|
||||
mock_rv.ok = True
|
||||
mock_rv.json.return_value = {'issue': {'id': 41}}
|
||||
mock_rv.json.return_value = {'number': 41}
|
||||
mock_request_post.return_value = mock_rv
|
||||
|
||||
commit_time = (datetime.now() - timedelta(days=1)).timestamp()
|
||||
|
|
@ -2951,7 +3034,7 @@ class TestRequestUnretirement(CliTestCase):
|
|||
|
||||
post_data = mock_request_post.call_args_list[0][1]['data']
|
||||
actual_issue_content = json.loads(json.loads(
|
||||
post_data)['issue_content'].strip('```'))
|
||||
post_data)['body'].strip('```'))
|
||||
self.assertEqual(expected_issue_content, actual_issue_content)
|
||||
mock_gcd.assert_called_once_with(
|
||||
'https://src.example.com', 'rpms', 'testpkg', 'f40')
|
||||
|
|
|
|||
|
|
@ -360,17 +360,18 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
|
||||
|
||||
@patch('requests.post')
|
||||
class TestNewPagureIssue(unittest.TestCase):
|
||||
"""Test new_pagure_issue"""
|
||||
class TestNewForgejoIssue(unittest.TestCase):
|
||||
"""Test new_forgejo_issue"""
|
||||
|
||||
def test_raise_error_if_connection_error(self, post):
|
||||
post.side_effect = ConnectionError
|
||||
logger = Mock()
|
||||
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The connection to Pagure failed',
|
||||
utils.new_pagure_issue,
|
||||
logger, 'http://distgit/', '123456', 'new package', {'repo': 'pkg1'}, 'fedpkg')
|
||||
rpkgError, 'The connection to Forgejo failed',
|
||||
utils.new_forgejo_issue,
|
||||
logger, 'http://forge.example.com/', '123456', 'new package',
|
||||
'{"repo": "pkg1"}', 'fedpkg')
|
||||
|
||||
def test_responses_not_ok_and_response_body_is_not_json(self, post):
|
||||
rv = Mock(ok=False, text='error')
|
||||
|
|
@ -380,53 +381,45 @@ class TestNewPagureIssue(unittest.TestCase):
|
|||
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
'The following error occurred while creating a new issue',
|
||||
utils.new_pagure_issue,
|
||||
logger, 'http://distgit/', '123456', 'new package', {'repo': 'pkg1'}, 'fedpkg')
|
||||
'The following error occurred while creating a new issue in Forgejo',
|
||||
utils.new_forgejo_issue,
|
||||
logger, 'http://forge.example.com/', '123456', 'new package',
|
||||
'{"repo": "pkg1"}', 'fedpkg')
|
||||
|
||||
def test_responses_not_ok_when_token_is_expired(self, post):
|
||||
rv = Mock(
|
||||
ok=False,
|
||||
text='Invalid or expired token. Please visit '
|
||||
'https://pagure.io/settings#api-keys to get or renew your API token.')
|
||||
rv.json.side_effect = ValueError
|
||||
def test_responses_not_ok_when_token_is_invalid(self, post):
|
||||
rv = Mock(ok=False)
|
||||
rv.json.return_value = {'message': 'token is required'}
|
||||
post.return_value = rv
|
||||
logger = Mock()
|
||||
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
'\nFor invalid or expired tokens please '
|
||||
'set a new token in your user configuration by running:'
|
||||
'\n\n\tfedpkg set-pagure-token\n\n'
|
||||
'The command is interactive; enter the new token when prompted.',
|
||||
utils.new_pagure_issue,
|
||||
logger, 'http://distgit/', '123456', 'new package', {'repo': 'pkg1'}, 'fedpkg')
|
||||
'Please set a valid token in your user configuration',
|
||||
utils.new_forgejo_issue,
|
||||
logger, 'http://forge.example.com/', '123456', 'new package',
|
||||
'{"repo": "pkg1"}', 'fedpkg')
|
||||
|
||||
def test_create_pagure_issue(self, post):
|
||||
def test_create_forgejo_issue(self, post):
|
||||
rv = Mock(ok=True)
|
||||
rv.json.return_value = {'issue': {'id': 1}}
|
||||
rv.json.return_value = {'number': 42}
|
||||
post.return_value = rv
|
||||
logger = Mock()
|
||||
|
||||
pagure_api_url = 'http://distgit'
|
||||
issue_ticket_body = {'repo': 'pkg1'}
|
||||
forgejo_url = 'http://forge.example.com'
|
||||
issue_ticket_body = '{"repo": "pkg1"}'
|
||||
|
||||
issue_url = utils.new_pagure_issue(logger,
|
||||
pagure_api_url,
|
||||
'123456',
|
||||
'new package',
|
||||
issue_ticket_body,
|
||||
'fedpkg',)
|
||||
issue_url = utils.new_forgejo_issue(logger,
|
||||
forgejo_url,
|
||||
'123456',
|
||||
'new package',
|
||||
issue_ticket_body,
|
||||
'fedpkg')
|
||||
|
||||
expected_issue_url = (
|
||||
'{0}/releng/fedora-scm-requests/issue/1'
|
||||
.format(pagure_api_url)
|
||||
)
|
||||
expected_issue_url = '{0}/releng/fedora-scm-requests/issues/42'.format(forgejo_url)
|
||||
self.assertEqual(expected_issue_url, issue_url)
|
||||
|
||||
post.assert_called_once_with(
|
||||
'{0}/api/0/releng/fedora-scm-requests/new_issue'
|
||||
.format(pagure_api_url),
|
||||
'{0}/api/v1/repos/releng/fedora-scm-requests/issues'.format(forgejo_url),
|
||||
headers={
|
||||
'Authorization': 'token {0}'.format(123456),
|
||||
'Accept': 'application/json',
|
||||
|
|
@ -434,7 +427,7 @@ class TestNewPagureIssue(unittest.TestCase):
|
|||
},
|
||||
data=json.dumps({
|
||||
'title': 'new package',
|
||||
'issue_content': issue_ticket_body,
|
||||
'body': issue_ticket_body,
|
||||
}),
|
||||
timeout=60
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue