-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfind_contributors_without_citation.py
138 lines (110 loc) · 3.58 KB
/
find_contributors_without_citation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
Find contributors without citation in the CITATION.cff file.
This script could work in two modes:
1. Find missed contributors fo a given milestone
2. Find missed contributors for the whole project
When pass `--generate` option then script will generate
the missing entries based on GitHub data.
"""
import argparse
import os
from tqdm import tqdm
from yaml import safe_load
from release_utils import (
BOT_LIST,
LOCAL_DIR,
REPO_DIR_NAME,
existing_file,
get_milestone,
get_repo,
iter_pull_request,
setup_cache,
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--milestone', help='The milestone to check', default=''
)
parser.add_argument('--repo', help='The repo to check', action='append')
# parser.add_argument(
# "--additional-repo", help="The additional repo to check", action="append"
# )
parser.add_argument(
'--correction-file',
help='The file with the corrections',
default=LOCAL_DIR / 'name_corrections.yaml',
)
parser.add_argument(
'--citation-path',
help='',
default=str(os.path.join(REPO_DIR_NAME, 'CITATION.cff')),
type=existing_file,
)
parser.add_argument(
'--generate',
help='Generate the missing entries based on github data',
action='store_true',
)
args = parser.parse_args()
if args.repo is None:
args.repo = ['napari/napari', 'napari/docs']
with args.citation_path.open() as f:
citation = safe_load(f)
missing_authors = set()
for repo in args.repo:
missing_authors |= find_missing_authors_for_milestone(
citation, repo, args.milestone
)
if args.generate:
for login, name in sorted(missing_authors):
if name is None:
continue
name, sure_name = name.rsplit(' ', 1)
print(
f'- given-names: {name}\n family-names: {sure_name}\n alias: {login}'
)
else:
for login, name in sorted(missing_authors):
print(f'@{login} ', end='') # ({name})")
print()
def find_missing_authors(citation, repository: str) -> set[tuple[str, str]]:
author_dict = {}
for author in citation['authors']:
author_dict[author['alias']] = author
setup_cache()
missing_authors = set()
contributors = get_repo(*repository.split('/')).get_contributors()
for creator in tqdm(
contributors,
total=contributors.totalCount,
desc=f'finding authors for {repository}',
):
if creator.login in BOT_LIST:
continue
if creator.login not in author_dict:
missing_authors.add((creator.login, creator.name))
return missing_authors
def find_missing_authors_for_milestone(
citation, repository: str, milestone_str: str = ''
) -> set[tuple[str, str]]:
if not milestone_str:
return find_missing_authors(citation, repository)
author_dict = {}
for author in citation['authors']:
author_dict[author['alias']] = author
setup_cache()
milestone = get_milestone(milestone_str, repository)
missing_authors = set()
user, repo = repository.split('/')
for pull in iter_pull_request(
f'milestone:{milestone.title} is:merged', user, repo
):
issue = pull.as_issue()
creator = issue.user
if creator.login in BOT_LIST:
continue
if creator.login not in author_dict:
missing_authors.add((creator.login, creator.name))
return missing_authors
if __name__ == '__main__':
main()