Skip to content

Commit 8721d8f

Browse files
committed
scripts/set_assignees.py: also set assignee on manifest changes
Parse manifest for changes and set assignees for any manifest entries that has changed. Signed-off-by: Anas Nashif <[email protected]>
1 parent bddef56 commit 8721d8f

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

scripts/set_assignees.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
from collections import defaultdict
1414
from west.manifest import Manifest
1515
from west.manifest import ManifestProject
16+
from git import Repo
17+
from pathlib import Path
1618

1719
TOP_DIR = os.path.join(os.path.dirname(__file__))
1820
sys.path.insert(0, os.path.join(TOP_DIR, "scripts"))
1921
from get_maintainer import Maintainers
2022

23+
zephyr_base = os.getenv('ZEPHYR_BASE', os.path.join(TOP_DIR, '..'))
24+
2125
def log(s):
2226
if args.verbose > 0:
2327
print(s, file=sys.stdout)
@@ -50,11 +54,46 @@ def parse_args():
5054
parser.add_argument("-r", "--repo", default="zephyr",
5155
help="Github repository")
5256

57+
parser.add_argument("-c", "--commits", default=None,
58+
help="Commit range in the form: a..b")
59+
5360
parser.add_argument("-v", "--verbose", action="count", default=0,
5461
help="Verbose Output")
5562

5663
args = parser.parse_args()
5764

65+
66+
def process_manifest():
67+
repo = Repo(zephyr_base)
68+
old_manifest_content = repo.git.show(f"{args.commits[:-2]}:west.yml")
69+
with open("west_old.yml", "w") as manifest:
70+
manifest.write(old_manifest_content)
71+
old_manifest = Manifest.from_file("west_old.yml")
72+
new_manifest = Manifest.from_file("west.yml")
73+
old_projs = set((p.name, p.revision) for p in old_manifest.projects)
74+
new_projs = set((p.name, p.revision) for p in new_manifest.projects)
75+
# Removed projects
76+
rprojs = set(filter(lambda p: p[0] not in list(p[0] for p in new_projs),
77+
old_projs - new_projs))
78+
# Updated projects
79+
uprojs = set(filter(lambda p: p[0] in list(p[0] for p in old_projs),
80+
new_projs - old_projs))
81+
# Added projects
82+
aprojs = new_projs - old_projs - uprojs
83+
84+
# All projs
85+
projs = rprojs | uprojs | aprojs
86+
projs_names = [name for name, rev in projs]
87+
88+
if not projs_names:
89+
return
90+
areas = []
91+
for p in projs_names:
92+
areas.append(f'West project: {p}')
93+
94+
log(f'manifest areas: {areas}')
95+
return areas
96+
5897
def process_pr(gh, maintainer_file, number):
5998

6099
gh_repo = gh.get_repo(f"{args.org}/{args.repo}")
@@ -70,10 +109,6 @@ def process_pr(gh, maintainer_file, number):
70109
all_areas = set()
71110
fn = list(pr.get_files())
72111

73-
for changed_file in fn:
74-
if changed_file.filename in ['west.yml','submanifests/optional.yaml']:
75-
break
76-
77112
if pr.commits == 1 and (pr.additions <= 1 and pr.deletions <= 1):
78113
labels = {'size: XS'}
79114

@@ -84,7 +119,16 @@ def process_pr(gh, maintainer_file, number):
84119
for changed_file in fn:
85120
num_files += 1
86121
log(f"file: {changed_file.filename}")
87-
areas = maintainer_file.path2areas(changed_file.filename)
122+
123+
areas = []
124+
if changed_file.filename in ['west.yml','submanifests/optional.yaml']:
125+
changed_areas = process_manifest()
126+
for _area in changed_areas:
127+
area_match = maintainer_file.name2areas(_area)
128+
if area_match:
129+
areas.extend(area_match)
130+
else:
131+
areas = maintainer_file.path2areas(changed_file.filename)
88132

89133
if not areas:
90134
continue

0 commit comments

Comments
 (0)