-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Added nest app and slack command for sponsorship #947
base: main
Are you sure you want to change the base?
Conversation
07f5706
to
e7f54b1
Compare
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.
It looks good but needs to be structured properly first:
related_name="sponsorships", | ||
) | ||
|
||
class Meta: |
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.
Move to top
@@ -65,6 +83,48 @@ def get_news_data(limit=10, timeout=30): | |||
return items | |||
|
|||
|
|||
def get_or_create_issue(issue_link): |
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.
This scope is to broad for /sponsor command's function. Let's split it and remove from here.
try: | ||
return Issue.objects.get(url=issue_link) | ||
except Issue.DoesNotExist: | ||
pass | ||
|
||
github_client = Github(settings.GITHUB_TOKEN) | ||
issue_number = int(parts[6]) | ||
owner = parts[3] | ||
repo_name = parts[4] | ||
|
||
try: | ||
# Fetch the repository and issue from GitHub | ||
gh_repo = github_client.get_repo(f"{owner}/{repo_name}") | ||
gh_issue = gh_repo.get_issue(issue_number) | ||
repository = Repository.objects.get(name=repo_name) | ||
author = User.objects.get(login=gh_issue.user.login) | ||
|
||
# Update or create the issue in the database | ||
return Issue.update_data(gh_issue, author=author, repository=repository) | ||
except Exception as e: | ||
logger.exception("Failed to fetch issue from GitHub: %s") | ||
raise ValidationError(FETCH_ISSUE_ERROR.format(error=e)) from e |
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.
This should be a part of github.common.py
sync_issue()
repository = Repository.objects.get(name=repo_name) | ||
author = User.objects.get(login=gh_issue.user.login) |
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.
These may not exist yet.
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.
yes what did you suggest create user or repository too ?(if it not exist in the database?
|
||
# Extract repository owner, repo name, and issue number from the issue link | ||
# Example: https://github.com/OWASP/Nest/issues/XYZ | ||
parts = issue_link.strip("/").split("/") |
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.
Use urllib.parse.urlparse
for this.
def validate_deadline(deadline_str): | ||
"""Validate that the deadline is in a valid datetime format.""" | ||
try: | ||
# Try parsing the deadline in YYYY-MM-DD format | ||
deadline = datetime.strptime(deadline_str, "%Y-%m-%d").replace( | ||
tzinfo=timezone.get_current_timezone() | ||
) | ||
except ValueError: | ||
try: | ||
# Try parsing the deadline in YYYY-MM-DD HH:MM format | ||
deadline = datetime.strptime(deadline_str, "%Y-%m-%d %H:%M").replace( | ||
tzinfo=timezone.get_current_timezone() | ||
) | ||
except ValueError as e: | ||
raise ValidationError(DEADLINE_FORMAT_ERROR) from e | ||
|
||
if deadline < timezone.now(): | ||
raise ValidationError(DEADLINE_FUTURE_ERROR) | ||
|
||
return deadline | ||
|
||
|
||
def validate_github_issue_link(issue_link): | ||
"""Validate that the issue link belongs to a valid OWASP-related repository.""" | ||
if not issue_link.startswith("https://github.com/OWASP"): | ||
raise ValidationError(ISSUE_LINK_ERROR) | ||
return issue_link | ||
|
||
|
||
def validate_price(price): | ||
"""Validate that the price is a positive float value.""" | ||
try: | ||
price = float(price) | ||
if price <= 0: | ||
raise ValidationError(PRICE_POSITIVE_ERROR) | ||
except ValueError as e: | ||
raise ValidationError(PRICE_VALID_ERROR) from e | ||
return price |
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.
These validators belong with Snapshot
model, definitely not here.
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.
Snapshot model ? really?
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.
i think you meant sponsorship
model !!!
Resolves #916
Add the PR description here.
Screenshot/Preview
Results with command