From d9ffaffc55eadc578fcd061e4765757c9c22adc8 Mon Sep 17 00:00:00 2001 From: Mark Likhachev Date: Tue, 13 Sep 2022 11:19:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BD=D0=B0=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/notion.yml | 4 ++-- main.py | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/notion.yml b/.github/workflows/notion.yml index 629bb33..c2fa80a 100644 --- a/.github/workflows/notion.yml +++ b/.github/workflows/notion.yml @@ -15,8 +15,8 @@ jobs: DEBUGGING: true GITHUB2NOTION_PRIORITY: '{"name": "Приоритет", "object": {"select": {"name": "P3"}}}' GITHUB2NOTION_PROJECT: '{"name": "Проект", "object": {"select": {"name": "Olymp Group"}}}' - GITHUB_ASSIGNEES_TO_NOTION: ${{ secrets.GITHUB_ASSIGNEES_TO_NOTION }} - GITHUB_STATUSES_TO_NOTION: ${{ secrets.GITHUB_STATUSES_TO_NOTION }} + GH_ASSIGNEES_TO_NOTION: ${{ secrets.GH_ASSIGNEES_TO_NOTION }} + GH_STATUSES_TO_NOTION: ${{ secrets.GH_STATUSES_TO_NOTION }} LABELS_PROPERTY_NAME: "Вид" NOTION_API_TOKEN: ${{ secrets.NOTION_API_TOKEN }} STATUS_PROPERTY_NAME: "Статус" diff --git a/main.py b/main.py index 65f0c19..775b0fd 100644 --- a/main.py +++ b/main.py @@ -8,18 +8,18 @@ EVENT_PATH = os.environ.get("GITHUB_EVENT_PATH") # Github secrets and environment variables -API_TOKEN = os.environ["NOTION_API_TOKEN"] BRACKET_TYPE = os.environ["BRACKET_TYPE"] DATABASE_ID = os.environ["DATABASE_ID"] DEBUGGING = os.environ.get("DEBUGGING") +NOTION_API_TOKEN = os.environ["NOTION_API_TOKEN"] ASSIGNEES_PROPERTY_NAME = os.environ["ASSIGNEES_PROPERTY_NAME"] LABELS_PROPERTY_NAME = os.environ["LABELS_PROPERTY_NAME"] STATUS_PROPERTY_NAME = os.environ["STATUS_PROPERTY_NAME"] TITLE_PROPERTY_NAME = os.environ["TITLE_PROPERTY_NAME"] -GITHUB_ASSIGNEES_TO_NOTION = json.loads(os.environ.get("GITHUB_ASSIGNEES_TO_NOTION")) -GITHUB_STATUSES_TO_NOTION = json.loads(os.environ["GITHUB_STATUSES_TO_NOTION"]) +GH_ASSIGNEES_TO_NOTION = json.loads(os.environ.get("GH_ASSIGNEES_TO_NOTION")) +GH_STATUSES_TO_NOTION = json.loads(os.environ["GH_STATUSES_TO_NOTION"]) CUSTOM_PROPERTIES = parse_env_variables_to_properties() @@ -28,7 +28,7 @@ "Accept": "application/json", "Notion-Version": "2022-06-28", "Content-Type": "application/json", - "Authorization": f"Bearer {API_TOKEN}", + "Authorization": f"Bearer {NOTION_API_TOKEN}", } # Database @@ -90,7 +90,7 @@ def create_or_update_page( "id": "%24v1Q", "type": "people", "people": [ - {"id": GITHUB_ASSIGNEES_TO_NOTION[assignee]} + {"id": GH_ASSIGNEES_TO_NOTION[assignee]} for assignee in issue_assignees ], }, @@ -103,7 +103,7 @@ def create_or_update_page( } if not page: payload["properties"][STATUS_PROPERTY_NAME] = { - "select": {"name": GITHUB_STATUSES_TO_NOTION["opened"]} + "select": {"name": GH_STATUSES_TO_NOTION["opened"]} } payload = {**PARENT, **payload} @@ -171,9 +171,7 @@ def update_labels(page: dict, labels: list) -> None: def close_issue(page: dict) -> None: payload = { "properties": { - STATUS_PROPERTY_NAME: { - "select": {"name": GITHUB_STATUSES_TO_NOTION["closed"]} - }, + STATUS_PROPERTY_NAME: {"select": {"name": GH_STATUSES_TO_NOTION["closed"]}}, }, } payload = {**PARENT, **payload} @@ -184,7 +182,7 @@ def reopen_issue(page: dict) -> None: payload = { "properties": { STATUS_PROPERTY_NAME: { - "select": {"name": GITHUB_STATUSES_TO_NOTION["reopened"]} + "select": {"name": GH_STATUSES_TO_NOTION["reopened"]} }, }, } @@ -205,7 +203,7 @@ def update_assignees(page, issue_assignees: list) -> None: "id": "%24v1Q", "type": "people", "people": [ - {"id": GITHUB_ASSIGNEES_TO_NOTION[assignee]} + {"id": GH_ASSIGNEES_TO_NOTION[assignee]} for assignee in issue_assignees ] if issue_assignees