Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ repos:
hooks:
- id: mypy
additional_dependencies:
- strawberry-graphql-django
- types-jsonschema
- types-lxml
- types-python-dateutil
Expand Down
Empty file.
10 changes: 0 additions & 10 deletions backend/apps/common/graphql/nodes.py

This file was deleted.

7 changes: 0 additions & 7 deletions backend/apps/common/graphql/queries.py

This file was deleted.

48 changes: 28 additions & 20 deletions backend/apps/github/graphql/nodes/issue.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
"""GitHub issue GraphQL node."""

import graphene
import strawberry
import strawberry_django

from apps.common.graphql.nodes import BaseNode
from apps.github.graphql.nodes.user import UserNode
from apps.github.models.issue import Issue


class IssueNode(BaseNode):
@strawberry_django.type(
Issue,
fields=[
"created_at",
"state",
"title",
"url",
],
)
class IssueNode:
"""GitHub issue node."""

organization_name = graphene.String()
repository_name = graphene.String()

class Meta:
model = Issue
fields = (
"author",
"created_at",
"state",
"title",
"url",
@strawberry.field
def author(self) -> UserNode | None:
"""Resolve author."""
return self.author

@strawberry.field
def organization_name(self) -> str | None:
"""Resolve organization name."""
return (
self.repository.organization.login
if self.repository and self.repository.organization
else None
)

def resolve_organization_name(self, info) -> str | None:
"""Return organization name."""
return self.repository.organization.login if self.repository.organization else None

def resolve_repository_name(self, info):
@strawberry.field
def repository_name(self) -> str | None:
"""Resolve the repository name."""
return self.repository.name
return self.repository.name if self.repository else None
59 changes: 33 additions & 26 deletions backend/apps/github/graphql/nodes/milestone.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
"""Github Milestone Node."""

import graphene
import strawberry
import strawberry_django

from apps.common.graphql.nodes import BaseNode
from apps.github.graphql.nodes.user import UserNode
from apps.github.models.milestone import Milestone


class MilestoneNode(BaseNode):
@strawberry_django.type(
Milestone,
fields=[
"closed_issues_count",
"created_at",
"body",
"open_issues_count",
"title",
"url",
],
)
class MilestoneNode:
"""Github Milestone Node."""

organization_name = graphene.String()
progress = graphene.Float()
repository_name = graphene.String()

class Meta:
model = Milestone

fields = (
"author",
"body",
"created_at",
"title",
"open_issues_count",
"closed_issues_count",
"url",
@strawberry.field
def author(self) -> UserNode | None:
"""Resolve author."""
return self.author

@strawberry.field
def organization_name(self) -> str | None:
"""Resolve organization name."""
return (
self.repository.organization.login
if self.repository and self.repository.organization
else None
)

def resolve_organization_name(self, info):
"""Return organization name."""
return self.repository.organization.login if self.repository.organization else None

def resolve_progress(self, info):
"""Return milestone progress."""
@strawberry.field
def progress(self) -> float:
"""Resolve milestone progress."""
total_issues_count = self.closed_issues_count + self.open_issues_count
if not total_issues_count:
return 0.0
return round((self.closed_issues_count / total_issues_count) * 100, 2)

def resolve_repository_name(self, info):
@strawberry.field
def repository_name(self) -> str | None:
"""Resolve repository name."""
return self.repository.name
return self.repository.name if self.repository else None
67 changes: 34 additions & 33 deletions backend/apps/github/graphql/nodes/organization.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
"""GitHub organization GraphQL node."""

import graphene
import strawberry
import strawberry_django
from django.db import models

from apps.common.graphql.nodes import BaseNode
from apps.github.models.organization import Organization
from apps.github.models.repository import Repository
from apps.github.models.repository_contributor import RepositoryContributor


class OrganizationStatsNode(graphene.ObjectType):
@strawberry.type
class OrganizationStatsNode:
"""Organization stats node."""

total_repositories = graphene.Int()
total_contributors = graphene.Int()
total_stars = graphene.Int()
total_forks = graphene.Int()
total_issues = graphene.Int()
total_contributors: int
total_forks: int
total_issues: int
total_repositories: int
total_stars: int


class OrganizationNode(BaseNode):
@strawberry_django.type(
Organization,
fields=[
"avatar_url",
"collaborators_count",
"company",
"created_at",
"description",
"email",
"followers_count",
"location",
"login",
"name",
"updated_at",
],
)
class OrganizationNode:
"""GitHub organization node."""

stats = graphene.Field(OrganizationStatsNode)
url = graphene.String()

class Meta:
model = Organization
fields = (
"avatar_url",
"collaborators_count",
"company",
"created_at",
"description",
"email",
"followers_count",
"location",
"login",
"name",
"updated_at",
)

def resolve_stats(self, info):
@strawberry.field
def stats(self) -> OrganizationStatsNode:
"""Resolve organization stats."""
repositories = Repository.objects.filter(organization=self)

Expand All @@ -51,9 +50,10 @@ def resolve_stats(self, info):
total_forks=models.Sum("forks_count"),
total_issues=models.Sum("open_issues_count"),
)
total_stars = aggregated_stats["total_stars"] or 0
total_forks = aggregated_stats["total_forks"] or 0
total_issues = aggregated_stats["total_issues"] or 0

total_stars = aggregated_stats.get("total_stars") or 0
total_forks = aggregated_stats.get("total_forks") or 0
total_issues = aggregated_stats.get("total_issues") or 0

unique_contributors = (
RepositoryContributor.objects.filter(repository__in=repositories)
Expand All @@ -70,6 +70,7 @@ def resolve_stats(self, info):
total_issues=total_issues,
)

def resolve_url(self, info):
@strawberry.field
def url(self) -> str:
"""Resolve organization URL."""
return self.url
50 changes: 29 additions & 21 deletions backend/apps/github/graphql/nodes/pull_request.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
"""GitHub Pull Request Node."""

import graphene
import strawberry
import strawberry_django

from apps.common.graphql.nodes import BaseNode
from apps.github.graphql.nodes.user import UserNode
from apps.github.models.pull_request import PullRequest


class PullRequestNode(BaseNode):
@strawberry_django.type(
PullRequest,
fields=[
"created_at",
"title",
],
)
class PullRequestNode:
"""GitHub pull request node."""

organization_name = graphene.String()
repository_name = graphene.String()
url = graphene.String()

class Meta:
model = PullRequest
fields = (
"author",
"created_at",
"title",
@strawberry.field
def author(self) -> UserNode | None:
"""Resolve author."""
return self.author

@strawberry.field
def organization_name(self) -> str | None:
"""Resolve organization name."""
return (
self.repository.organization.login
if self.repository and self.repository.organization
else None
)

def resolve_organization_name(self, info):
"""Return organization name."""
return self.repository.organization.login if self.repository.organization else None

def resolve_repository_name(self, info):
@strawberry.field
def repository_name(self) -> str | None:
"""Resolve repository name."""
return self.repository.name
return self.repository.name if self.repository else None

def resolve_url(self, info):
@strawberry.field
def url(self) -> str:
"""Resolve URL."""
return self.url
return str(self.url) if self.url else ""
Loading