예제 #1
0
    def serialize(self, obj, attrs, user):
        data = {
            "id": str(obj.id),
            "raw": obj.raw,
            "dateCreated": obj.date_added,
            "dateUpdated": obj.date_updated,
            "codeMappingId": str(obj.repository_project_path_config_id),
            "provider": "unknown",
        }

        data["provider"] = attrs.get("provider", "unknown")

        if "codeMapping" in self.expand:
            config = attrs.get("codeMapping", {})
            data["codeMapping"] = serialize(
                config,
                user=user,
                serializer=RepositoryProjectPathConfigSerializer())
        if "ownershipSyntax" in self.expand:
            data["ownershipSyntax"] = convert_schema_to_rules_text(obj.schema)

        if "errors" in self.expand:
            _, errors = ProjectCodeOwners.validate_codeowners_associations(
                obj.raw, obj.project)
            data["errors"] = errors

        return data
예제 #2
0
def test_convert_schema_to_rules_text():
    assert (
        convert_schema_to_rules_text(
            {
                "$version":
                1,
                "rules": [
                    {
                        "matcher": {
                            "type": "path",
                            "pattern": "*.js"
                        },
                        "owners": [
                            {
                                "type": "team",
                                "identifier": "frontend"
                            },
                            {
                                "type": "user",
                                "identifier": "*****@*****.**"
                            },
                        ],
                    },
                    {
                        "matcher": {
                            "type": "url",
                            "pattern": "http://google.com/*"
                        },
                        "owners": [{
                            "type": "team",
                            "identifier": "backend"
                        }],
                    },
                    {
                        "matcher": {
                            "type": "path",
                            "pattern": "src/sentry/*"
                        },
                        "owners": [{
                            "type": "user",
                            "identifier": "*****@*****.**"
                        }],
                    },
                    {
                        "matcher": {
                            "type": "tags.foo",
                            "pattern": "bar"
                        },
                        "owners": [{
                            "type": "user",
                            "identifier": "*****@*****.**"
                        }],
                    },
                    {
                        "matcher": {
                            "type": "tags.foo",
                            "pattern": "bar baz"
                        },
                        "owners": [{
                            "type": "user",
                            "identifier": "*****@*****.**"
                        }],
                    },
                    {
                        "matcher": {
                            "type": "module",
                            "pattern": "foo.bar"
                        },
                        "owners": [
                            {
                                "type": "team",
                                "identifier": "workflow"
                            }
                        ],
                    },
                    {
                        "matcher": {
                            "type": "module",
                            "pattern": "foo bar"
                        },
                        "owners": [
                            {
                                "type": "user",
                                "identifier": "*****@*****.**"
                            }
                        ],
                    },
                ],
            }) ==
        "path:*.js #frontend [email protected]\nurl:http://google.com/* #backend\npath:src/sentry/* [email protected]\ntags.foo:bar [email protected]\ntags.foo:bar baz [email protected]\nmodule:foo.bar #workflow\nmodule:foo bar [email protected]\n"
    )