Skip to content

Commit

Permalink
Поддержка пользовательских меток Github в Notion
Browse files Browse the repository at this point in the history
  • Loading branch information
memew1se committed Sep 13, 2022
1 parent b742f26 commit 12728c7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)

GH_ASSIGNEES_TO_NOTION = json.loads(os.environ["GH_ASSIGNEES_TO_NOTION"])
GH_LABELS_TO_NOTION = json.loads(os.environ["GH_LABELS_TO_NOTION"])
GH_STATUSES_TO_NOTION = json.loads(os.environ["GH_STATUSES_TO_NOTION"])

# Authentication
Expand Down Expand Up @@ -107,7 +108,9 @@ def create_or_update_page(

if issue_labels:
payload["properties"][LABELS_PROPERTY_NAME] = {
"multi_select": [{"name": label["name"]} for label in issue_labels]
"multi_select": [
{"name": GH_LABELS_TO_NOTION[label["name"]]} for label in issue_labels
]
}
if not page:
payload["properties"][STATUS_PROPERTY_NAME] = {
Expand Down Expand Up @@ -145,10 +148,10 @@ def get_page(issue_number: str) -> dict:
pages_amount = len(results)

if pages_amount != 1:
raise ValueError(
f"Cannot find a specific page. Number of pages found: {pages_amount}. "
print(f"Cannot find a specific page. Number of pages found: {pages_amount}.")
if DEBUGGING:
f"Urls are: {', '.join([page['url'] for page in results])}"
)
raise ValueError("Cannot find a specific page.")
else:
return results[0]

Expand All @@ -168,7 +171,9 @@ def update_labels(page: dict, labels: list) -> None:
payload = {
"properties": {
LABELS_PROPERTY_NAME: {
"multi_select": [{"name": label["name"]} for label in labels]
"multi_select": [
{"name": GH_LABELS_TO_NOTION[label["name"]]} for label in labels
]
},
},
}
Expand Down

0 comments on commit 12728c7

Please sign in to comment.