|
2 | 2 |
|
3 | 3 | import json
|
4 | 4 | import os
|
| 5 | +from base64 import b64decode |
5 | 6 | from os.path import dirname, join
|
6 | 7 |
|
7 | 8 | import github3
|
|
21 | 22 | organization = os.getenv("ORGANIZATION")
|
22 | 23 |
|
23 | 24 | # Get all repos from organization
|
24 |
| - search_string = "org:" + organization + " topic:" + topic |
| 25 | + search_string = "org:{} topic:{}".format(organization, topic) |
25 | 26 | all_repos = gh.search_repositories(search_string)
|
26 | 27 | repo_list = []
|
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[ |
| 50 | + "all" |
| 51 | + ] |
| 52 | + |
| 53 | + # fetch contributing guidelines |
| 54 | + try: |
| 55 | + # if CONTRIBUTING.md exists in the repository, link to that instead of repo root |
| 56 | + content = repo.repository.file_contents("/CONTRIBUTING.md").content |
| 57 | + innersource_repo["_InnerSourceMetadata"][ |
| 58 | + "guidelines" |
| 59 | + ] = "CONTRIBUTING.md" |
| 60 | + except github3.exceptions.NotFoundError: |
| 61 | + # CONTRIBUTING.md not found in repository, but it's not required |
| 62 | + pass |
| 63 | + |
| 64 | + # fetch repository topics |
| 65 | + topics = repo.repository.topics() |
| 66 | + innersource_repo["_InnerSourceMetadata"]["topics"] = topics.names |
| 67 | + |
| 68 | + repo_list.append(innersource_repo) |
35 | 69 |
|
36 | 70 | # Write each repository to a repos.json file
|
37 | 71 | with open("repos.json", "w") as f:
|
|
0 commit comments