-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): validate a repositories existance
- Loading branch information
Showing
4 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
from django.core.validators import RegexValidator | ||
from subprocess import run | ||
|
||
from django.core.validators import RegexValidator, ValidationError | ||
from django.utils.deconstruct import deconstructible | ||
|
||
|
||
@deconstructible | ||
class RepositoryURLValidator(RegexValidator): | ||
regex = r"(http[s]?)(://)([\w\.@\:/\-~]+)(\.git)" | ||
message = "Enter a valid http or https url to a git repository." | ||
|
||
|
||
def validate_repo_exists(value: str): | ||
"""Validate the existance of a remote git repository""" | ||
result = run(["git", "ls-remote", value], capture_output=True) | ||
if result.returncode != 0: | ||
raise ValidationError("Repository does not exist.", params={"value": value}) |