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

fix: Fix auto activation in the repo level #996

Merged
merged 3 commits into from
Nov 25, 2024
Merged

Conversation

RulaKhaled
Copy link
Contributor

@RulaKhaled RulaKhaled commented Nov 21, 2024

Purpose/Motivation

What is the feature? Why is this being done?
We used to auto-activate only if both coverage and bundle were enabled. This fix ensures that if one product is enabled, auto-activation still works as expected.

We don't need OwnerNotActivatedError anymore, this is handled by isCurrentUserActivated in gazebo

Links to relevant tickets

Fixes: [Self-hosted] Auto-activate members doesn't work in latest/24.10.1

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-notifications
Copy link

codecov-notifications bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Nov 21, 2024

❌ 127 Tests Failed:

Tests completed Failed Passed Skipped
2690 127 2563 6
View the top 3 failed tests by shortest run time
graphql_api/tests/test_repository.py::TestFetchRepository::test_repo_upload_token_not_available_config_setting_owner_is_anonymous
Stack Traces | 0.431s run time
self = <graphql_api.tests.test_repository.TestFetchRepository testMethod=test_repo_upload_token_not_available_config_setting_owner_is_anonymous>

    @override_settings(HIDE_ALL_CODECOV_TOKENS=True)
    def test_repo_upload_token_not_available_config_setting_owner_is_anonymous(self):
        owner = OwnerFactory(service="gitlab")
    
        repo = RepositoryFactory(
            author=owner,
            author__service="gitlab",
            service_id=12345,
            active=True,
            private=False,
        )
    
        query = """
            query {
                owner(username: "%s") {
                    repository(name: "%s") {
                        ... on Repository {
                            uploadToken
                        }
                    }
                }
            }
        """ % (
            owner.username,
            repo.name,
        )
    
        data = self.gql_request(
            query,
            variables={"name": repo.name},
            provider="gitlab",
        )
    
>       assert data["owner"]["repository"]["uploadToken"] == TOKEN_UNAVAILABLE
E       TypeError: 'NoneType' object is not subscriptable

graphql_api/tests/test_repository.py:766: TypeError
graphql_api/tests/test_branch.py::TestBranch::test_fetch_path_contents_with_no_report
Stack Traces | 0.443s run time
self = <graphql_api.tests.test_branch.TestBranch testMethod=test_fetch_path_contents_with_no_report>
report_mock = <MagicMock name='build_report_from_commit' id='139690061333904'>

    @override_settings(DEBUG=True)
    @patch("shared.reports.api_report_service.build_report_from_commit")
    def test_fetch_path_contents_with_no_report(self, report_mock):
        report_mock.return_value = None
        commit_without_report = CommitFactory(repository=self.repo)
        branch = BranchFactory(
            repository=self.repo,
            head=commit_without_report.commitid,
            name="branch-two",
            updatestamp=(datetime.now() + timedelta(1)),
        )
        variables = {
            "org": self.org.username,
            "repo": self.repo.name,
            "branch": branch.name,
            "path": "",
            "filters": {},
        }
        data = self.gql_request(query_files, variables=variables)
>       assert data == {
            "owner": {
                "repository": {
                    "branch": {
                        "head": {
                            "pathContents": {
                                "__typename": "MissingHeadReport",
                                "message": "Missing head report",
                            }
                        }
                    }
                }
            }
        }
E       AssertionError: assert {'owner': None} == {'owner': {'r... report'}}}}}}
E         
E         Differing items:
E         {'owner': None} != {'owner': {'repository': {'branch': {'head': {'pathContents': {'__typename': 'MissingHeadReport', 'message': 'Missing head report'}}}}}}
E         Use -v to get more diff

graphql_api/tests/test_branch.py:271: AssertionError
graphql_api/tests/test_branch.py::TestBranch::test_fetch_path_contents_component_and_flag_filters_unknown_flags
Stack Traces | 0.445s run time
self = <graphql_api.tests.test_branch.TestBranch testMethod=test_fetch_path_contents_component_and_flag_filters_unknown_flags>
flag_files_mock = <MagicMock name='files_belonging_to_flags' id='139637507155168'>
report_mock = <MagicMock name='build_report_from_commit' id='139637507317808'>
commit_components_mock = <MagicMock name='commit_components' id='139637506877600'>
filtered_mock = <MagicMock name='component_filtered_report' id='139637506872272'>

    @patch("services.components.component_filtered_report")
    @patch("services.components.commit_components")
    @patch("shared.reports.api_report_service.build_report_from_commit")
    @patch("services.report.files_belonging_to_flags")
    def test_fetch_path_contents_component_and_flag_filters_unknown_flags(
        self, flag_files_mock, report_mock, commit_components_mock, filtered_mock
    ):
        flag_files_mock.return_value = ["fileA.py"]
        report_mock.return_value = MockNoFlagsReport()
        commit_components_mock.return_value = [
            Component.from_dict(
                {
                    "component_id": "unit",
                    "name": "unit",
                    "paths": ["fileA.py"],
                    "flag_regexes": "flag-a",
                }
            ),
            Component.from_dict(
                {
                    "component_id": "integration",
                    "name": "integration",
                    "paths": ["fileB.py"],
                }
            ),
            Component.from_dict(
                {
                    "component_id": "global",
                    "name": "Global",
                    "paths": ["(?s:.*/[^\\/]*\\.py.*)\\Z"],
                    "flag_regexes": "flag-a",
                }
            ),
        ]
        filtered_mock.return_value = MockNoFlagsReport()
    
        query_files = """
            query FetchFiles($org: String!, $repo: String!, $branch: String!, $path: String!, $filters: PathContentsFilters!) {
                owner(username: $org) {
                    repository(name: $repo) {
                        ... on Repository {
                            branch(name: $branch) {
                                head {
                                    pathContents (path: $path, filters: $filters) {
                                        __typename
                                        ... on PathContents {
                                            results {
                                                __typename
                                                name
                                                path
                                            }
                                        }
                                        ... on MissingCoverage {
                                            message
                                        }
                                        ... on UnknownFlags {
                                            message
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        """
        components, flags = ["integration"], ["flag-a"]
        variables = {
            "org": self.org.username,
            "repo": self.repo.name,
            "branch": self.branch.name,
            "path": "",
            "filters": {"components": components, "flags": flags},
        }
        data = self.gql_request(query_files, variables=variables)
>       assert data == {
            "owner": {
                "repository": {
                    "branch": {
                        "head": {
                            "pathContents": {
                                "__typename": "UnknownFlags",
                                "message": f"No coverage with chosen flags: {flags}",
                            }
                        }
                    }
                }
            }
        }
E       assert {'owner': None} == {'owner': {'r...lag-a']"}}}}}}
E         
E         Differing items:
E         {'owner': None} != {'owner': {'repository': {'branch': {'head': {'pathContents': {'__typename': 'UnknownFlags', 'message': "No coverage with chosen flags: ['flag-a']"}}}}}}
E         Use -v to get more diff

graphql_api/tests/test_branch.py:969: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.03%. Comparing base (4a2bb9b) to head (d7732cc).
Report is 6 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #996      +/-   ##
==========================================
- Coverage   96.03%   96.03%   -0.01%     
==========================================
  Files         828      828              
  Lines       19166    19163       -3     
==========================================
- Hits        18407    18404       -3     
  Misses        759      759              
Flag Coverage Δ
unit 92.28% <100.00%> (-0.03%) ⬇️
unit-latest-uploader 92.28% <100.00%> (-0.03%) ⬇️

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.

Copy link

❌ 127 Tests Failed:

Tests completed Failed Passed Skipped
2690 127 2563 6
View the top 3 failed tests by shortest run time
graphql_api/tests/test_repository.py::TestFetchRepository::test_repo_upload_token_not_available_config_setting_owner_is_anonymous
Stack Traces | 0.431s run time
self = &lt;graphql_api.tests.test_repository.TestFetchRepository testMethod=test_repo_upload_token_not_available_config_setting_owner_is_anonymous&gt;

    @override_settings(HIDE_ALL_CODECOV_TOKENS=True)
    def test_repo_upload_token_not_available_config_setting_owner_is_anonymous(self):
        owner = OwnerFactory(service="gitlab")
    
        repo = RepositoryFactory(
            author=owner,
            author__service="gitlab",
            service_id=12345,
            active=True,
            private=False,
        )
    
        query = """
            query {
                owner(username: "%s") {
                    repository(name: "%s") {
                        ... on Repository {
                            uploadToken
                        }
                    }
                }
            }
        """ % (
            owner.username,
            repo.name,
        )
    
        data = self.gql_request(
            query,
            variables={"name": repo.name},
            provider="gitlab",
        )
    
&gt;       assert data["owner"]["repository"]["uploadToken"] == TOKEN_UNAVAILABLE
E       TypeError: 'NoneType' object is not subscriptable

graphql_api/tests/test_repository.py:766: TypeError
graphql_api/tests/test_branch.py::TestBranch::test_fetch_path_contents_with_no_report
Stack Traces | 0.443s run time
self = &lt;graphql_api.tests.test_branch.TestBranch testMethod=test_fetch_path_contents_with_no_report&gt;
report_mock = &lt;MagicMock name='build_report_from_commit' id='139690061333904'&gt;

    @override_settings(DEBUG=True)
    @patch("shared.reports.api_report_service.build_report_from_commit")
    def test_fetch_path_contents_with_no_report(self, report_mock):
        report_mock.return_value = None
        commit_without_report = CommitFactory(repository=self.repo)
        branch = BranchFactory(
            repository=self.repo,
            head=commit_without_report.commitid,
            name="branch-two",
            updatestamp=(datetime.now() + timedelta(1)),
        )
        variables = {
            "org": self.org.username,
            "repo": self.repo.name,
            "branch": branch.name,
            "path": "",
            "filters": {},
        }
        data = self.gql_request(query_files, variables=variables)
&gt;       assert data == {
            "owner": {
                "repository": {
                    "branch": {
                        "head": {
                            "pathContents": {
                                "__typename": "MissingHeadReport",
                                "message": "Missing head report",
                            }
                        }
                    }
                }
            }
        }
E       AssertionError: assert {'owner': None} == {'owner': {'r... report'}}}}}}
E         
E         Differing items:
E         {'owner': None} != {'owner': {'repository': {'branch': {'head': {'pathContents': {'__typename': 'MissingHeadReport', 'message': 'Missing head report'}}}}}}
E         Use -v to get more diff

graphql_api/tests/test_branch.py:271: AssertionError
graphql_api/tests/test_branch.py::TestBranch::test_fetch_path_contents_component_and_flag_filters_unknown_flags
Stack Traces | 0.445s run time
self = &lt;graphql_api.tests.test_branch.TestBranch testMethod=test_fetch_path_contents_component_and_flag_filters_unknown_flags&gt;
flag_files_mock = &lt;MagicMock name='files_belonging_to_flags' id='139637507155168'&gt;
report_mock = &lt;MagicMock name='build_report_from_commit' id='139637507317808'&gt;
commit_components_mock = &lt;MagicMock name='commit_components' id='139637506877600'&gt;
filtered_mock = &lt;MagicMock name='component_filtered_report' id='139637506872272'&gt;

    @patch("services.components.component_filtered_report")
    @patch("services.components.commit_components")
    @patch("shared.reports.api_report_service.build_report_from_commit")
    @patch("services.report.files_belonging_to_flags")
    def test_fetch_path_contents_component_and_flag_filters_unknown_flags(
        self, flag_files_mock, report_mock, commit_components_mock, filtered_mock
    ):
        flag_files_mock.return_value = ["fileA.py"]
        report_mock.return_value = MockNoFlagsReport()
        commit_components_mock.return_value = [
            Component.from_dict(
                {
                    "component_id": "unit",
                    "name": "unit",
                    "paths": ["fileA.py"],
                    "flag_regexes": "flag-a",
                }
            ),
            Component.from_dict(
                {
                    "component_id": "integration",
                    "name": "integration",
                    "paths": ["fileB.py"],
                }
            ),
            Component.from_dict(
                {
                    "component_id": "global",
                    "name": "Global",
                    "paths": ["(?s:.*/[^\\/]*\\.py.*)\\Z"],
                    "flag_regexes": "flag-a",
                }
            ),
        ]
        filtered_mock.return_value = MockNoFlagsReport()
    
        query_files = """
            query FetchFiles($org: String!, $repo: String!, $branch: String!, $path: String!, $filters: PathContentsFilters!) {
                owner(username: $org) {
                    repository(name: $repo) {
                        ... on Repository {
                            branch(name: $branch) {
                                head {
                                    pathContents (path: $path, filters: $filters) {
                                        __typename
                                        ... on PathContents {
                                            results {
                                                __typename
                                                name
                                                path
                                            }
                                        }
                                        ... on MissingCoverage {
                                            message
                                        }
                                        ... on UnknownFlags {
                                            message
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        """
        components, flags = ["integration"], ["flag-a"]
        variables = {
            "org": self.org.username,
            "repo": self.repo.name,
            "branch": self.branch.name,
            "path": "",
            "filters": {"components": components, "flags": flags},
        }
        data = self.gql_request(query_files, variables=variables)
&gt;       assert data == {
            "owner": {
                "repository": {
                    "branch": {
                        "head": {
                            "pathContents": {
                                "__typename": "UnknownFlags",
                                "message": f"No coverage with chosen flags: {flags}",
                            }
                        }
                    }
                }
            }
        }
E       assert {'owner': None} == {'owner': {'r...lag-a']"}}}}}}
E         
E         Differing items:
E         {'owner': None} != {'owner': {'repository': {'branch': {'head': {'pathContents': {'__typename': 'UnknownFlags', 'message': "No coverage with chosen flags: ['flag-a']"}}}}}}
E         Use -v to get more diff

graphql_api/tests/test_branch.py:969: AssertionError

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

Copy link
Contributor

github-actions bot commented Nov 21, 2024

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@RulaKhaled RulaKhaled added this pull request to the merge queue Nov 25, 2024
Merged via the queue into main with commit 86862da Nov 25, 2024
17 of 19 checks passed
@RulaKhaled RulaKhaled deleted the fix-auto-activation branch November 25, 2024 16:26
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.

[Self-hosted] Auto-activate members doesn't work in latest/24.10.1
2 participants