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

Added nest app and slack command for sponsorship #947

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

abhayymishraa
Copy link
Collaborator

@abhayymishraa abhayymishraa commented Feb 27, 2025

Resolves #916

Add the PR description here.

  • Added a new app nest.
  • Added models and migrations
  • Extended the slack command /sponsor

Screenshot/Preview

Results with command

image

image

image

Copy link
Collaborator

@arkid15r arkid15r left a 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:
Copy link
Collaborator

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):
Copy link
Collaborator

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.

Comment on lines +104 to +125
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
Copy link
Collaborator

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()

Comment on lines +118 to +119
repository = Repository.objects.get(name=repo_name)
author = User.objects.get(login=gh_issue.user.login)
Copy link
Collaborator

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.

Copy link
Collaborator Author

@abhayymishraa abhayymishraa Feb 28, 2025

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("/")
Copy link
Collaborator

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.

Comment on lines +197 to +234
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
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Snapshot model ? really?

Copy link
Collaborator Author

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 !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Initial Support for Sponsorship Program
2 participants