66by an environment rule leaves no log at all. Each of those went unnoticed for
77days. This treats anything other than success/skipped as a problem.
88
9- Run with: python -m machine.health [--issue]
9+ It only reads. The report goes to stdout and the run's step summary; nothing
10+ is written to GitHub and nobody is mentioned, so it runs only when a person
11+ starts it.
12+
13+ Run with: python -m machine.health
1014"""
1115
1216from __future__ import annotations
2428
2529API = "https://api.github.com"
2630CONFIG = Path (__file__ ).with_name ("repos.json" )
27- ISSUE_TITLE = "Org health report"
2831
2932# Conclusions that mean the run did its job. Everything else is surfaced —
3033# `cancelled` and `timed_out` included, because that is how silent failures look.
@@ -178,58 +181,8 @@ def render(findings: list[Finding], config: dict[str, Any]) -> str:
178181 return "\n " .join (lines ) + "\n "
179182
180183
181- def fingerprint (findings : list [Finding ]) -> str :
182- """Stable identity of a problem set: what is broken, not when it was checked."""
183- return "," .join (sorted (f"{ f .where } ={ f .what } " for f in findings ))
184-
185-
186- def alert_needed (previous_body : str , current : str ) -> bool :
187- """Alert only when the set of problems changed — and never for all clear.
188-
189- A daily ping about the same known failure trains people to ignore the
190- ping; the point is to hear about the *new* one.
191- """
192- if not current :
193- return False
194- return f"<!-- fingerprint:{ current } -->" not in previous_body
195-
196-
197- def publish (body : str , token : str , repo : str , findings : list [Finding ], mention : str ) -> None :
198- """Keep one open issue up to date instead of opening one per run."""
199- def call (method : str , path : str , payload : dict [str , Any ] | None = None ) -> Any :
200- data = json .dumps (payload ).encode ("utf-8" ) if payload is not None else None
201- request = urllib .request .Request (f"{ API } { path } " , data = data , method = method , headers = {
202- "Accept" : "application/vnd.github+json" ,
203- "Authorization" : f"Bearer { token } " ,
204- "Content-Type" : "application/json" ,
205- })
206- with urllib .request .urlopen (request , timeout = 30 ) as response :
207- return json .loads (response .read ().decode ("utf-8" ) or "null" )
208-
209- current = fingerprint (findings )
210- stamped = f"{ body } \n <!-- fingerprint:{ current } -->\n "
211-
212- issues = call ("GET" , f"/repos/{ repo } /issues?state=open&per_page=100" )
213- existing = next ((i for i in issues if i .get ("title" ) == ISSUE_TITLE ), None )
214- if existing :
215- number = existing ["number" ]
216- previous = existing .get ("body" ) or ""
217- call ("PATCH" , f"/repos/{ repo } /issues/{ number } " , {"body" : stamped })
218- else :
219- number = call ("POST" , f"/repos/{ repo } /issues" , {"title" : ISSUE_TITLE , "body" : stamped })["number" ]
220- previous = ""
221-
222- # A comment, not an edit: editing an issue body notifies nobody.
223- if mention and alert_needed (previous , current ):
224- lines = "\n " .join (f"- { f .where } : **{ f .what } **" for f in findings )
225- call ("POST" , f"/repos/{ repo } /issues/{ number } /comments" ,
226- {"body" : f"@{ mention } the org health report changed:\n \n { lines } " })
227-
228-
229184def main () -> int :
230- parser = argparse .ArgumentParser (description = __doc__ .splitlines ()[0 ])
231- parser .add_argument ("--issue" , action = "store_true" , help = "update the health issue" )
232- args = parser .parse_args ()
185+ argparse .ArgumentParser (description = __doc__ .splitlines ()[0 ]).parse_args ()
233186
234187 config = json .loads (CONFIG .read_text (encoding = "utf-8" ))
235188 token = os .environ .get ("GITHUB_TOKEN" )
@@ -240,9 +193,6 @@ def main() -> int:
240193 summary = os .environ .get ("GITHUB_STEP_SUMMARY" )
241194 if summary :
242195 Path (summary ).write_text (report , encoding = "utf-8" )
243- if args .issue and token :
244- publish (report , token , os .environ .get ("GITHUB_REPOSITORY" , "GetTechAPI/TechMachine" ),
245- findings , config .get ("notify" , "" ))
246196 # The report is the output; a red run would only add a second alert.
247197 return 0
248198
0 commit comments