Skip to content
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

PSCE-408 refactor: replaces regex with urllib for repo URL parsing #215

Merged
merged 3 commits into from
May 7, 2024

Conversation

jpower432
Copy link
Contributor

@jpower432 jpower432 commented Apr 26, 2024

Description

In GitProvider class and concrete implementations, move any repo url string parsing to urllib and only use regex for path pattern matching and capturing. Also removes regex related code smell.

Prep for #200

Type of change

  • Bug fix (non-breaking change which fixes an issue) (Refactor)

How has this been tested?

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Using a dedicated library for url parsing is generally less error
prone and easier to maintain

Signed-off-by: Jennifer Power <[email protected]>
@jpower432 jpower432 added the maintenance Maintenance tasks and refactors label Apr 26, 2024
Resolves type errors in python 3.8

Signed-off-by: Jennifer Power <[email protected]>
@jpower432 jpower432 added this to the 0.10.0 milestone Apr 30, 2024
@jpower432 jpower432 changed the title refactor: replaces regex with urllib for repo URL parsing PSCE-408 refactor: replaces regex with urllib for repo URL parsing May 3, 2024
@jpower432 jpower432 marked this pull request as ready for review May 6, 2024 14:15
@jpower432 jpower432 requested review from a team and gvauter May 6, 2024 14:15
Copy link
Member

@gvauter gvauter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes look good and local testing passed 👍

def match_url(self, repo_url: str) -> Tuple[Optional[re.Match[str]], str]:
"""Match a repository URL with the pattern"""
parsed_url: ParseResult = urlparse(repo_url)
scheme = parsed_url.scheme
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit-pick comment so feel free to ignore. These could be summarized to reduce verbosity. Ex:

if host := parsed_url.hostname:
    stripped_url = f"{host}{path}"
if scheme := parsed_url.scheme:
    stripped_url = f"{scheme}://{stripped_url}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gvauter. I will apply this.

@jpower432 jpower432 merged commit 87242b9 into main May 7, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance tasks and refactors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants