Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,22 @@ you should be able to call the executable, like so:
``howfairis`` supports URLs from the following code repository platforms:

1. ``https://github.com``
2. ``https://gitlab.com`` (not including self-hosted instances)
2. ``https://gitlab.com``
3. self-hosted GitLab instances

Self-hosted GitLab instances will rely on the required features being supported,
expect errors if this is not the case.

Docker
---------------

You can run howfairis Docker image using the command below.
There is a howfairis Docker image that can be obtrained using the command below.

.. code:: console

docker pull fairsoftware/howfairis

You can run howfairis Docker image using the command below.
You can then run the howfairis Docker image using the command below.

.. code:: console

Expand Down Expand Up @@ -242,7 +246,10 @@ Which then shows something like:

* https://github.com

* https://gitlab.com (not including any self-hosted instances)
* https://gitlab.com

* a self-hosted GitLab instance (provided the required features are
supported, expect errors)

Options:
-b, --branch TEXT Which git branch to use. Also accepts other
Expand All @@ -258,6 +265,11 @@ Which then shows something like:
-i, --ignore-repo-config Ignore any configuration files on the
remote.

-s, --self-hosted Use a self-hosted GitLab instance, guessing
the FQDN to use. This may not work,
depending on the server version. Expect
errors if unsupported features are requried.

-p, --path TEXT Relative path (on the remote). Use this if
you want howfairis to look for a README and
a configuration file in a subdirectory.
Expand Down
21 changes: 14 additions & 7 deletions howfairis/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
help="Show default configuration and exit.")
@click.option("-i", "--ignore-repo-config", default=False, is_flag=True,
help="Ignore any configuration files on the remote.")
@click.option("-s", "--self-hosted", default=False, is_flag=True,
help="Use a self-hosted GitLab instance, guessing the FQDN to use. This may not work, depending on the "
"server version. Expect errors if unsupported features are requried.")
@click.option("-p", "--path", default=None, type=click.STRING,
help="Relative path (on the remote). Use this if you want howfairis to look for a "
"README and a configuration file in a subdirectory.")
Expand All @@ -40,15 +43,17 @@
@click.option("-v", "--version", default=False, is_flag=True,
help="Show version and exit.")
@click.argument("url", required=False)
def cli(url=None, branch=None, user_config_filename=None, repo_config_filename=None, path=None,
def cli(url=None, branch=None, user_config_filename=None, repo_config_filename=None, self_hosted=False, path=None,
show_trace=False, json_output=False, version=False, ignore_repo_config=False, show_default_config=False, quiet=False):

"""Determine compliance with recommendations from fair-software.eu for the repository at URL. The following
code repository platforms are supported:

* https://github.com

* https://gitlab.com (not including any self-hosted instances)
* https://gitlab.com

* a self-hosted GitLab instance (provided the required features are supported, expect errors)
"""

if show_trace is False:
Expand All @@ -66,13 +71,15 @@ def cli(url=None, branch=None, user_config_filename=None, repo_config_filename=N
quiet = True

init_terminal_colors()
repo = Repo(url, branch, path)
repo = Repo(url, branch, self_hosted, path)

print_feedback_about_repo_args(url, branch, path, is_quiet=quiet)
print_feedback_about_config_args(ignore_repo_config, repo_config_filename, user_config_filename, is_quiet=quiet)
print_feedback_about_repo_args(url, branch, self_hosted, path, is_quiet=quiet)
print_feedback_about_config_args(ignore_repo_config, repo_config_filename,
user_config_filename, is_quiet=quiet)

checker = Checker(repo, user_config_filename=user_config_filename, repo_config_filename=repo_config_filename,
ignore_repo_config=ignore_repo_config, is_quiet=quiet)
checker = Checker(repo, user_config_filename=user_config_filename,
repo_config_filename=repo_config_filename,
ignore_repo_config=ignore_repo_config, is_quiet=quiet)

previous_compliance = checker.readme.get_compliance()
current_compliance = checker.check_five_recommendations()
Expand Down
5 changes: 4 additions & 1 deletion howfairis/cli/print_feedback_about_repo_args.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def print_feedback_about_repo_args(url, branch, path, is_quiet=False):
def print_feedback_about_repo_args(url, branch, self_hosted, path, is_quiet=False):
""" """

assert url is not None, "Expected URL to not be emtpy."
Expand All @@ -9,6 +9,9 @@ def print_feedback_about_repo_args(url, branch, path, is_quiet=False):
if url is not None:
print("url: " + url)

if self_hosted:
print("using self-hosted instance")

if branch is not None:
print("branch: " + branch)

Expand Down
2 changes: 1 addition & 1 deletion howfairis/mixins/license_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def has_license(self):
result = True

if self.repo.platform == Platform.GITLAB:
url = f"https://gitlab.com/{self.repo.owner}/{self.repo.repo}"
url = f"https://{self.repo.instance}/{self.repo.owner}/{self.repo.repo}"

try:
response = get_from_platform(
Expand Down
38 changes: 25 additions & 13 deletions howfairis/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class Repo:
url: URL of a code repository such as https://github.com/fair-software/howfairis
branch: Branch to checkout. Defaults to default branch of the repository.
Can also be a commit SHA-1 hash or tag.
self_hosted: Flag if self-hosted GitLab instance such as my.gitlab.tld is used
path: Path inside repository. Defaults to root.

Attributes:
url (str): URL of a code repository,
branch (str, None): Branch to checkout. If None then :attr:`Repo.default_branch` will be used.
instance (str): FQDN of a self-hosted GitLab instance. 'gitlab.com' by default.
path (str): Path inside repository.
platform (.code_repository_platforms.Platform): Detected code repository platform of repo.
owner (str): Owner of the repo.
Expand All @@ -34,15 +36,18 @@ class Repo:

# pylint: disable=too-many-instance-attributes
def __init__(
self, url: str, branch: Optional[str] = None, path: Optional[str] = None
self, url: str, branch: Optional[str] = None,
self_hosted: Optional[bool] = False,
path: Optional[str] = None
):

# run assertions on user input
Repo._check_assertions(url)
Repo._check_assertions(url, self_hosted)

# assign arguments to instance members
self.url = url
self.branch = branch
self.instance = "gitlab.com" if not self_hosted else urlparse(url).netloc
self.path = "" if path is None else "/" + path.strip("/")

# assign remaining members as needed
Expand All @@ -55,21 +60,28 @@ def __init__(
self.reuse_url = self._derive_reuse_url()

@staticmethod
def _check_assertions(url):
def _check_assertions(url, self_hosted):
assert url.startswith("https://"), "url should start with https://"
assert True in [
url.startswith("https://github.com"),
url.startswith("https://gitlab.com"),
], "Repository should be on github.com or on gitlab.com."
assert re.search(
"^https://git(hub|lab).com/[^/]+/[^/]+", url
if self_hosted:
assert False in [
url.startswith("https://github.com"),
url.startswith("https://gitlab.com"),
], f"Repository should be on self-hosted GitLab."
else:
assert True in [
url.startswith("https://github.com"),
url.startswith(f"https://gitlab.com"),
], f"Repository should be on github.com or on gitlab.com."
assert (
re.search("^https://git(hub|lab).com/[^/]+/[^/]+", url) or
re.search("^https://"+urlparse(url).netloc+"/[^/]+/[^/]+", url)
), "url is not a repository"

def _derive_api(self):
if self.platform == Platform.GITHUB:
api = f"https://api.github.com/repos/{self.owner}/{self.repo}"
elif self.platform == Platform.GITLAB:
api = f"https://gitlab.com/api/v4/projects/{self.owner}%2F{self.repo}"
api = f"https://{self.instance}/api/v4/projects/{self.owner}%2F{self.repo}"
return api

def _derive_reuse_url(self):
Expand All @@ -89,7 +101,7 @@ def _derive_owner_and_repo(self):
elif self.platform == Platform.GITLAB:
try:
owner, repo = (
self.url.replace("https://gitlab.com", "").strip("/").split("/")[:2]
self.url.replace(f"https://{self.instance}", "").strip("/").split("/")[:2]
)
except ValueError as ex:
raise ValueError("Bad value for input argument URL.") from ex
Expand All @@ -103,7 +115,7 @@ def _derive_platform(self):
if self.url.startswith("https://github.com"):
return Platform.GITHUB

if self.url.startswith("https://gitlab.com"):
if self.url.startswith(f"https://{self.instance}"):
return Platform.GITLAB

return None
Expand All @@ -122,7 +134,7 @@ def _derive_raw_url_format_string(self):
)

elif self.platform == Platform.GITLAB:
raw_url_format_string = f"https://gitlab.com/{self.owner}/{self.repo}/-/raw/{branch}{self.path}/{{0}}"
raw_url_format_string = f"https://{self.instance}/{self.owner}/{self.repo}/-/raw/{branch}{self.path}/{{0}}"

return raw_url_format_string

Expand Down