Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Pytest](https://github.com/Arcadia822/codedog/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/Arcadia822/codedog/actions/workflows/test.yml)
[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Arcadia822/ce38dae58995aeffef42065093fcfe84/raw/codedog_master.json)](https://github.com/Arcadia822/codedog/actions/workflows/test.yml)


Review your Github/Gitlab PR with ChatGPT

![Design](docs/design.png)
Expand All @@ -19,18 +18,18 @@ poetry install --with dev

settings:

| 环境变量 | 是否必要 | 默认值 | 说明 |
| ----------------------- | -------- | ---------------------- | ----------------------------------- |
| CODEDOG_WORKER_NUM | 否 | 1 | 服务线程数 |
| CODEDOG_ENV | 否 | "unknown" | 表明 codedog 实例所属环境 |
| DATADOG_METRIC | 否 | | 值为 True 时向 datadog 发送统计指标 |
| DATADOG_AGENT_HOST | 否 | localhost | datadog agent host |
| DATADOG_DOGSTATSD_PORT | 否 | 8125 | datadog agent dogstatsd port |
| GITHUB_TOKEN | 否 | | 用于连接 github 和评论 |
| GITHUB_APP_ID | 否 | 0 | 用于配置 github app id |
| GITHUB_PRIVATE_KEY_PATH | 否 | "/app/private_key.pem" | 用于生成 github app jwt token |
| OPENAI_API_KEY | 是 | | 调用 OPENAI 的 API KEY |
| OPENAI_PROXY | 否 | | 设置到 openai.proxy |
| 环境变量 | 是否必要 | 默认值 | 说明 |
| ---------------------- | -------- | --------- | ----------------------------------- |
| CODEDOG_WORKER_NUM | 否 | 1 | 服务线程数 |
| CODEDOG_ENV | 否 | "unknown" | 表明 codedog 实例所属环境 |
| DATADOG_METRIC | 否 | | 值为 True 时向 datadog 发送统计指标 |
| DATADOG_AGENT_HOST | 否 | localhost | datadog agent host |
| DATADOG_DOGSTATSD_PORT | 否 | 8125 | datadog agent dogstatsd port |
| GITHUB_TOKEN | 否 | | 用于连接 github 和评论 |
| GITHUB_APP_ID | 否 | 0 | 用于配置 github app id |
| GITHUB_APP_PRIVATE_KEY | 否 | "" | 用于认证 github app |
| OPENAI_API_KEY | 是 | | 调用 OPENAI 的 API KEY |
| OPENAI_PROXY | 否 | | 设置到 openai.proxy |

## Start Server

Expand All @@ -42,5 +41,4 @@ poetry run start

### Github


### Gitlab
3 changes: 1 addition & 2 deletions codedog/adapters/github_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
get_jwt_token,
get_sha256,
get_ttl_hash,
load_private_key,
)

logger = logging.getLogger(__name__)
Expand All @@ -38,7 +37,7 @@

# used for github app
github_app_id = env.get("GITHUB_APP_ID", 0)
github_private_key = load_private_key(env.get("GITHUB_PRIVATE_KEY_PATH", "/app/private_key.pem"))
github_private_key = env.get("GITHUB_APP_PRIVATE_KEY", "")


issue_pattern = re.compile(r"#[0-9]+")
Expand Down
9 changes: 0 additions & 9 deletions codedog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import jwt
import requests
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization

# -- Logging ------------------------------------------------------------------

Expand Down Expand Up @@ -103,10 +101,3 @@ def get_access_token_by_installation_id(installation_id: int, jwt_token: str):
response.raise_for_status()
token_info = response.json()
return token_info["token"]


def load_private_key(filename):
# 从文件中读取你的私钥
with open(filename, "rb") as key_file:
private_key = serialization.load_pem_private_key(key_file.read(), password=None, backend=default_backend())
return private_key
13 changes: 5 additions & 8 deletions examples/github/github_app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from github import Github

from codedog.utils import (
get_access_token_by_installation_id,
get_jwt_token,
load_private_key,
)
from codedog.utils import get_access_token_by_installation_id, get_jwt_token

YOUR_APP_ID = 363842
installation_id = 39837873

private_key = load_private_key('codedogassistant.private-key.pem')

print(private_key)
private_key = """
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
"""

jwt_token = get_jwt_token(private_key, YOUR_APP_ID)

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ uvicorn = "^0.21.1"
pygithub = "^1.58.2"
unidiff = "^0.7.5"
pyjwt = "^2.8.0"
cryptography = "^41.0.2"

[tool.poetry.group.dev]
optional = true
Expand Down