|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
| 3 | +from base64 import b64decode |
3 | 4 | import json
|
4 | 5 | import os
|
5 | 6 | from os.path import dirname, join
|
|
27 | 28 |
|
28 | 29 | for repo in all_repos:
|
29 | 30 | if repo is not None:
|
30 |
| - # TODO: #7 For each resulting project add a key _InnerSourceMetadata |
31 | 31 | print("{0}".format(repo.repository))
|
32 | 32 | full_repository = repo.repository.refresh()
|
33 |
| - # Add stuff here about innersource.json data before appending to list |
34 |
| - repo_list.append(repo.as_dict()) |
| 33 | + |
| 34 | + innersource_repo = repo.as_dict() |
| 35 | + innersource_repo['_InnerSourceMetadata'] = {} |
| 36 | + |
| 37 | + # fetch innersource.json |
| 38 | + try: |
| 39 | + content = repo.repository.file_contents('/innersource.json').content |
| 40 | + metadata = json.loads(b64decode(content)) |
| 41 | + |
| 42 | + innersource_repo['_InnerSourceMetadata'] = metadata |
| 43 | + except github3.exceptions.NotFoundError: |
| 44 | + # innersource.json not found in repository, but it's not required |
| 45 | + pass |
| 46 | + |
| 47 | + # fetch repository participation |
| 48 | + participation = repo.repository.weekly_commit_count() |
| 49 | + innersource_repo['_InnerSourceMetadata']['participation'] = participation['all'] |
| 50 | + |
| 51 | + # fetch contributing guidelines |
| 52 | + try: |
| 53 | + # if CONTRIBUTING.md exists in the repository, link to that instead of repo root |
| 54 | + content = repo.repository.file_contents('/CONTRIBUTING.md').content |
| 55 | + innersource_repo['_InnerSourceMetadata']['guidelines'] = 'CONTRIBUTING.md' |
| 56 | + except github3.exceptions.NotFoundError: |
| 57 | + # CONTRIBUTING.md not found in repository, but it's not required |
| 58 | + pass |
| 59 | + |
| 60 | + # fetch repository topics |
| 61 | + topics = repo.repository.topics() |
| 62 | + innersource_repo['_InnerSourceMetadata']['topics'] = topics.names |
| 63 | + |
| 64 | + repo_list.append(innersource_repo) |
35 | 65 |
|
36 | 66 | # Write each repository to a repos.json file
|
37 | 67 | with open("repos.json", "w") as f:
|
|
0 commit comments