Skip to content

Commit

Permalink
fix(github): create_file to accept org and token
Browse files Browse the repository at this point in the history
  • Loading branch information
10zinten committed Oct 23, 2020
1 parent c5cb9bd commit 7bf1562
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
13 changes: 11 additions & 2 deletions openpecha/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _add_id_url(self, row):
row[0] = f"[{id}](https://github.com/{self.org}/{id})"
return row

def update_catalog(self):
def update(self):
"""Updates the catalog csv to have new opf-pechas metadata"""
# update last_id
content = self.batch[-1][0].strip()
Expand All @@ -67,6 +67,8 @@ def update_catalog(self):
content,
"update last id of Pecha",
update=True,
org=self.org,
token=self.token,
)

# update last_id
Expand All @@ -77,7 +79,14 @@ def update_catalog(self):
"\n".join([",".join(row) for row in map(self._add_id_url, self.batch)])
+ "\n"
)
create_file(self.repo_name, self.batch_path, content, "create new batch")
create_file(
self.repo_name,
self.batch_path,
content,
"create new batch",
org=self.org,
token=self.token,
)
print("[INFO] Updated the catalog")

# reset the batch
Expand Down
12 changes: 10 additions & 2 deletions openpecha/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,16 @@ def github_publish(
commit(local_repo, message, not_includes, branch=layer)


def create_file(repo_name, path, content, msg, update=False):
repo = get_github_repo(repo_name)
def create_file(
repo_name,
path,
content,
msg,
update=False,
org="OpenPecha",
token=os.environ.get("GITHUB_TOKEN"),
):
repo = get_github_repo(repo_name, org, token)
if update:
old_content = repo.get_contents(path)
repo.update_file(old_content.path, msg, content, old_content.sha)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ def test_googleocr():

@pytest.mark.skip(reason="no urgent")
def test_hfml_with_metadata():
metadata = {"source_metadata": {"title": "example-title"}}
metadata = {
"source_metadata": {
"title": "example-title",
"subtitle": "v001",
"author": "authors",
"id": "2323",
}
}
layers = ["Citation", "BookTitle", "Author"]
catalog = CatalogManager(
formatter=HFMLFormatter(output_path="./output", metadata=metadata),
layers=layers,
)
catalog.add_hfml_item("./tests/data/formatter/hfml/P0001")
catalog.update()


if __name__ == "__main__":
Expand Down

0 comments on commit 7bf1562

Please sign in to comment.