forked from clan/clan-infra
Merge pull request 'matrix-bot: Remove __pycache__ dir and fix changelog room' (#205) from Qubasa/clan-infra:Qubasa-main into main
This commit is contained in:
commit
34a284d191
@ -33,7 +33,7 @@ in
|
|||||||
script = ''
|
script = ''
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
mbot
|
mbot --changelog-room "!FdCwyKsRlfooNYKYzx:matrix.org" --review-room "!tmSRJlbsVXFUKAddiM:gchq.icu"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
1
pkgs/matrix-bot/.gitignore
vendored
1
pkgs/matrix-bot/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.json
|
*.json
|
||||||
**/data
|
**/data
|
||||||
|
**/__pycache__
|
||||||
|
@ -119,6 +119,9 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
|
|||||||
|
|
||||||
|
|
||||||
def matrix_password() -> str:
|
def matrix_password() -> str:
|
||||||
|
matrix_password = environ.get("MATRIX_PASSWORD")
|
||||||
|
if matrix_password is not None:
|
||||||
|
return matrix_password
|
||||||
matrix_password_file = environ.get("MATRIX_PASSWORD_FILE", default=None)
|
matrix_password_file = environ.get("MATRIX_PASSWORD_FILE", default=None)
|
||||||
if matrix_password_file is None:
|
if matrix_password_file is None:
|
||||||
raise Exception("MATRIX_PASSWORD_FILE environment variable is not set")
|
raise Exception("MATRIX_PASSWORD_FILE environment variable is not set")
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@ import asyncio
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ def write_file_with_date_prefix(
|
|||||||
|
|
||||||
async def git_pull(repo_path: Path) -> None:
|
async def git_pull(repo_path: Path) -> None:
|
||||||
cmd = ["git", "pull"]
|
cmd = ["git", "pull"]
|
||||||
|
log.debug(f"Running command: {shlex.join(cmd)}")
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmd,
|
*cmd,
|
||||||
cwd=str(repo_path),
|
cwd=str(repo_path),
|
||||||
@ -81,6 +83,7 @@ async def git_log(repo_path: str, ndays: int) -> str:
|
|||||||
"--stat",
|
"--stat",
|
||||||
"--patch",
|
"--patch",
|
||||||
]
|
]
|
||||||
|
log.debug(f"Running command: {shlex.join(cmd)}")
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmd,
|
*cmd,
|
||||||
cwd=repo_path,
|
cwd=repo_path,
|
||||||
@ -133,7 +136,7 @@ async def changelog_bot(
|
|||||||
return
|
return
|
||||||
|
|
||||||
# If you made a new room and haven't joined as that user, you can use
|
# If you made a new room and haven't joined as that user, you can use
|
||||||
room: JoinResponse = await client.join(matrix.review_room)
|
room: JoinResponse = await client.join(matrix.changelog_room)
|
||||||
|
|
||||||
if not room.transport_response.ok:
|
if not room.transport_response.ok:
|
||||||
log.error("This can happen if the room doesn't exist or the bot isn't invited")
|
log.error("This can happen if the room doesn't exist or the bot isn't invited")
|
||||||
@ -160,17 +163,23 @@ async def changelog_bot(
|
|||||||
log.info(f"Generating changelog from {fromdate} to {todate}")
|
log.info(f"Generating changelog from {fromdate} to {todate}")
|
||||||
|
|
||||||
system_prompt = f"""
|
system_prompt = f"""
|
||||||
Generate a concise changelog for the past week from {fromdate} to {todate},
|
Create a concise changelog for the past week from {fromdate} to {todate}.
|
||||||
focusing only on new features and summarizing bug fixes into a single entry.
|
Follow these guidelines:
|
||||||
Ensure the following:
|
|
||||||
|
|
||||||
- Deduplicate entries
|
|
||||||
- Discard uninteresting changes
|
|
||||||
- Keep the summary as brief as possible
|
|
||||||
- Use present tense
|
- Use present tense
|
||||||
- Our commit messages are in the format: "scope: message". For example: "changelog: Add a new feature"
|
- Keep the summary brief
|
||||||
- Only ever mention the same feature once
|
- Follow commit message format: "scope: message (#number)"
|
||||||
The changelog is as follows:
|
- Link pull requests as: '{gitea.url}/{gitea.owner}/{gitea.repo}/pulls/<number>'
|
||||||
|
- Mention each scope and pull request number only once
|
||||||
|
- Have these headers in the changelog if applicable:
|
||||||
|
- New Features
|
||||||
|
- Bug Fixes
|
||||||
|
- Refactoring
|
||||||
|
- Documentation
|
||||||
|
- Removed Features
|
||||||
|
- Other Changes
|
||||||
|
|
||||||
|
Changelog:
|
||||||
---
|
---
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -12,6 +12,10 @@ url: str = "https://api.openai.com/v1/chat/completions"
|
|||||||
|
|
||||||
|
|
||||||
def api_key() -> str:
|
def api_key() -> str:
|
||||||
|
openapi_key = environ.get("OPENAI_API_KEY")
|
||||||
|
if openapi_key is not None:
|
||||||
|
return openapi_key
|
||||||
|
|
||||||
openai_key_file = environ.get("OPENAI_API_KEY_FILE", default=None)
|
openai_key_file = environ.get("OPENAI_API_KEY_FILE", default=None)
|
||||||
if openai_key_file is None:
|
if openai_key_file is None:
|
||||||
raise Exception("OPENAI_API_KEY_FILE environment variable is not set")
|
raise Exception("OPENAI_API_KEY_FILE environment variable is not set")
|
||||||
|
Loading…
Reference in New Issue
Block a user