1+ import yaml
2+ import collections
3+ from pathlib import Path
4+
5+ dependabot = {}
6+ dependabot ['version' ] = 2
7+ dependabot ['updates' ] = []
8+ ignored_folders = ['node_modules' , 'dist' , '.git' , 'deprecated' ]
9+
10+ def get_owners (path ):
11+ while not Path (path / 'OWNERS' ).is_file ():
12+ path = path .parent .absolute ()
13+ with open (path / 'OWNERS' ) as owner_file :
14+ owners = yaml .load (owner_file )
15+ return owners
16+
17+ def get_docker_paths ():
18+ dockerfile_list = list (repo_path .glob ('**/*ockerfile*' ))
19+ docker_clean_list = []
20+ for dockerfile in dockerfile_list :
21+ if all (x not in str (dockerfile ) for x in ignored_folders ):
22+ if dockerfile .parents [0 ] not in docker_clean_list :
23+ docker_clean_list .append (dockerfile .parents [0 ])
24+ return docker_clean_list
25+
26+ def get_npm_paths ():
27+ npm_list = list (repo_path .glob ('**/package*.json' ))
28+ npm_clean_list = []
29+ for npm_file in npm_list :
30+ if all (x not in str (npm_file ) for x in ignored_folders ):
31+ if npm_file .parents [0 ] not in npm_clean_list :
32+ npm_clean_list .append (npm_file .parents [0 ])
33+ return npm_clean_list
34+
35+ def get_pip_paths ():
36+ pip_list = list (repo_path .glob ('**/*requirements.txt' ))
37+ pip_clean_list = []
38+ for pip_file in pip_list :
39+ if all (x not in str (pip_file ) for x in ignored_folders ):
40+ if pip_file .parents [0 ] not in pip_clean_list :
41+ pip_clean_list .append (pip_file .parents [0 ])
42+ return pip_clean_list
43+
44+ def get_go_paths ():
45+ go_list = list (repo_path .glob ('**/go.*' ))
46+ go_clean_list = []
47+ for go_file in go_list :
48+ if all (x not in str (go_file ) for x in ignored_folders ):
49+ if go_file .parents [0 ] not in go_clean_list :
50+ go_clean_list .append (go_file .parents [0 ])
51+ return go_clean_list
52+
53+ def append_updates (ecosystem , directory , assignees , reviewers = None ):
54+ config = {}
55+ config ['package-ecosystem' ] = ecosystem
56+ config ['directory' ] = directory
57+ config ['schedule' ]= {}
58+ config ['schedule' ]['interval' ] = 'daily'
59+ config ['open-pull-requests-limit' ] = 10
60+ config ['assignees' ] = assignees
61+ if reviewers :
62+ config ['reviewers' ] = reviewers
63+ dependabot ['updates' ].append (config )
64+
65+ def main ():
66+ for docker_path in get_docker_paths ():
67+ string_path = str (docker_path )
68+ assignees = get_owners (docker_path ).get ('approvers' )
69+ reviewers = get_owners (docker_path ).get ('reviewers' )
70+ append_updates ('docker' , string_path , assignees , reviewers )
71+
72+ for npm_path in get_npm_paths ():
73+ string_path = str (npm_path )
74+ assignees = get_owners (npm_path ).get ('approvers' )
75+ reviewers = get_owners (npm_path ).get ('reviewers' )
76+ append_updates ('npm' , string_path , assignees , reviewers )
77+
78+ for pip_path in get_pip_paths ():
79+ string_path = str (pip_path )
80+ assignees = get_owners (pip_path ).get ('approvers' )
81+ reviewers = get_owners (pip_path ).get ('reviewers' )
82+ append_updates ('pip' , string_path , assignees , reviewers )
83+
84+ for go_path in get_go_paths ():
85+ string_path = str (go_path )
86+ assignees = get_owners (go_path ).get ('approvers' )
87+ reviewers = get_owners (go_path ).get ('reviewers' )
88+ append_updates ('gomod' , string_path , assignees , reviewers )
89+
90+ with open ('.github/dependabot.yml' , 'w' ) as outfile :
91+ yaml .dump (dependabot , outfile , default_flow_style = False )
92+
93+ print (get_docker_paths ())
94+ print (get_npm_paths ())
95+ print (get_pip_paths ())
96+ print (get_go_paths ())
97+
98+ if __name__ == "__main__" :
99+ repo_path = Path (__file__ ).parents [1 ]
100+ main ()
0 commit comments