Skip to content

Commit 1d95844

Browse files
committed
Handle missing README files, closes #57
1 parent 54a9849 commit 1d95844

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

github_to_sqlite/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ def fetch_readme(token, full_name, html=False):
763763
headers["accept"] = "application/vnd.github.VERSION.html"
764764
url = "https://api.github.com/repos/{}/readme".format(full_name)
765765
response = requests.get(url, headers=headers)
766-
response.raise_for_status()
766+
if response.status_code != 200:
767+
return None
767768
if html:
768769
return response.text
769770
else:

tests/test_repos.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,33 @@ def test_repos(mocked, tmpdir):
6868
assert repo["full_name"] == "dogsheep/github-to-sqlite"
6969
assert repo["readme"] == "# This is the README"
7070
assert repo["readme_html"] == "<h1>This is the README</h1>"
71+
72+
73+
def test_repos_readme_not_available(requests_mock, tmpdir):
74+
runner = CliRunner()
75+
requests_mock.get(
76+
"https://api.github.com/repos/dogsheep/github-to-sqlite",
77+
json=json.load(open(pathlib.Path(__file__).parent / "repo.json")),
78+
)
79+
requests_mock.get(
80+
"https://api.github.com/repos/dogsheep/github-to-sqlite/readme",
81+
status_code=400,
82+
)
83+
db_path = str(tmpdir / "test.db")
84+
result = runner.invoke(
85+
cli.cli,
86+
[
87+
"repos",
88+
db_path,
89+
"-r",
90+
"dogsheep/github-to-sqlite",
91+
"--readme",
92+
"--readme-html",
93+
],
94+
)
95+
assert 0 == result.exit_code
96+
db = sqlite_utils.Database(db_path)
97+
row = list(db["repos"].rows)[0]
98+
assert row["name"] == "github-to-sqlite"
99+
assert row["readme"] is None
100+
assert row["readme_html"] is None

0 commit comments

Comments
 (0)