Skip to content

Commit 42dedea

Browse files
authored
Merge pull request #15 from jasonmacgowan/jasonmacgowan/metadata
fetch data for _InnerSourceMetadata
2 parents f8da2b5 + f1c9aa2 commit 42dedea

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

crawler.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
from base64 import b64decode
56
from os.path import dirname, join
67

78
import github3
@@ -21,17 +22,50 @@
2122
organization = os.getenv("ORGANIZATION")
2223

2324
# Get all repos from organization
24-
search_string = "org:" + organization + " topic:" + topic
25+
search_string = "org:{} topic:{}".format(organization, topic)
2526
all_repos = gh.search_repositories(search_string)
2627
repo_list = []
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[
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)
3569

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

0 commit comments

Comments
 (0)