Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 125 additions & 25 deletions backend/apps/github/models/mixins/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class IssueIndexMixin:

@property
def is_indexable(self):
"""Issues to index."""
"""Determine if the issue is indexable.

Returns:
bool: True if the issue is indexable, False otherwise.
"""
return (
self.id
and self.state == self.State.OPEN
Expand All @@ -21,120 +25,216 @@ def is_indexable(self):

@property
def idx_author_login(self) -> str:
"""Return author login for indexing."""
"""Return the author login for indexing.

Returns:
str: The login name of the issue author.
"""
return self.author.login if self.author else ""

@property
def idx_author_name(self) -> str:
"""Return author name for indexing."""
"""Return the author name for indexing.

Returns:
str: The name of the issue author.
"""
return self.author.name if self.author else ""

@property
def idx_comments_count(self) -> int:
"""Return comments count at for indexing."""
"""Return the comments count for indexing.

Returns:
int: The number of comments on the issue.
"""
return self.comments_count

@property
def idx_created_at(self) -> float:
"""Return created at for indexing."""
"""Return the created at timestamp for indexing.

Returns:
float: The creation timestamp of the issue.
"""
return self.created_at.timestamp()

@property
def idx_hint(self) -> str:
"""Return hint for indexing."""
"""Return the hint for indexing.

Returns:
str: The hint associated with the issue.
"""
return self.hint

@property
def idx_labels(self) -> list[str]:
"""Return labels for indexing."""
"""Return the labels for indexing.

Returns:
list[str]: A list of label names associated with the issue.
"""
return [label.name for label in self.labels.all()]

@property
def idx_project_description(self) -> str:
"""Return project description for indexing."""
"""Return the project description for indexing.

Returns:
str: The description of the project associated with the issue.
"""
return self.project.idx_description if self.project else ""

@property
def idx_project_level(self) -> str:
"""Return project level or indexing."""
"""Return the project level for indexing.

Returns:
str: The level of the project associated with the issue.
"""
return self.project.idx_level if self.project else ""

@property
def idx_project_level_raw(self) -> str:
"""Return project raw level for indexing."""
"""Return the project raw level for indexing.

Returns:
str: The raw level of the project associated with the issue.
"""
return self.project.idx_level_raw if self.project else ""

@property
def idx_project_tags(self) -> list[str]:
"""Return project tags for indexing."""
"""Return the project tags for indexing.

Returns:
list[str]: A list of tags associated with the project.
"""
return self.project.idx_tags if self.project else []

@property
def idx_project_topics(self) -> list[str]:
"""Return project topics for indexing."""
"""Return the project topics for indexing.

Returns:
list[str]: A list of topics associated with the project.
"""
return self.project.idx_topics if self.project else []

@property
def idx_project_name(self) -> str:
"""Return project name for indexing."""
"""Return the project name for indexing.

Returns:
str: The name of the project associated with the issue.
"""
return self.project.idx_name if self.project else ""

@property
def idx_project_url(self) -> str:
"""Return project URL for indexing."""
"""Return the project URL for indexing.

Returns:
str: The URL of the project associated with the issue.
"""
return self.project.idx_url if self.project else ""

@property
def idx_repository_contributors_count(self) -> int:
"""Return repository contributors count for indexing."""
"""Return the repository contributors count for indexing.

Returns:
int: The number of contributors to the repository.
"""
return self.repository.idx_contributors_count

@property
def idx_repository_description(self) -> str:
"""Return repository description for indexing."""
"""Return the repository description for indexing.

Returns:
str: The description of the repository.
"""
return self.repository.idx_description

@property
def idx_repository_forks_count(self) -> int:
"""Return repository forks count for indexing."""
"""Return the repository forks count for indexing.

Returns:
int: The number of forks of the repository.
"""
return self.repository.idx_forks_count

@property
def idx_repository_languages(self) -> list[str]:
"""Return repository languages for indexing."""
"""Return the repository languages for indexing.

Returns:
list[str]: A list of languages used in the repository.
"""
return self.repository.top_languages

@property
def idx_repository_name(self) -> str:
"""Return repository name for indexing."""
"""Return the repository name for indexing.

Returns:
str: The name of the repository.
"""
return self.repository.idx_name

@property
def idx_repository_stars_count(self) -> int:
"""Return repository stars count for indexing."""
"""Return the repository stars count for indexing.

Returns:
int: The number of stars received by the repository.
"""
return self.repository.idx_stars_count

@property
def idx_summary(self) -> str:
"""Return summary for indexing."""
"""Return the summary for indexing.

Returns:
str: The summary of the issue.
"""
return self.summary

@property
def idx_title(self) -> str:
"""Return title for indexing."""
"""Return the title for indexing.

Returns:
str: The title of the issue.
"""
return self.title

@property
def idx_repository_topics(self) -> list[str]:
"""Return repository stars count for indexing."""
"""Return the repository topics for indexing.

Returns:
list[str]: A list of topics associated with the repository.
"""
return self.repository.idx_topics

@property
def idx_updated_at(self) -> float:
"""Return updated at for indexing."""
"""Return the updated at timestamp for indexing.

Returns:
float: The last update timestamp of the issue.
"""
return self.updated_at.timestamp()

@property
def idx_url(self) -> str:
"""Return URL for indexing."""
"""Return the URL for indexing.

Returns:
str: The URL of the issue.
"""
return self.url
65 changes: 54 additions & 11 deletions backend/apps/github/models/mixins/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@ class OrganizationIndexMixin:

@property
def is_indexable(self) -> bool:
"""Organizations to index."""
"""Determine if the organization is indexable.

Returns:
bool: True if it's an OWASP-related organization with a name and login, False otherwise.
"""
return bool(self.is_owasp_related_organization and self.name and self.login)

@property
def idx_avatar_url(self) -> str:
"""Return avatar URL for indexing."""
"""Return the avatar URL for indexing.

Returns:
str: The URL of the organization's avatar.
"""
return self.avatar_url

@property
def idx_collaborators_count(self):
"""Return collaborators count for indexing.
"""Return the collaborators count for indexing.

This calculates the total number of unique collaborators across all repositories
owned by this organization.

Returns:
int: The total count of unique collaborators.
"""
from apps.github.models.repository import Repository
from apps.github.models.repository_contributor import RepositoryContributor
Expand All @@ -40,40 +51,72 @@ def idx_collaborators_count(self):

@property
def idx_created_at(self) -> float | None:
"""Return created at for indexing."""
"""Return the created at timestamp for indexing.

Returns:
float | None: The creation timestamp, or None if not available.
"""
return self.created_at.timestamp() if self.created_at else None

@property
def idx_description(self) -> str:
"""Return description for indexing."""
"""Return the description for indexing.

Returns:
str: The organization's description.
"""
return self.description or ""

@property
def idx_followers_count(self) -> int:
"""Return followers count for indexing."""
"""Return the followers count for indexing.

Returns:
int: The number of followers the organization has.
"""
return self.followers_count

@property
def idx_location(self) -> str:
"""Return location for indexing."""
"""Return the location for indexing.

Returns:
str: The organization's location.
"""
return self.location or ""

@property
def idx_login(self) -> str:
"""Return login for indexing."""
"""Return the login for indexing.

Returns:
str: The organization's login name.
"""
return self.login

@property
def idx_name(self) -> str:
"""Return name for indexing."""
"""Return the name for indexing.

Returns:
str: The organization's name.
"""
return self.name or ""

@property
def idx_public_repositories_count(self) -> int:
"""Return public repositories count for indexing."""
"""Return the public repositories count for indexing.

Returns:
int: The number of public repositories owned by the organization.
"""
return self.public_repositories_count

@property
def idx_url(self) -> str:
"""Return URL for indexing."""
"""Return the URL for indexing.

Returns:
str: The URL of the organization's GitHub profile.
"""
return self.url
Loading