(args)
| 97 | |
| 98 | |
| 99 | def create_file(args): |
| 100 | repository_safe = "".join([c for c in args.repository if re.match(r'\w', c)]) |
| 101 | collaborators = get_collaborators(args) |
| 102 | skippable = {collaborator['login'].lower() for collaborator in collaborators} |
| 103 | # Remove people that are in CONTRIBUTORS for some reason or another |
| 104 | skippable.discard('lefticus') |
| 105 | skippable.discard('ubsan') |
| 106 | # Added in the thanks to section of the readme |
| 107 | skippable.update(['filcab', 'voxelf', 'johanengelen', 'jsheard', 'dkm', 'andrewpardoe']) |
| 108 | # Duplicated people under different accounts |
| 109 | skippable.add('jaredadobe') |
| 110 | all_contributors = get_contributors(args) |
| 111 | # People already listed somewhere else. Use set diff? |
| 112 | contributors = [contributor for contributor in all_contributors if contributor['login'].lower() not in skippable] |
| 113 | print('Found {} contributors. Skipping {} collaborators'.format(len(contributors), len(skippable))) |
| 114 | # Create cache folder, which can be cleared at any moment |
| 115 | cache_dir_base = 'contributorer-cache-{}'.format(repository_safe) |
| 116 | if not os.path.isdir(cache_dir_base): |
| 117 | os.mkdir(cache_dir_base) |
| 118 | dprint('Cache base dir: {}'.format(cache_dir_base), args) |
| 119 | cache_dir_commits = '{}/commits'.format(cache_dir_base) |
| 120 | if not os.path.isdir(cache_dir_commits): |
| 121 | os.mkdir(cache_dir_commits) |
| 122 | dprint('Cache commits dir: {}'.format(cache_dir_commits), args) |
| 123 | first_commits = [] |
| 124 | for contributor in contributors: |
| 125 | commits = {} |
| 126 | # Where should the commits for this contributor be? |
| 127 | # This works even if outdated because we are looking for old commits, not new |
| 128 | contrib_file = '{}/{}-commits.json'.format(cache_dir_commits, contributor['login']) |
| 129 | dprint('Checking commits file: {}'.format(contrib_file), args) |
| 130 | if os.path.isfile(contrib_file): |
| 131 | dprint('File found, using as commit source', args) |
| 132 | with open(contrib_file, 'r') as c: |
| 133 | commits = json.load(c) |
| 134 | else: |
| 135 | dprint('None found, querying to GitHub', args) |
| 136 | # TODO: Buffer them and send only 1 request? |
| 137 | result = get_oauth('https://api.github.com/repos/{}/commits'.format(args.repository), args, |
| 138 | params={'author': contributor['login']}) |
| 139 | if result.status_code == 200: |
| 140 | commits = result.json() |
| 141 | dprint('Writing results to file', args) |
| 142 | with open(contrib_file, 'w') as c: |
| 143 | c.write(result.text) |
| 144 | if len(commits) > 0: |
| 145 | first_commit = commits[-1] |
| 146 | dprint( |
| 147 | 'First commit for {} was in {}'.format(contributor['login'], first_commit['commit']['author']['date']), |
| 148 | args |
| 149 | ) |
| 150 | first_commits.append({'date': first_commit['commit']['author']['date'], |
| 151 | 'name': first_commit['commit']['author']['name'] |
| 152 | or '"{}"'.format(first_commit['author']['login']), |
| 153 | 'url': first_commit['author']['html_url']}) |
| 154 | dprint('Sorting commits from oldest to newest', args) |
| 155 | sorted_commits = sorted(first_commits, key=lambda x: PySO8601.parse(x['date'])) |
| 156 | with open(args.output, 'w') as md: |
no test coverage detected