Skip to content

Commit 4c64329

Browse files
committed
fetch data for _InnerSourceMetadata
fixes #7
1 parent 35f517f commit 4c64329

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

crawler.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
from base64 import b64decode
34
import json
45
import os
56
from os.path import dirname, join
@@ -27,11 +28,40 @@
2728

2829
for repo in all_repos:
2930
if repo is not None:
30-
# TODO: #7 For each resulting project add a key _InnerSourceMetadata
3131
print("{0}".format(repo.repository))
3232
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)
3565

3666
# Write each repository to a repos.json file
3767
with open("repos.json", "w") as f:

0 commit comments

Comments
 (0)