| |
@@ -30,7 +30,8 @@
|
| |
:param repo_name: a string of the repository name
|
| |
:param namespace: a string determines a type of the repository
|
| |
:param cli_name: string of the CLI's name (e.g. centpkg)
|
| |
- :return: a bool; True when fork was created, False when already exists
|
| |
+ :return: a tuple consisting of whether the fork needed to be created (bool)
|
| |
+ and the fork path (string)
|
| |
"""
|
| |
api_url = '{0}/api/v4'.format(base_url.rstrip('/'))
|
| |
project_id = quote_plus("redhat/centos-stream/{0}/{1}".format(namespace, repo_name))
|
| |
@@ -58,7 +59,7 @@
|
| |
try:
|
| |
# Extract response json for debugging
|
| |
rv_json = rv.json()
|
| |
- logger.debug("Pagure API response: '{0}'".format(rv_json))
|
| |
+ logger.debug("GitLab API response: '{0}'".format(rv_json))
|
| |
except Exception:
|
| |
pass
|
| |
|
| |
@@ -66,7 +67,12 @@
|
| |
if not rv.ok:
|
| |
# fork was already created
|
| |
if rv.status_code == 409 or rv.reason == "Conflict":
|
| |
- return False
|
| |
+ # When the repo already exists, the return doesn't contain the repo
|
| |
+ # path or username. Make one more API call to get the username of
|
| |
+ # the token to construct the repo path.
|
| |
+ rv = requests.get('{0}/user'.format(api_url), headers=headers)
|
| |
+ username = rv.json()['username']
|
| |
+ return False, '{0}/{1}'.format(username, safe_name)
|
| |
# show hint for invalid, expired or revoked token
|
| |
elif rv.status_code == 401 or rv.reason == "Unauthorized":
|
| |
base_error_msg += '\nFor invalid or expired token refer to ' \
|
| |
@@ -74,38 +80,33 @@
|
| |
'configuration.'.format(cli_name)
|
| |
raise rpkgError(base_error_msg.format(rv.text))
|
| |
|
| |
- return True
|
| |
+ return True, rv_json['path_with_namespace']
|
| |
|
| |
|
| |
- def do_add_remote(base_url, remote_base_url, username, repo, repo_name,
|
| |
- namespace):
|
| |
+ def do_add_remote(base_url, remote_base_url, repo, repo_path, remote_name):
|
| |
"""
|
| |
Adds remote tracked repository
|
| |
:param base_url: a string of the URL repository
|
| |
:param remote_base_url: a string of the remote tracked repository
|
| |
- :param username: a string of the (FAS) user name
|
| |
:param repo: object, current project git repository
|
| |
- :param repo_name: a string of the repository name
|
| |
- :param namespace: a string determines a type of the repository
|
| |
+ :param repo_path: a string of the repository path
|
| |
+ :param remote_name: a string of the remote name
|
| |
:return: a bool; True if remote was created, False when already exists
|
| |
"""
|
| |
parsed_url = urlparse(remote_base_url)
|
| |
- remote_url = '{0}://{1}/{2}/centos_{3}_{4}.git'.format(
|
| |
+ remote_url = '{0}://{1}/{2}.git'.format(
|
| |
parsed_url.scheme,
|
| |
parsed_url.netloc,
|
| |
- username,
|
| |
- namespace,
|
| |
- repo_name,
|
| |
+ repo_path,
|
| |
)
|
| |
|
| |
# check already existing remote
|
| |
for remote in repo.remotes:
|
| |
- if remote.name == username:
|
| |
+ if remote.name == remote_name:
|
| |
return False
|
| |
|
| |
try:
|
| |
- # create remote with username as its name
|
| |
- repo.create_remote(username, url=remote_url)
|
| |
+ repo.create_remote(remote_name, url=remote_url)
|
| |
except git.exc.GitCommandError as e:
|
| |
error_msg = "During create remote:\n {0}\n {1}".format(
|
| |
" ".join(e.command), e.stderr)
|
| |