Skip to content

Commit

Permalink
Merge pull request #2870 from nf-core/task_1763/short_sha
Browse files Browse the repository at this point in the history
fix: adds a short sha representation to modules list command pointing to the repo specific commit
  • Loading branch information
ewels committed Mar 18, 2024
2 parents 73f0a58 + 54afd8d commit 4823fe4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
- Patch: handle file not found when it is an added file to a module ([#2771](https://github.com/nf-core/tools/pull/2771))
- Handle symlinks when migrating pytest ([#2770](https://github.com/nf-core/tools/pull/2770))
- Add `--profile` parameter to nf-test command ([#2767](https://github.com/nf-core/tools/pull/2767))
- Reduce the sha length in the `nf-core modules list local` and add links to the specific commit ([#2870](https://github.com/nf-core/tools/pull/2870))
- Add links the nf-core module page and to open the local file in VSCode for module lint results ([#2870](https://github.com/nf-core/tools/pull/2870))

### General

Expand Down
19 changes: 17 additions & 2 deletions nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import rich.box
import rich.console
import rich.panel
import rich.repr
from rich.markdown import Markdown
from rich.table import Table

Expand All @@ -31,6 +32,7 @@ class LintExceptionError(Exception):
pass


@rich.repr.auto
class LintResult:
"""An object to hold the results of a lint test"""

Expand All @@ -42,6 +44,7 @@ def __init__(self, component, lint_test, message, file_path):
self.component_name = component.component_name


@rich.repr.auto
class ComponentLint(ComponentCommand):
"""
An object for linting modules and subworkflows either in a clone of the 'nf-core/modules'
Expand Down Expand Up @@ -231,9 +234,21 @@ def format_result(test_results, table):
if last_modname and lint_result.component_name != last_modname:
even_row = not even_row
last_modname = lint_result.component_name

# If this is an nf-core module, link to the nf-core webpage
if lint_result.component.repo_url == "https://github.com/nf-core/modules.git":
module_url = "https://nf-co.re/modules/" + lint_result.component_name.replace("/", "_")
module_name = f"[link={module_url}]{lint_result.component_name}[/link]"
else:
module_name = lint_result.component_name

# Make the filename clickable to open in VSCode
file_path = os.path.relpath(lint_result.file_path, self.dir)
file_path_link = f"[link=vscode://file/{os.path.abspath(file_path)}]{file_path}[/link]"

table.add_row(
Markdown(f"{lint_result.component_name}"),
os.path.relpath(lint_result.file_path, self.dir),
module_name,
file_path_link,
Markdown(f"{lint_result.message}"),
style="dim" if even_row else None,
)
Expand Down
16 changes: 12 additions & 4 deletions nf_core/components/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def pattern_msg(keywords: List[str]) -> str:
# We have a pipeline - list what's installed
else:
# Check that we are in a pipeline directory
print(f"{self.repo_type=}")
log.info(f"Repository type: [blue]{self.repo_type}")
try:
if self.repo_type != "pipeline":
raise UserWarning(
Expand Down Expand Up @@ -125,10 +125,11 @@ def pattern_msg(keywords: List[str]) -> str:
version_sha = component_entry["git_sha"]
try:
# pass repo_name to get info on modules even outside nf-core/modules
message, date = ModulesRepo(
module = ModulesRepo(
remote_url=repo_url,
branch=component_entry["branch"],
).get_commit_info(version_sha)
)
message, date = module.get_commit_info(version_sha)
except LookupError as e:
log.warning(e)
date = "[red]Not Available"
Expand All @@ -140,7 +141,14 @@ def pattern_msg(keywords: List[str]) -> str:
version_sha = "[red]Not Available"
date = "[red]Not Available"
message = "[red]Not Available"
table.add_row(component, repo_url, version_sha, message, date)
nice_repo_name = repo_url.replace("https://github.com/", "").replace(".git", "")
table.add_row(
component,
f"[link={repo_url}]{nice_repo_name}[/link]",
f"[link={module.gitless_repo()}/commit/{version_sha}]{version_sha[:7]}[/link]",
message,
date,
)
components.append(component)

if print_json:
Expand Down
6 changes: 6 additions & 0 deletions nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def __init__(self, remote_url=None, branch=None, no_pull=False, hide_progress=Fa

self.avail_module_names = None

def gitless_repo(self):
gitless_repo_url = self.remote_url
if self.remote_url and ".git" in self.remote_url:
gitless_repo_url = gitless_repo_url[:-4]
return gitless_repo_url

def setup_local_repo(self, remote, branch, hide_progress=True, in_cache=False):
"""
Sets up the local git repository. If the repository has been cloned previously, it
Expand Down

0 comments on commit 4823fe4

Please sign in to comment.