From e5ce2d636973bc97a1a79960f4acaec8c17d3089 Mon Sep 17 00:00:00 2001 From: Kazuhiro Oka Date: Sun, 16 Nov 2025 23:55:47 +0900 Subject: [PATCH 1/2] add: github action (#8) --- .github/CODEOWNERS | 1 + .github/workflows/close_pr_from_main.yml | 37 +++++++++++++++++++++ .github/workflows/close_pr_to_main.yml | 42 ++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/close_pr_from_main.yml create mode 100644 .github/workflows/close_pr_to_main.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..9eee8f7 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @KO1231 \ No newline at end of file diff --git a/.github/workflows/close_pr_from_main.yml b/.github/workflows/close_pr_from_main.yml new file mode 100644 index 0000000..7c77452 --- /dev/null +++ b/.github/workflows/close_pr_from_main.yml @@ -0,0 +1,37 @@ +name: Close Pull Requests from main +on: + pull_request_target: + types: + - opened + - reopened + - edited + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + close_pr_from_main: + runs-on: ubuntu-latest + if: github.head_ref == 'main' + steps: + - name: Close PR + uses: actions/github-script@v7 + with: + script: | + const commentParams = { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: 'Pull request from main branch is restricted.', + }; + const closeParams = { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + state: 'closed', + }; + + await github.rest.issues.createComment(commentParams); + await github.rest.pulls.update(closeParams); \ No newline at end of file diff --git a/.github/workflows/close_pr_to_main.yml b/.github/workflows/close_pr_to_main.yml new file mode 100644 index 0000000..1ca5925 --- /dev/null +++ b/.github/workflows/close_pr_to_main.yml @@ -0,0 +1,42 @@ +name: Close Pull Requests to main +on: + pull_request_target: + branches: + - main + types: + - opened + - reopened + - edited + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + close_pr_to_main: + runs-on: ubuntu-latest + if: | + github.head_ref != 'develop' && + github.head_ref != 'hotfix' && + !startsWith(github.head_ref, 'hotfix/') + steps: + - name: Close PR + uses: actions/github-script@v7 + with: + script: | + const commentParams = { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: 'Pull request to main branch from this branch is restricted.', + }; + const closeParams = { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + state: 'closed', + }; + + await github.rest.issues.createComment(commentParams); + await github.rest.pulls.update(closeParams); \ No newline at end of file From 77cb4d41e6672a6448511eb50df4f0088ceee75e Mon Sep 17 00:00:00 2001 From: Kazuhiro Oka Date: Sun, 16 Nov 2025 23:56:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=AEbody=E3=81=8C\u=3F=3F=3F=3F=E8=A1=A8=E8=A8=98?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=82=8B=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classifier/classifier_gptoss.py | 2 +- .../classifier/classifier_openai.py | 4 ++-- .../classifier/email_priority_classifier.py | 2 +- email_priority_classifier/type/classified_email_data.py | 9 +++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/email_priority_classifier/classifier/classifier_gptoss.py b/email_priority_classifier/classifier/classifier_gptoss.py index a975616..9a9b633 100644 --- a/email_priority_classifier/classifier/classifier_gptoss.py +++ b/email_priority_classifier/classifier/classifier_gptoss.py @@ -63,7 +63,7 @@ def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority: input=request_input ) - logger.debug(f"GPTOSS request_data: {json.dumps(request_input, indent=2)}") + logger.debug(f"GPTOSS request_data: {json.dumps(request_input, indent=2, ensure_ascii=False)}") except Exception as e: raise EmailPriorityClassifierOpenAIException("Some error occurred while calling the GPTOSS API.") from e diff --git a/email_priority_classifier/classifier/classifier_openai.py b/email_priority_classifier/classifier/classifier_openai.py index 3f82ce2..eda4611 100644 --- a/email_priority_classifier/classifier/classifier_openai.py +++ b/email_priority_classifier/classifier/classifier_openai.py @@ -28,7 +28,7 @@ def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority: try: data = { "thread_subject": thread_messages[0].subject, - "thread_messages": super()._encode_thread_messages(thread_messages)[:1500], # 大体4000前後input-tokenくらい + "thread_messages": super()._encode_thread_messages(thread_messages)[:2500], # 大体4000前後input-tokenくらい } response = _CLIENT.responses.create( # model="gpt-5-nano", @@ -41,7 +41,7 @@ def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority: } ) - logger.debug(f"OpenAPI request_data: {json.dumps(data, indent=2)}") + logger.debug(f"OpenAPI request_data: {json.dumps(data, indent=2, ensure_ascii=False)}") except Exception as e: raise EmailPriorityClassifierOpenAIException("Some error occurred while calling the OpenAI API.") from e diff --git a/email_priority_classifier/classifier/email_priority_classifier.py b/email_priority_classifier/classifier/email_priority_classifier.py index 6a7ffca..39ebf41 100644 --- a/email_priority_classifier/classifier/email_priority_classifier.py +++ b/email_priority_classifier/classifier/email_priority_classifier.py @@ -12,7 +12,7 @@ def _encode_thread_messages(thread_messages: list[ClassifiedEmailData]) -> str: return json.dumps({ "labels": list(labels), "messages": thread_messages - }, cls=ClassifiedEmailDataEncoder) + }, cls=ClassifiedEmailDataEncoder, ensure_ascii=False) @abstractmethod def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority: diff --git a/email_priority_classifier/type/classified_email_data.py b/email_priority_classifier/type/classified_email_data.py index 6f1f7aa..2a1086f 100644 --- a/email_priority_classifier/type/classified_email_data.py +++ b/email_priority_classifier/type/classified_email_data.py @@ -37,7 +37,8 @@ def _extract_subject_from_payload(payload: dict) -> str: @staticmethod def _decode_body(body: str, headers: list[dict]) -> str: - return base64.urlsafe_b64decode(body).decode("utf-8") + return (base64.urlsafe_b64decode(body).decode("utf-8") + .replace("\r", "").replace("\n", "").replace("\t", "")) """ for header in headers: if header.get("name", "").lower() == 'content-transfer-encoding': @@ -61,7 +62,7 @@ def get_data(self) -> str: body = payload.get("body", {}) if len(body) != 0 and body.get("size", 0) != 0: data = self._decode_body(body["data"], payload.get("headers", [])) - return json.dumps(data) + return data text_parts = [part for part in payload.get("parts", []) if part.get("mimeType", "").startswith("text/")] if len(text_parts) == 0: @@ -75,9 +76,9 @@ def get_data(self) -> str: if body_data is None: return "body data could not found." data = self._decode_body(text_part["body"]["data"], text_part.get("headers", [])) - return json.dumps(data) + return data - return json.dumps(text_parts[0]) + return json.dumps(text_parts[0], ensure_ascii=False) @classmethod def init(cls, message: dict, personal_labels_info: dict[str, str]) -> "ClassifiedEmailData":