Skip to content

Commit 7bc2c84

Browse files
authored
Merge pull request #10 from codedog-ai/feature/read-private-key-from-env
feat: ✨ read github private key from env
2 parents 7fbe9f3 + 1c388f3 commit 7bc2c84

File tree

6 files changed

+19
-35
lines changed

6 files changed

+19
-35
lines changed

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![Pytest](https://github.com/Arcadia822/codedog/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/Arcadia822/codedog/actions/workflows/test.yml)
55
[![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)
66

7-
87
Review your Github/Gitlab PR with ChatGPT
98

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

2019
settings:
2120

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

3534
## Start Server
3635

@@ -42,5 +41,4 @@ poetry run start
4241

4342
### Github
4443

45-
4644
### Gitlab

codedog/adapters/github_adapter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
get_jwt_token,
2626
get_sha256,
2727
get_ttl_hash,
28-
load_private_key,
2928
)
3029

3130
logger = logging.getLogger(__name__)
@@ -38,7 +37,7 @@
3837

3938
# used for github app
4039
github_app_id = env.get("GITHUB_APP_ID", 0)
41-
github_private_key = load_private_key(env.get("GITHUB_PRIVATE_KEY_PATH", "/app/private_key.pem"))
40+
github_private_key = env.get("GITHUB_APP_PRIVATE_KEY", "")
4241

4342

4443
issue_pattern = re.compile(r"#[0-9]+")

codedog/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import jwt
1010
import requests
11-
from cryptography.hazmat.backends import default_backend
12-
from cryptography.hazmat.primitives import serialization
1311

1412
# -- Logging ------------------------------------------------------------------
1513

@@ -103,10 +101,3 @@ def get_access_token_by_installation_id(installation_id: int, jwt_token: str):
103101
response.raise_for_status()
104102
token_info = response.json()
105103
return token_info["token"]
106-
107-
108-
def load_private_key(filename):
109-
# 从文件中读取你的私钥
110-
with open(filename, "rb") as key_file:
111-
private_key = serialization.load_pem_private_key(key_file.read(), password=None, backend=default_backend())
112-
return private_key

examples/github/github_app.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from github import Github
22

3-
from codedog.utils import (
4-
get_access_token_by_installation_id,
5-
get_jwt_token,
6-
load_private_key,
7-
)
3+
from codedog.utils import get_access_token_by_installation_id, get_jwt_token
84

95
YOUR_APP_ID = 363842
106
installation_id = 39837873
117

12-
private_key = load_private_key('codedogassistant.private-key.pem')
13-
14-
print(private_key)
8+
private_key = """
9+
-----BEGIN RSA PRIVATE KEY-----
10+
-----END RSA PRIVATE KEY-----
11+
"""
1512

1613
jwt_token = get_jwt_token(private_key, YOUR_APP_ID)
1714

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ uvicorn = "^0.21.1"
1919
pygithub = "^1.58.2"
2020
unidiff = "^0.7.5"
2121
pyjwt = "^2.8.0"
22-
cryptography = "^41.0.2"
2322

2423
[tool.poetry.group.dev]
2524
optional = true

0 commit comments

Comments
 (0)