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

Api models #1

Merged
merged 36 commits into from
Jul 12, 2024
Merged

Api models #1

merged 36 commits into from
Jul 12, 2024

Conversation

SalmanAsh
Copy link
Contributor

@SalmanAsh SalmanAsh commented Jul 10, 2024

This change is Reviewable

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 11 of 22 files at r1, all commit messages.
Reviewable status: 11 of 22 files reviewed, 18 unresolved discussions (waiting on @SalmanAsh)


api/urls.py line 22 at r1 (raw file):

from rest_framework.routers import DefaultRouter

# from .views import FruitViewSet

delete commented out lines


api/fixtures/contributors.json line 4 at r1 (raw file):

  {
    "model": "api.contributor",
    "pk": 111111,

1


api/fixtures/contributors.json line 15 at r1 (raw file):

  {
    "model": "api.contributor",
    "pk": 222222,

2


api/fixtures/contributors.json line 26 at r1 (raw file):

  {
    "model": "api.contributor",
    "pk": 333333,

3


api/fixtures/repositories.json line 4 at r1 (raw file):

  {
    "model": "api.repository",
    "pk": 111,

1


api/fixtures/repositories.json line 13 at r1 (raw file):

  {
    "model": "api.repository",
    "pk": 222,

2


api/fixtures/repositories.json line 22 at r1 (raw file):

  {
    "model": "api.repository",
    "pk": 333,

3


api/migrations/0002_agreementsignature_contributor_repository.py line 1 at r1 (raw file):

# Generated by Django 3.2.25 on 2024-07-09 10:23

delete all migrations and regenerate the initial migration


api/migrations/0003_auto_20240709_1347.py line 1 at r1 (raw file):

# Generated by Django 3.2.25 on 2024-07-09 12:47

delete all migrations and regenerate the initial migration


api/migrations/0004_delete_fruit.py line 1 at r1 (raw file):

# Generated by Django 3.2.25 on 2024-07-10 10:57

delete all migrations and regenerate the initial migration


api/models/agreement_signature.py line 22 at r1 (raw file):

    """Signature of a contributor signing the agreement"""

    contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)

write the following above this field

contributor_id: int

api/models/contributor.py line 21 at r1 (raw file):

    id = models.IntegerField(primary_key=True)
    email = models.TextField()

Use EmailField()


api/models/contributor.py line 32 at r1 (raw file):

    def __str__(self):
        return self.name

return f"{self.name} <{self.email}>"


api/models/repository.py line 23 at r1 (raw file):

    id = models.IntegerField(primary_key=True)
    contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)

write the following above this field

contributor_id: int

api/models/repository.py line 25 at r1 (raw file):

    contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)
    NAME_CHOICES = [("portal", "portal"), ("rr", "rr")]
    name = models.TextField(choices=NAME_CHOICES)

on second thought, let's replace this field with

gh_id = models.IntegerField(_("GitHub ID"))

api/models/repository.py line 29 at r1 (raw file):

    class Meta(TypedModelMeta):
        unique_together = ["contributor", "name"]

unique_together = ["contributor", "gh_id"]


api/models/repository.py line 34 at r1 (raw file):

    def __str__(self):
        return self.name

return f"{self.contributor}:{self.gh_id}"


api/fixtures/agreement_signatures.json line 7 at r1 (raw file):

    "fields": {
      "contributor": 111111,
      "agreement_id": "g3d3d3s8dgd3vc37",

should be 40 chars long (the length of commit id). do this for all agreement_ids.

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 22 files at r1, 7 of 14 files at r2, all commit messages.
Reviewable status: 16 of 23 files reviewed, 12 unresolved discussions (waiting on @SalmanAsh)


api/models/agreement_signature.py line 25 at r2 (raw file):

    contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)

    agreement_id = models.CharField(_("agreement id"), max_length=40)

add some helper text explaining that this field contains the commit id of the agreement.

  agreement_id = models.CharField(
_("agreement id"),
max_length=40
helper_text=_("The commit ID of the contribution agreement in the workspace.")
)

api/models/agreement_signature.py line 36 at r2 (raw file):

        cont = f"Contributor {self.contributor} signed"
        repo = f"{self.agreement_id[:7]} at {self.signed_at}"
        return f"{cont} {repo}"

change self.contributor to self.contributor.pk

format like so

return (
f"Contributor {self.contributor.pk} signed"
f" {self.agreement_id[:7]} at {self.signed_at}"
)

api/models/contributor.py line 20 at r2 (raw file):

    """A contributor that contributes to a repo"""

    id = models.IntegerField(primary_key=True)

add some helper text explaining that this field contains the GitHub User-ID of the contributor.

  id = models.IntegerField(
primary_key=True,
helper_text=_("The contributor's GitHub user-ID.")
)

api/models/repository.py line 20 at r2 (raw file):

class Repository(models.Model):
    """A repository to contribute to"""
"""A repository that a contributor has contributed to."""

api/models/repository.py line 34 at r2 (raw file):

    def __str__(self):
        return f"{self.contributor}: {self.gh_id}"

remove the space.

return f"{self.contributor}:{self.gh_id}"

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 14 files at r2.
Reviewable status: 18 of 23 files reviewed, 5 unresolved discussions (waiting on @SalmanAsh)

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 14 files at r2.
Reviewable status: 19 of 23 files reviewed, 5 unresolved discussions (waiting on @SalmanAsh)

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewable status: 19 of 23 files reviewed, 6 unresolved discussions (waiting on @SalmanAsh)


api/models/repository.py line 26 at r2 (raw file):

    gh_id = models.IntegerField(_("GitHub ID"))
    points = models.IntegerField(_("points"), default=0)

add some helper text explaining that this represents how many story points the contributor has closed for this repo.

  id = models.IntegerField(
_("points"),
default=0,
helper_text=_("How many story points the contributor has closed for this repository.")
)

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewable status: 19 of 23 files reviewed, 8 unresolved discussions (waiting on @SalmanAsh)


api/models/contributor_test.py line 22 at r2 (raw file):

    def test_str(self):
        """Parsing a contributor object instance to returns its name."""
"""Parsing a contributor instance to a string returns its name and email."""

api/models/contributor_test.py line 27 at r2 (raw file):

        assert str(self.contributor1) == f"{name} <{email}>"

    def test_fields(self):

unnecessary test, delete it. we only need to test custom we write. we can assume django works correctly and so we don't need to test that django will return the correct field values.

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 14 files at r2.
Reviewable status: 20 of 23 files reviewed, 8 unresolved discussions (waiting on @SalmanAsh)

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 14 files at r2.
Reviewable status: 22 of 23 files reviewed, 10 unresolved discussions (waiting on @SalmanAsh)


api/models/agreement_signature_test.py line 23 at r2 (raw file):

    def test_str(self):
        """Parsing a contributor object instance to returns its name."""

full test-case descriptions please. like so:

"""
Parsing an agreement-signature instance to a string returns the contributor's primary key, the first 7 characters of the agreement's commit ID and the timestamp of when the agreement was signed.
"""

api/models/agreement_signature_test.py line 31 at r2 (raw file):

        assert str(self.agreement_signature) == expected_str

    def test_unique_fields(self):

unnecessary test, delete it. we only need to test custom code we write. we can assume django works correctly. we want to test our code, not django's code.

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 14 files at r2.
Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @SalmanAsh)


api/models/repository_test.py line 24 at r2 (raw file):

    def test_str(self):
        """Parsing a contributor object instance to returns its name."""

full test-case descriptions please. like so:

"""
Parsing a repository instance to a string returns the contributor's primary key and the repository's GitHub ID.
"""

api/models/repository_test.py line 28 at r2 (raw file):

        assert str(self.repository) == expected

    def test_default_value(self):

unnecessary test, delete it. we only need to test custom we write. we can assume django works correctly and so we don't need to test that django will return the correct field values.


api/models/repository_test.py line 43 at r2 (raw file):

        assert repository.points == 0

    def test_unique_fields(self):

unnecessary test, delete it. we only need to test custom we write. we can assume django works correctly and so we don't need to test that django will return the correct field values.

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @SalmanAsh)


api/models/repository.py line 34 at r2 (raw file):

    def __str__(self):
        return f"{self.contributor}: {self.gh_id}"

use self.contributor.pk instead

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 7 files at r3, all commit messages.
Reviewable status: 17 of 23 files reviewed, 14 unresolved discussions (waiting on @SalmanAsh)

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 7 files at r3.
Reviewable status: 18 of 23 files reviewed, 12 unresolved discussions (waiting on @SalmanAsh)

Copy link
Contributor

@SKairinos SKairinos left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 7 files at r3.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @SalmanAsh)

@SalmanAsh SalmanAsh merged commit 507407d into development Jul 12, 2024
7 of 8 checks passed
@SalmanAsh SalmanAsh deleted the api-models branch July 12, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants