MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / create_method

Method create_method

scripts/openapi.py:3050–3116  ·  view source on GitHub ↗
(
        self,
        spec_file: str,
        index_filename: str,
        class_name: str,
        method_name: str,
        api_verb: str,
        api_path: str,
        api_response: str | None,
        return_property: str | None,
        dry_run: bool,
        handle_new_schemas: HandleNewSchemas,
    )

Source from the content-addressed store, hash-verified

3048 classes.update(**index.get("classes", {}))
3049
3050 def create_method(
3051 self,
3052 spec_file: str,
3053 index_filename: str,
3054 class_name: str,
3055 method_name: str,
3056 api_verb: str,
3057 api_path: str,
3058 api_response: str | None,
3059 return_property: str | None,
3060 dry_run: bool,
3061 handle_new_schemas: HandleNewSchemas,
3062 ) -> bool:
3063 print(f"Using spec {spec_file}")
3064 with open(spec_file) as r:
3065 spec = json.load(r)
3066 with open(index_filename) as r:
3067 index = json.load(r)
3068
3069 clazz = GithubClass.from_class_name(class_name, index)
3070 print(f"Creating method {clazz.full_class_name}.{method_name} in {clazz.filename}")
3071 if not os.path.exists(clazz.filename):
3072 raise ValueError(f"File does not exist: {clazz.filename}")
3073
3074 with open(clazz.filename) as r:
3075 code = "".join(r.readlines())
3076
3077 prefix_path = None
3078 return_schema_to_paths = index.get("indices", {}).get("return_schema_to_paths")
3079 if return_schema_to_paths is None:
3080 raise RuntimeError("OpenAPI spec has not been indexed via openapi.py index")
3081 for schema in clazz.schemas:
3082 for path in return_schema_to_paths.get(schema, []):
3083 if api_path.startswith(f"{path}/"):
3084 prefix_path = path
3085 break
3086 if prefix_path:
3087 break
3088
3089 create_new_class_func = None
3090 if handle_new_schemas == HandleNewSchemas.create_class:
3091
3092 def create_new_class(schema: str) -> None:
3093 classes = index.get("classes", {})
3094 github_path = index.get("sources")
3095 self.create_class_for_schema(
3096 github_path, spec_file, index_filename, spec, classes, tests=True, schema=schema
3097 )
3098
3099 create_new_class_func = create_new_class
3100
3101 transformer = CreateClassMethodTransformer(
3102 spec,
3103 index,
3104 clazz,
3105 method_name,
3106 api_verb,
3107 api_path,

Callers 1

mainMethod · 0.95

Calls 5

write_codeMethod · 0.95
loadMethod · 0.80
from_class_nameMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected