88import httpx
99import jinja2
1010
11+ REPO = "getsentry/sentry"
12+ BRANCH = "master"
1113TEMPLATE = """package sentrydata
1214
1315{% for key, value in result.items() %}
@@ -46,33 +48,20 @@ def is_list(value: Any) -> TypeGuard[list[Any]]:
4648
4749def get_text (path : str ) -> str :
4850 r = httpx .get (
49- f"https://raw.githubusercontent.com/getsentry/sentry/ refs/heads/master /{ path } "
51+ f"https://raw.githubusercontent.com/{ REPO } / refs/heads/{ BRANCH } /{ path } "
5052 )
5153 r .raise_for_status ()
5254 return r .text
5355
5456
55- class GitHubUrl (str ):
56- def for_stmt (self , stmt : ast .stmt ) -> GitHubUrl :
57- return self .lineno (stmt .lineno ).end_lineno (stmt .end_lineno )
58-
59- def lineno (self , lineno : int ) -> GitHubUrl :
60- return GitHubUrl (f"{ self } #L{ lineno } " )
61-
62- def end_lineno (self , lineno : int | None ) -> GitHubUrl :
63- if lineno is None :
64- return self
65- return GitHubUrl (f"{ self } -L{ lineno } " )
66-
67-
6857class FileData (NamedTuple ):
69- github_url : GitHubUrl
58+ github_url : str
7059 tree : ast .Module
7160
7261
7362def get_file_data (path : str ) -> FileData :
7463 return FileData (
75- github_url = GitHubUrl ( f"https://github.com/getsentry/sentry/ blob/master /{ path } " ) ,
64+ github_url = f"https://github.com/{ REPO } / blob/{ BRANCH } /{ path } " ,
7665 tree = ast .parse (get_text (path )),
7766 )
7867
@@ -97,15 +86,15 @@ def parse_constants() -> dict[str, ResultData[Any]]:
9786 value = ast .Dict (keys = keys , values = values ),
9887 ):
9988 out ["LogLevels" ] = ResultData (
100- github_url = data .github_url . for_stmt ( node ) ,
89+ github_url = data .github_url ,
10190 result = [],
10291 )
10392 out ["LogLevelNameToId" ] = ResultData (
104- github_url = data .github_url . for_stmt ( node ) ,
93+ github_url = data .github_url ,
10594 result = OrderedDict (),
10695 )
10796 out ["LogLevelIdToName" ] = ResultData (
108- github_url = data .github_url . for_stmt ( node ) ,
97+ github_url = data .github_url ,
10998 result = OrderedDict (),
11099 )
111100 for key , value in zip (keys , values ):
@@ -127,15 +116,15 @@ def parse_issues_grouptype() -> dict[str, ResultData[Any]]:
127116 match node :
128117 case ast .ClassDef (name = "GroupCategory" , body = body ):
129118 out ["IssueGroupCategories" ] = ResultData (
130- github_url = data .github_url . for_stmt ( node ) ,
119+ github_url = data .github_url ,
131120 result = [],
132121 )
133122 out ["IssueGroupCategoryNameToId" ] = ResultData (
134- github_url = data .github_url . for_stmt ( node ) ,
123+ github_url = data .github_url ,
135124 result = OrderedDict (),
136125 )
137126 out ["IssueGroupCategoryIdToName" ] = ResultData (
138- github_url = data .github_url . for_stmt ( node ) ,
127+ github_url = data .github_url ,
139128 result = OrderedDict (),
140129 )
141130 for node in body :
@@ -167,7 +156,7 @@ def parse_rules_conditions_event_attribute() -> dict[str, ResultData[Any]]:
167156 value = ast .Dict (keys = keys ),
168157 ):
169158 out ["EventAttributes" ] = ResultData (
170- github_url = data .github_url . for_stmt ( node ) ,
159+ github_url = data .github_url ,
171160 result = [],
172161 )
173162 for key in keys :
@@ -185,15 +174,15 @@ def parse_rules_match() -> dict[str, ResultData[Any]]:
185174 match node :
186175 case ast .ClassDef (name = "MatchType" , body = body ):
187176 out ["MatchTypes" ] = ResultData (
188- github_url = data .github_url . for_stmt ( node ) ,
177+ github_url = data .github_url ,
189178 result = [],
190179 )
191180 out ["MatchTypeNameToId" ] = ResultData (
192- github_url = data .github_url . for_stmt ( node ) ,
181+ github_url = data .github_url ,
193182 result = OrderedDict (),
194183 )
195184 out ["MatchTypeIdToName" ] = ResultData (
196- github_url = data .github_url . for_stmt ( node ) ,
185+ github_url = data .github_url ,
197186 result = OrderedDict (),
198187 )
199188 for node in body :
@@ -214,7 +203,7 @@ def parse_rules_match() -> dict[str, ResultData[Any]]:
214203 value = ast .Dict (keys = keys ),
215204 ):
216205 out ["LevelMatchTypes" ] = ResultData (
217- github_url = data .github_url . for_stmt ( node ) ,
206+ github_url = data .github_url ,
218207 result = [],
219208 )
220209 for key in keys :
@@ -254,7 +243,7 @@ def extract_types(classdef: ast.ClassDef) -> list[str]:
254243 types = extract_types (node )
255244 if types :
256245 out [name ] = ResultData (
257- github_url = data .github_url . for_stmt ( node ) ,
246+ github_url = data .github_url ,
258247 result = types ,
259248 )
260249 case _:
@@ -272,7 +261,7 @@ def parse_models_project() -> dict[str, ResultData[Any]]:
272261 value = ast .List (elts = elts ),
273262 ):
274263 out ["Platforms" ] = ResultData (
275- github_url = data .github_url . for_stmt ( node ) ,
264+ github_url = data .github_url ,
276265 result = ["other" ],
277266 )
278267 for elt in elts :
0 commit comments