:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(tasks): check github access against master (#125247)
Charles Vien86d196ea835b
diff --git a/products/tasks/backend/models.py b/products/tasks/backend/models.pyindex 849a5da98ca6..32cf5be4a4e4 100644--- a/products/tasks/backend/models.py+++ b/products/tasks/backend/models.py@@ -1217,6 +1217,23 @@ class Task(Taggable, DeletedMetaFields, models.Model):def delete(self, *args, **kwargs):raise Exception("Cannot hard delete Task. Use soft_delete() instead.")+ @staticmethod+ def _github_resolution_allowed(origin_product: str, *, has_repository: bool) -> bool:+ # Audits and repo-less signals, autoresearch or metrics import tasks must carry no GitHub+ # credential. Provisioning injects any attached integration; these runs read member-authored+ # text, so an attached token turns planted text into repository access.+ return origin_product != Task.OriginProduct.ACCOUNT_AUDIT and (+ has_repository+ or origin_product+ not in (+ Task.OriginProduct.SIGNALS_CHAT,+ Task.OriginProduct.SIGNAL_REPORT,+ Task.OriginProduct.SIGNALS_SCOUT_SUGGESTIONS,+ Task.OriginProduct.AUTORESEARCH,+ Task.OriginProduct.METRICS_IMPORT,+ )+ )+@staticmethoddef _build_task(*,@@ -1300,20 +1317,7 @@ class Task(Taggable, DeletedMetaFields, models.Model):user_github_integration_is_usable,)- # Audits and repo-less signals, autoresearch or metrics import tasks must carry no GitHub- # credential. Provisioning injects any attached integration; these runs read member-authored- # text, so an attached token turns planted text into repository access.- github_resolution_allowed = origin_product != Task.OriginProduct.ACCOUNT_AUDIT and (- bool(repository)- or origin_product- not in (- Task.OriginProduct.SIGNALS_CHAT,- Task.OriginProduct.SIGNAL_REPORT,- Task.OriginProduct.SIGNALS_SCOUT_SUGGESTIONS,- Task.OriginProduct.AUTORESEARCH,- Task.OriginProduct.METRICS_IMPORT,- )- )+ github_resolution_allowed = Task._github_resolution_allowed(origin_product, has_repository=bool(repository))github_integration = Noneif github_resolution_allowed:github_integration = (diff --git a/products/tasks/backend/tests/test_profile_parity.py b/products/tasks/backend/tests/test_profile_parity.pyindex 819cc410ddac..8aca863596bb 100644--- a/products/tasks/backend/tests/test_profile_parity.py+++ b/products/tasks/backend/tests/test_profile_parity.py@@ -6,7 +6,15 @@ from django.test import SimpleTestCase, override_settingsfrom parameterized import parameterized-from products.tasks.backend.facade.profiles import DrivePolicy, Read, TaskProfile, WarmPolicy, WarmQuota, task_profiles+from products.tasks.backend.facade.profiles import (+ DrivePolicy,+ GithubResolution,+ Read,+ TaskProfile,+ WarmPolicy,+ WarmQuota,+ task_profiles,+)from products.tasks.backend.facade.run_config import WARMABLE_ORIGIN_PRODUCTSfrom products.tasks.backend.logic.services.compute_quota import is_billable_computefrom products.tasks.backend.logic.services.sandbox import parse_requested_sandbox_template@@ -28,6 +36,11 @@ from products.tasks.backend.visibility import ()PROFILES = [(profile.key, profile) for profile in task_profiles()]+PROFILES_BY_REPOSITORY = [+ (f"{profile.key}_{'with' if has_repository else 'without'}_repository", profile, has_repository)+ for profile in task_profiles()+ for has_repository in (True, False)+]MAX_RUN_DURATION_SECONDS = 3 * 60 * 60@@ -129,6 +142,16 @@ class TestTaskProfilesMatchMaster(SimpleTestCase):self.assertEqual(profile.inherit_user_defaults, apply_defaults.called)+ @parameterized.expand(PROFILES_BY_REPOSITORY)+ def test_github_resolution_matches_master(self, _name: str, profile: TaskProfile, has_repository: bool) -> None:+ attaches_github = {+ GithubResolution.ALWAYS: True,+ GithubResolution.WITH_REPOSITORY: has_repository,+ GithubResolution.NEVER: False,+ }[profile.github_resolution]+ master = Task._github_resolution_allowed(profile.origin_product, has_repository=has_repository)+ self.assertEqual(attaches_github, master)+@parameterized.expand(PROFILES)def test_user_authorable_prs_matches_master(self, _key: str, profile: TaskProfile) -> None:self.assertEqual(profile.user_authorable_prs, profile.origin_product in USER_AUTHORABLE_ORIGIN_PRODUCTS)