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

[feat] Hide Codecov tokens from non admins if YAML setting is enabled #923

Merged
merged 9 commits into from
Oct 28, 2024

Conversation

rohitvinnakota-codecov
Copy link
Contributor

@rohitvinnakota-codecov rohitvinnakota-codecov commented Oct 24, 2024

Purpose/Motivation

What is the feature? Why is this being done?

Relies on codecov/shared#397

Parent issue: https://github.com/codecov/internal-issues/issues/491

Also bumps shared.

Screenshot 2024-10-24 at 11 49 03 AM

@rohitvinnakota-codecov rohitvinnakota-codecov requested a review from a team as a code owner October 24, 2024 14:58
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.24%. Comparing base (4e9c42d) to head (91193be).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #923   +/-   ##
=======================================
  Coverage   96.23%   96.24%           
=======================================
  Files         823      823           
  Lines       18953    18968   +15     
=======================================
+ Hits        18240    18255   +15     
  Misses        713      713           
Flag Coverage Δ
unit 92.48% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 92.48% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@@ -24,6 +25,8 @@
from services.profiling import CriticalFile, ProfilingSummary
from services.redis_configuration import get_redis_connection

TOKEN_UNAVAILABLE = "Token Unavailable"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the plan for UI just to show this instead of the token? Or check the value and do something special?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just updated the PR and copy. Since this work is just for a single customer, we are just going to render the value directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool sounds good. I prefer this approach given this is not an official feature.

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

Comment on lines +79 to +80
if should_hide_tokens and not is_current_user_admin:
return TOKEN_UNAVAILABLE
Copy link

Choose a reason for hiding this comment

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

The command variable is being redefined. The second definition is redundant and should be removed to avoid confusion.

Suggested change
if should_hide_tokens and not is_current_user_admin:
return TOKEN_UNAVAILABLE
if should_hide_tokens and not is_current_user_admin:
return TOKEN_UNAVAILABLE
return command.get_upload_token(repository)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wow good point

Copy link
Contributor

This PR includes changes to shared. Please review them here: codecov/shared@4e27927...067b2e4

Copy link

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2643 tests with 4 failed, 2633 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: api.public.v2.tests.test_test_results_view.TestResultsViewsetTests
    Test name: test_list

    self = <test_test_results_view.TestResultsViewsetTests testMethod=test_list>

    def test_list(self):
    url = reverse(
    "api-v2-tests-results-list",
    kwargs={
    "service": self.org.service,
    "owner_username": self.org.username,
    "repo_name": self.repo.name,
    },
    )
    res = self.client.get(url)
    assert res.status_code == status.HTTP_200_OK
    assert res.json() == {
    "count": 2,
    "next": None,
    "previous": None,
    "results": [
    {
    "id": self.test_instances[0].id,
    "name": self.test_instances[0].test.name,
    "test_id": self.test_instances[0].test_id,
    "failure_message": self.test_instances[0].failure_message,
    "duration_seconds": self.test_instances[0].duration_seconds,
    "commitid": self.test_instances[0].commitid,
    "outcome": self.test_instances[0].outcome,
    "branch": self.test_instances[0].branch,
    "repoid": self.test_instances[0].repoid,
    "failure_rate": self.test_instances[0].test.failure_rate,
    "commits_where_fail": self.test_instances[
    0
    ].test.commits_where_fail,
    },
    {
    "id": self.test_instances[1].id,
    "name": self.test_instances[1].test.name,
    "test_id": self.test_instances[1].test_id,
    "failure_message": self.test_instances[1].failure_message,
    "duration_seconds": self.test_instances[1].duration_seconds,
    "commitid": self.test_instances[1].commitid,
    "outcome": self.test_instances[1].outcome,
    "branch": self.test_instances[1].branch,
    "repoid": self.test_instances[1].repoid,
    "failure_rate": self.test_instances[1].test.failure_rate,
    "commits_where_fail": self.test_instances[
    1
    ].test.commits_where_fail,
    },
    ],
    "total_pages": 1,
    > }
    E AttributeError: 'Test' object has no attribute 'failure_rate'

    .../v2/tests/test_test_results_view.py:78: AttributeError
  • Class name: api.public.v2.tests.test_test_results_view.TestResultsViewsetTests
    Test name: test_list_filters

    self = <test_test_results_view.TestResultsViewsetTests testMethod=test_list_filters>

    def test_list_filters(self):
    url = reverse(
    "api-v2-tests-results-list",
    kwargs={
    "service": self.org.service,
    "owner_username": self.org.username,
    "repo_name": self.repo.name,
    },
    )
    res = self.client.get(f"{url}&commit_id={self.test_instances[0].commitid}")
    assert res.status_code == status.HTTP_200_OK
    assert res.json() == {
    "count": 1,
    "next": None,
    "previous": None,
    "results": [
    {
    "id": self.test_instances[0].id,
    "name": self.test_instances[0].test.name,
    "test_id": self.test_instances[0].test_id,
    "failure_message": self.test_instances[0].failure_message,
    "duration_seconds": self.test_instances[0].duration_seconds,
    "commitid": self.test_instances[0].commitid,
    "outcome": self.test_instances[0].outcome,
    "branch": self.test_instances[0].branch,
    "repoid": self.test_instances[0].repoid,
    "failure_rate": self.test_instances[0].test.failure_rate,
    "commits_where_fail": self.test_instances[
    0
    ].test.commits_where_fail,
    },
    ],
    "total_pages": 1,
    > }
    E AttributeError: 'Test' object has no attribute 'failure_rate'

    .../v2/tests/test_test_results_view.py:113: AttributeError
  • Class name: api.public.v2.tests.test_test_results_view.TestResultsViewsetTests
    Test name: test_result_with_valid_super_token

    self = <test_test_results_view.TestResultsViewsetTests testMethod=test_result_with_valid_super_token>
    repository_artifact_permissions_has_permission = <MagicMock name='has_permission' id='140060501968896'>

    @override_settings(SUPER_API_TOKEN="testaxs3o76rdcdpfzexuccx3uatui2nw73r")
    @patch("api.shared.permissions.RepositoryArtifactPermissions.has_permission")
    def test_result_with_valid_super_token(
    self, repository_artifact_permissions_has_permission
    ):
    repository_artifact_permissions_has_permission.return_value = False
    res = self.client.get(
    reverse(
    "api-v2-tests-results-detail",
    kwargs={
    "service": self.org.service,
    "owner_username": self.org.username,
    "repo_name": self.repo.name,
    "pk": self.test_instances[0].pk,
    },
    ),
    HTTP_AUTHORIZATION="Bearer testaxs3o76rdcdpfzexuccx3uatui2nw73r",
    )
    assert res.status_code == 200
    assert res.json() == {
    "id": self.test_instances[0].id,
    "name": self.test_instances[0].test.name,
    "test_id": self.test_instances[0].test_id,
    "failure_message": self.test_instances[0].failure_message,
    "duration_seconds": self.test_instances[0].duration_seconds,
    "commitid": self.test_instances[0].commitid,
    "outcome": self.test_instances[0].outcome,
    "branch": self.test_instances[0].branch,
    "repoid": self.test_instances[0].repoid,
    "failure_rate": self.test_instances[0].test.failure_rate,
    "commits_where_fail": self.test_instances[0].test.commits_where_fail,
    > }
    E AttributeError: 'Test' object has no attribute 'failure_rate'

    .../v2/tests/test_test_results_view.py:245: AttributeError
  • Class name: api.public.v2.tests.test_test_results_view.TestResultsViewsetTests
    Test name: test_retrieve

    self = <test_test_results_view.TestResultsViewsetTests testMethod=test_retrieve>
    get_repo_permissions = <MagicMock name='get_repo_permissions' id='140060512737168'>

    @patch("api.shared.repo.repository_accessors.RepoAccessors.get_repo_permissions")
    def test_retrieve(self, get_repo_permissions):
    get_repo_permissions.return_value = (True, True)
    res = self.client.get(
    reverse(
    "api-v2-tests-results-detail",
    kwargs={
    "service": self.org.service,
    "owner_username": self.org.username,
    "repo_name": self.repo.name,
    "pk": self.test_instances[0].pk,
    },
    )
    )
    assert res.status_code == status.HTTP_200_OK
    assert res.json() == {
    "id": self.test_instances[0].id,
    "name": self.test_instances[0].test.name,
    "test_id": self.test_instances[0].test_id,
    "failure_message": self.test_instances[0].failure_message,
    "duration_seconds": self.test_instances[0].duration_seconds,
    "commitid": self.test_instances[0].commitid,
    "outcome": self.test_instances[0].outcome,
    "branch": self.test_instances[0].branch,
    "repoid": self.test_instances[0].repoid,
    "failure_rate": self.test_instances[0].test.failure_rate,
    "commits_where_fail": self.test_instances[0].test.commits_where_fail,
    > }
    E AttributeError: 'Test' object has no attribute 'failure_rate'

    .../v2/tests/test_test_results_view.py:142: AttributeError

@codecov-qa
Copy link

codecov-qa bot commented Oct 28, 2024

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
2637 4 2633 6
View the top 3 failed tests by shortest run time
api/public/v2/tests/test_test_results_view.py::TestResultsViewsetTests::test_retrieve
Stack Traces | 0.403s run time
self = &lt;test_test_results_view.TestResultsViewsetTests testMethod=test_retrieve&gt;
get_repo_permissions = &lt;MagicMock name='get_repo_permissions' id='140060512737168'&gt;

    @patch("api.shared.repo.repository_accessors.RepoAccessors.get_repo_permissions")
    def test_retrieve(self, get_repo_permissions):
        get_repo_permissions.return_value = (True, True)
        res = self.client.get(
            reverse(
                "api-v2-tests-results-detail",
                kwargs={
                    "service": self.org.service,
                    "owner_username": self.org.username,
                    "repo_name": self.repo.name,
                    "pk": self.test_instances[0].pk,
                },
            )
        )
        assert res.status_code == status.HTTP_200_OK
        assert res.json() == {
            "id": self.test_instances[0].id,
            "name": self.test_instances[0].test.name,
            "test_id": self.test_instances[0].test_id,
            "failure_message": self.test_instances[0].failure_message,
            "duration_seconds": self.test_instances[0].duration_seconds,
            "commitid": self.test_instances[0].commitid,
            "outcome": self.test_instances[0].outcome,
            "branch": self.test_instances[0].branch,
            "repoid": self.test_instances[0].repoid,
            "failure_rate": self.test_instances[0].test.failure_rate,
            "commits_where_fail": self.test_instances[0].test.commits_where_fail,
&gt;       }
E       AttributeError: 'Test' object has no attribute 'failure_rate'

.../v2/tests/test_test_results_view.py:142: AttributeError
api/public/v2/tests/test_test_results_view.py::TestResultsViewsetTests::test_list_filters
Stack Traces | 0.407s run time
self = &lt;test_test_results_view.TestResultsViewsetTests testMethod=test_list_filters&gt;

    def test_list_filters(self):
        url = reverse(
            "api-v2-tests-results-list",
            kwargs={
                "service": self.org.service,
                "owner_username": self.org.username,
                "repo_name": self.repo.name,
            },
        )
        res = self.client.get(f"{url}?commit_id={self.test_instances[0].commitid}")
        assert res.status_code == status.HTTP_200_OK
        assert res.json() == {
            "count": 1,
            "next": None,
            "previous": None,
            "results": [
                {
                    "id": self.test_instances[0].id,
                    "name": self.test_instances[0].test.name,
                    "test_id": self.test_instances[0].test_id,
                    "failure_message": self.test_instances[0].failure_message,
                    "duration_seconds": self.test_instances[0].duration_seconds,
                    "commitid": self.test_instances[0].commitid,
                    "outcome": self.test_instances[0].outcome,
                    "branch": self.test_instances[0].branch,
                    "repoid": self.test_instances[0].repoid,
                    "failure_rate": self.test_instances[0].test.failure_rate,
                    "commits_where_fail": self.test_instances[
                        0
                    ].test.commits_where_fail,
                },
            ],
            "total_pages": 1,
&gt;       }
E       AttributeError: 'Test' object has no attribute 'failure_rate'

.../v2/tests/test_test_results_view.py:113: AttributeError
api/public/v2/tests/test_test_results_view.py::TestResultsViewsetTests::test_result_with_valid_super_token
Stack Traces | 0.407s run time
self = &lt;test_test_results_view.TestResultsViewsetTests testMethod=test_result_with_valid_super_token&gt;
repository_artifact_permissions_has_permission = &lt;MagicMock name='has_permission' id='140060501968896'&gt;

    @override_settings(SUPER_API_TOKEN="testaxs3o76rdcdpfzexuccx3uatui2nw73r")
    @patch("api.shared.permissions.RepositoryArtifactPermissions.has_permission")
    def test_result_with_valid_super_token(
        self, repository_artifact_permissions_has_permission
    ):
        repository_artifact_permissions_has_permission.return_value = False
        res = self.client.get(
            reverse(
                "api-v2-tests-results-detail",
                kwargs={
                    "service": self.org.service,
                    "owner_username": self.org.username,
                    "repo_name": self.repo.name,
                    "pk": self.test_instances[0].pk,
                },
            ),
            HTTP_AUTHORIZATION="Bearer testaxs3o76rdcdpfzexuccx3uatui2nw73r",
        )
        assert res.status_code == 200
        assert res.json() == {
            "id": self.test_instances[0].id,
            "name": self.test_instances[0].test.name,
            "test_id": self.test_instances[0].test_id,
            "failure_message": self.test_instances[0].failure_message,
            "duration_seconds": self.test_instances[0].duration_seconds,
            "commitid": self.test_instances[0].commitid,
            "outcome": self.test_instances[0].outcome,
            "branch": self.test_instances[0].branch,
            "repoid": self.test_instances[0].repoid,
            "failure_rate": self.test_instances[0].test.failure_rate,
            "commits_where_fail": self.test_instances[0].test.commits_where_fail,
&gt;       }
E       AttributeError: 'Test' object has no attribute 'failure_rate'

.../v2/tests/test_test_results_view.py:245: AttributeError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@rohitvinnakota-codecov rohitvinnakota-codecov added this pull request to the merge queue Oct 28, 2024
Merged via the queue into main with commit 52d870a Oct 28, 2024
18 of 19 checks passed
@rohitvinnakota-codecov rohitvinnakota-codecov deleted the rvinnakota/hide-token-gql branch October 28, 2024 16:20
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