-
Notifications
You must be signed in to change notification settings - Fork 206
Fix #3655: Allow dots (.), hyphens (-), and underscores (_) in GitHub usernames #3658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nisarg908
wants to merge
8
commits into
nf-core:dev
Choose a base branch
from
Nisarg908:main
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4899003
Fix #3655: allowed dots, hyphens, and underscores in GitHub usernames…
Nisarg908 ffe8f46
Fix #3655: updated CHANGELOG.md
Nisarg908 55d2210
Fix #3655: updated CHANGELOG.md-2
Nisarg908 799b97e
Merge branch 'dev' into main
Nisarg908 c4262d6
Fix #3655: feat: add username validation tests and logic to skip stri…
Nisarg908 ada8dda
Merge branch 'main' of https://github.com/Nisarg908/nf-core_tools int…
Nisarg908 ef238c4
Fix #3655: Changed repo_url reference and added test function in test…
Nisarg908 e2c698e
Merge branch 'dev' into main
Nisarg908 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,16 +430,41 @@ def _get_username(self): | |
author_default = f"@{gh_auth_user['login']}" | ||
except Exception as e: | ||
log.debug(f"Could not find GitHub username using 'gh' cli command: [red]{e}") | ||
# Determine whether this repo is hosted on GitHub | ||
repo_url = ( | ||
getattr(self.modules_repo, "remote_url", None) | ||
or getattr(self.wf.dir, "git_origin_url", "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't thing |
||
or "" | ||
) | ||
is_github = "github.com" in repo_url.lower() | ||
|
||
# Regex to valid GitHub username: https://github.com/shinnn/github-username-regex | ||
github_username_regex = re.compile(r"^@[a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d])){0,38}$") | ||
while self.author is None or not github_username_regex.match(self.author): | ||
if self.author is not None and not github_username_regex.match(self.author): | ||
log.warning("Does not look like a valid GitHub username (must start with an '@')!") | ||
self.author = rich.prompt.Prompt.ask( | ||
f"[violet]GitHub Username:[/]{' (@author)' if author_default is None else ''}", | ||
default=author_default, | ||
) | ||
username_regex = re.compile( | ||
r"^@[A-Za-z\d](?:[A-Za-z\d]|[._-](?=[A-Za-z\d])){0,38}$" | ||
) | ||
|
||
while True: | ||
if self.author is None: | ||
self.author = rich.prompt.Prompt.ask( | ||
f"[violet]GitHub Username:[/]" | ||
f"{' (@author)' if author_default is None else ''}", | ||
default=author_default, | ||
) | ||
|
||
if is_github: | ||
valid = bool(username_regex.match(self.author)) | ||
warn = ( | ||
"Invalid GitHub username—must start with '@' and use only " | ||
"letters, numbers, '.', '_', or '-'" | ||
) | ||
else: | ||
valid = self.author.startswith("@") and len(self.author) > 1 | ||
warn = "Invalid username—must start with '@'" | ||
|
||
if valid: | ||
break | ||
|
||
log.warning(warn) | ||
self.author = None | ||
|
||
def _copy_old_files(self, component_old_path): | ||
"""Copy files from old module to new module""" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,49 @@ def test_modules_migrate_symlink(self, mock_rich_ask): | |
# Check that symlink is deleted | ||
assert not symlink_file.is_symlink() | ||
|
||
@pytest.mark.parametrize("origin_url, username, should_pass", [ | ||
# GitHub uses strict regex | ||
("git@github.com:nf-core/tools.git", "@john.doe", True), | ||
("https://github.com/foo/bar.git", "@foo_bar-1", True), | ||
("https://github.com/foo/bar.git", "@foo@bar", False), | ||
# Non-GitHub is more relaxed | ||
("git@gitlab.com:john.doe/proj.git", "@anything", True), | ||
("ssh://gitea.example/user", "@user.name", True), | ||
("ssh://gitlab.com/user", "user.name", False), | ||
]) | ||
def test_username_validation(self, origin_url, username, should_pass, monkeypatch): | ||
"""Test GitHub username validation in _get_username logic""" | ||
|
||
class DummyWF: | ||
def __init__(self, origin_url): | ||
self.config = {} | ||
self.dir = type("Dir", (), {"git_origin_url": origin_url}) | ||
|
||
class FakeModulesRepo: | ||
no_pull_global = False | ||
def __init__(self, *args, **kwargs): | ||
pass | ||
Comment on lines
+180
to
+188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see |
||
|
||
# Stub out all dependencies | ||
monkeypatch.setattr(nf_core.utils, "run_cmd", lambda *a, **k: (b"", b"")) | ||
monkeypatch.setattr(nf_core.modules.modules_repo, "ModulesRepo", FakeModulesRepo) | ||
monkeypatch.setattr(nf_core.components.components_utils, "get_repo_info", lambda d, p: (d, "pipeline", "org")) | ||
|
||
# Create minimal ComponentCreate object | ||
wf = DummyWF(origin_url) | ||
cc = object.__new__(nf_core.components.create.ComponentCreate) | ||
cc.wf = wf | ||
cc.author = None | ||
|
||
if should_pass: | ||
monkeypatch.setattr("rich.prompt.Prompt.ask", lambda *a, **k: username) | ||
cc._get_username() | ||
assert cc.author == username | ||
else: | ||
monkeypatch.setattr("rich.prompt.Prompt.ask", lambda *a, **k: (_ for _ in ()).throw(SystemExit())) | ||
with pytest.raises(SystemExit): | ||
cc._get_username() | ||
|
||
def test_modules_meta_yml_structure_biotools_meta(self): | ||
"""Test the structure of the module meta.yml file when it was generated with INFORMATION from bio.tools and WITH a meta.""" | ||
with responses.RequestsMock() as rsps: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.