@@ -90,13 +90,29 @@ def smp_preselect(_, config_dir, changed_files, exclude="", owners_file=".github
9090 (matching the SMP CLI's discovery), addressed by its path relative to
9191 config_dir (e.g. "logs", "logs/syslog"). Ownership is resolved from the
9292 checked-out CODEOWNERS on both sides, so the result depends only on the PR.
93+
94+ Only folders whose README declares `mode: team-gate` participate in
95+ auto-selection; `mode: optional` (or a missing mode) folders are never
96+ auto-selected -- they remain plain opt-in checkboxes in the comment.
9397 """
9498 import os
99+ import re
95100
96101 def _teams (owner_tuples ):
97102 # keep TEAM entries only (drop individual users), normalized to bare slugs
98103 return {team .casefold ().replace ("@datadog/" , "" ) for label , team in owner_tuples if label == 'TEAM' }
99104
105+ def _mode (rel ):
106+ # read `mode:` from the folder README frontmatter; default "optional"
107+ try :
108+ with open (os .path .join (config_dir , rel , "README.md" )) as f :
109+ content = f .read ()
110+ except OSError :
111+ return "optional"
112+ block = re .search (r'^---\s*$(.*?)^---\s*$' , content , re .MULTILINE | re .DOTALL )
113+ match = re .search (r'^\s*mode:\s*(\S+)' , block .group (1 ) if block else content , re .MULTILINE )
114+ return match .group (1 ).strip ().casefold () if match else "optional"
115+
100116 code_owners = read_owners (owners_file )
101117
102118 with open (changed_files ) as f :
@@ -112,6 +128,8 @@ def _teams(owner_tuples):
112128 rel = os .path .relpath (root , config_dir )
113129 if rel == "." or rel .split (os .sep )[0 ] in excluded :
114130 continue
131+ if _mode (rel ) != "team-gate" :
132+ continue
115133 if _teams (code_owners .of (f"{ config_dir } /{ rel } /" )) & involved_teams :
116134 selected .append (rel )
117135
0 commit comments