From 0952f2f7fb0dc85eae16ff1d708473080cec5ebd Mon Sep 17 00:00:00 2001 From: Ovsyannikov Dmitrii Date: Wed, 10 Apr 2024 23:57:35 +0200 Subject: [PATCH] ci: add github-watcher action (#22) * fix: change release job id * fix: github clients logging * ci: add github-watcher action --- .github/github-watcher-config.yaml | 30 +++++++++++++++++++++++++++ .github/workflows/github-watcher.yaml | 29 ++++++++++++++++++++++++++ .github/workflows/release.yaml | 2 +- backend/lib/github/clients/gql.py | 4 ++++ backend/lib/github/clients/rest.py | 2 +- 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .github/github-watcher-config.yaml create mode 100644 .github/workflows/github-watcher.yaml diff --git a/.github/github-watcher-config.yaml b/.github/github-watcher-config.yaml new file mode 100644 index 0000000..095ddcc --- /dev/null +++ b/.github/github-watcher-config.yaml @@ -0,0 +1,30 @@ +tasks: + - id: self + triggers: + - id: github + type: github + token_secret: + type: env + key: GITHUB_TOKEN + owner: ovsds + repos: + - github-watcher + subtriggers: + - type: repository_issue_created + exclude_author: + - ovsds + - type: repository_pr_created + exclude_author: + - ovsds + - type: repository_failed_workflow_run + exclude: + - Check PR + actions: + - id: telegram_webhook + type: telegram_webhook + chat_id_secret: + type: env + key: TELEGRAM_CHAT_ID + token_secret: + type: env + key: TELEGRAM_TOKEN diff --git a/.github/workflows/github-watcher.yaml b/.github/workflows/github-watcher.yaml new file mode 100644 index 0000000..8364758 --- /dev/null +++ b/.github/workflows/github-watcher.yaml @@ -0,0 +1,29 @@ +name: Github Watcher + +concurrency: + group: ${{ github.workflow }} + +on: + schedule: + - cron: "*/5 * * * *" # every 5 minutes + workflow_dispatch: + +jobs: + run-github-watcher: + runs-on: ubuntu-20.04 + + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run + uses: ovsds/github-watcher-action@main + with: + config_path: .github/github-watcher-config.yaml + env_variables: | + GITHUB_TOKEN=${{ secrets.PERSONAL_GITHUB_TOKEN }} + TELEGRAM_TOKEN=${{ secrets.TELEGRAM_TOKEN }} + TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 94fc5d8..aa428de 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,7 +6,7 @@ on: - published jobs: - deploy: + release: runs-on: ubuntu-20.04 permissions: diff --git a/backend/lib/github/clients/gql.py b/backend/lib/github/clients/gql.py index 90d1f28..0df34fb 100644 --- a/backend/lib/github/clients/gql.py +++ b/backend/lib/github/clients/gql.py @@ -2,6 +2,7 @@ import contextlib import dataclasses import datetime +import logging import typing import gql @@ -12,6 +13,8 @@ import lib.github.models as github_models +logger = logging.getLogger(__name__) + class BaseRequest(abc.ABC): document: graphql.DocumentNode = NotImplemented @@ -199,6 +202,7 @@ async def gql_client(self) -> typing.AsyncGenerator[gql.Client, None]: await gql_transport.close() async def _request(self, request: BaseRequest, response_model: type[ResponseT]) -> ResponseT: + logger.debug("Requesting document(%s) params(%s)", request.document, request.params) async with self.gql_client() as gql_client: response = await gql_client.execute_async( document=request.document, diff --git a/backend/lib/github/clients/rest.py b/backend/lib/github/clients/rest.py index f419f01..1104e2e 100644 --- a/backend/lib/github/clients/rest.py +++ b/backend/lib/github/clients/rest.py @@ -111,7 +111,7 @@ async def _request( "Authorization": f"Bearer {self._token}", "Accept": "application/vnd.github.v3+json", } - logger.info("Requesting method(%s) url(%s) params(%s)", request.method, request.url, request.params) + logger.debug("Requesting method(%s) url(%s) params(%s)", request.method, request.url, request.params) async with self._aiohttp_client.request( method=request.method, url=request.url,