Skip to content

Commit

Permalink
Edit achievements (#437)
Browse files Browse the repository at this point in the history
* edit_achievements

* edit_achievements_addition

* Added common statistics in footer

* add test for contributors:contributor_achievements and minor linter fix

* Add helper function to calc achivements percentage

* fix inline styles

* update common and personal stat

* resolve conflict

* resolve wps

* resolve wps editon 1

* resolve wps editon 2

* resolve wps editon 3

* resolve wps editon 4

* resolve wps editon 6

* resolve wps editon 7

* Update CI.yml

* fix linter notifications

* fix linter notifications

* refactor contributor_achievements.py

* delete sum brackets

* CHECK differences

---------

Co-authored-by: ivan neivan <69588756+sgmdlt@users.noreply.github.com>
  • Loading branch information
AleksandrKosmylev and sgmdlt authored Feb 7, 2025
1 parent 4e502ed commit 6b6a865
Show file tree
Hide file tree
Showing 32 changed files with 754 additions and 77 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8.x
- uses: actions/cache@v2
python-version: 3.10.x
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ transcompile:
uv run django-admin compilemessages

load-dump:
psql -h $(DB_HOST) -U $(DB_USER) -d $(DB_NAME) -p $(DB_PORT) -f dump.sql
psql -h $(DB_HOST) -U $(DB_USER) -d $(DB_NAME) -p $(DB_PORT) -f dump.sql
# Need to have GNU gettext installed
transprepare:
uv run django-admin makemessages --locale ru --add-location file
Expand Down
4 changes: 2 additions & 2 deletions auth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def setUp(self):
"""Create a test client."""
self.client: Client = Client()

@patch('contributors.utils.github_lib.get_access_token', lambda *args: None) # noqa: E501
@patch('contributors.utils.github_lib.get_data_of_token_holder', lambda *args: None) # noqa: E501
@patch('contributors.utils.github_lib.get_access_token', lambda *args: None)
@patch('contributors.utils.github_lib.get_data_of_token_holder', lambda *args: None)
@patch('auth.backends.GitHubBackend.authenticate', lambda *args: None)
def test_github_auth_view(self):
"""Send a request without authentication and check the response."""
Expand Down
13 changes: 13 additions & 0 deletions contributors/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@
from contributors.models.organization import Organization
from contributors.models.project import Project
from contributors.models.repository import Repository

__all__ = [
'CommonFields',
'CommitStats',
'Contribution',
'ContributionLabel',
'Contributor',
'IssueInfo',
'Label',
'Organization',
'Project',
'Repository',
]
10 changes: 10 additions & 0 deletions contributors/templatetags/contrib_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,13 @@ def get_canonical_url(context):
if request:
return request.build_absolute_uri(request.path)
return ''


@register.simple_tag
def calc_percent_achievement(numerator, denominator):
"""Get contributor statistics and required quantity."""
if numerator is not None:
if numerator / denominator > 1:
return 100.0
return numerator / denominator * 100
return 0
10 changes: 10 additions & 0 deletions contributors/tests/test_contributors_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
EXPECTED_CONTRIBUTORS_ISSUE_COUNT = 2
EXPECTED_CONTRIBUTORS_PR_COUNT = 2

TEST_CONTRIBUTORS = ["mintough57", "kinganduld", "indecing", "pilly1964", "suir1948"]


class TestContributorDetailView(TestCase):
"""Test the methods for the contributor's details view."""
Expand Down Expand Up @@ -149,3 +151,11 @@ def test_get_context_data(self):
self.assertEqual(response.context['contributors_issues_gte_1'], 2)
self.assertEqual(response.context['contributors_comments_gte_1'], 0)
self.assertEqual(response.context['contributors_editions_gte_1'], 0)

def test_get_context_data_contributor(self):
for contributor in TEST_CONTRIBUTORS:
response = self.client.get(reverse(
'contributors:contributor_achievements',
args=[contributor]),
)
self.assertEqual(response.status_code, HTTPStatus.OK)
5 changes: 5 additions & 0 deletions contributors/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
views.achievements.AchievementListView.as_view(),
name='achievements',
),
path(
'contributor_achievements/<slug:slug>',
views.contributor_achievements.ContributorAchievementListView.as_view(),
name='contributor_achievements',
),
path(
'landing/',
views.landing.LandingView.as_view(),
Expand Down
2 changes: 1 addition & 1 deletion contributors/utils/github_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.conf import settings

GITHUB_API_URL = 'https://api.github.com'
GITHUB_TOKEN_PROVIDER_URL = 'https://github.com/login/oauth/access_token' # noqa: E501,S105
GITHUB_TOKEN_PROVIDER_URL = 'https://github.com/login/oauth/access_token' # noqa: S105


def merge_dicts(*dicts):
Expand Down
1 change: 1 addition & 0 deletions contributors/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
about,
achievements,
config,
contributor_achievements,
contributor_compare,
filters,
home,
Expand Down
1 change: 1 addition & 0 deletions contributors/views/achievements.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AchievementListView(generic.ListView):
contributors = Contributor.objects.with_contributions()

pull_request_ranges_for_achievements = [100, 50, 25, 10, 1]

commit_ranges_for_achievements = [200, 100, 50, 25, 1]
issue_ranges_for_achievements = [50, 25, 10, 5, 1]
comment_ranges_for_achievements = [200, 100, 50, 25, 1]
Expand Down
Loading

0 comments on commit 6b6a865

Please sign in to comment.