pr-proof 0.1.0-beta.0 → 0.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/api/webhook.py +9 -3
- package/app/setup/configure.py +35 -20
- package/app/setup/files.py +15 -4
- package/app/setup/github_setup.py +10 -6
- package/app/setup/setup_pure.py +37 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ npx . start # 서버 실행 (api, worker, smee에서 받아
|
|
|
118
118
|
|
|
119
119
|
configure가 묻는 것은 넷이다.
|
|
120
120
|
|
|
121
|
-
1. 처리할 repo. 예: `octocat/hello-world`. 여럿이면 띄어
|
|
121
|
+
1. 처리할 repo. 예: `octocat/hello-world`. GitHub 주소를 붙여 넣어도 된다. 여럿이면 띄어 쓴다. 대소문자는 GitHub에 적힌 대로 맞춰 넣는다
|
|
122
122
|
2. GitHub 인증 방식: gh 로그인(`gh auth login`을 해 둔 계정) 또는 토큰
|
|
123
123
|
3. 토큰. 토큰 방식일 때만 묻고, 화면에 보이지 않게 입력한다
|
|
124
124
|
4. 웹훅 받는 주소. 없으면 Enter
|
package/app/api/webhook.py
CHANGED
|
@@ -23,9 +23,15 @@ def parse_event(
|
|
|
23
23
|
event: str, payload: dict[str, Any], delivery_id: str | None, allowed_repos: frozenset[str]
|
|
24
24
|
) -> PRJob | Ignored:
|
|
25
25
|
"""GitHub 이벤트를 작업으로 바꾼다. 처리하지 않을 이벤트는 Ignored와 이유를 돌려준다."""
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
sent = (payload.get("repository") or {}).get("full_name")
|
|
27
|
+
# GitHub의 계정·저장소 이름은 대소문자를 가리지 않는다. 설정에 다른 대소문자로 적혀 있어도 같은
|
|
28
|
+
# 저장소이고, 작업에는 설정에 적힌 철자를 쓴다(동기화가 만드는 작업과 같은 이름이 되게)
|
|
29
|
+
repo = next(
|
|
30
|
+
(r for r in allowed_repos if isinstance(sent, str) and r.casefold() == sent.casefold()),
|
|
31
|
+
None,
|
|
32
|
+
)
|
|
33
|
+
if repo is None:
|
|
34
|
+
return Ignored(f"허용 목록에 없는 리포: {sent}")
|
|
29
35
|
action = payload.get("action")
|
|
30
36
|
|
|
31
37
|
if event == "pull_request":
|
package/app/setup/configure.py
CHANGED
|
@@ -216,11 +216,13 @@ def _secret(directory: Path) -> str | None:
|
|
|
216
216
|
|
|
217
217
|
|
|
218
218
|
def check_access(run: gh.Runner, repos: Sequence[str], io: Io) -> list[str]:
|
|
219
|
-
"""읽을 수 있는 repo
|
|
219
|
+
"""읽을 수 있는 repo만, GitHub이 적는 정식 이름으로 돌려준다(대소문자가 사용자가 적은 것과 다를
|
|
220
|
+
수 있다. 웹훅 소식에는 정식 이름이 온다). 못 읽는 것과 쓸 수 없는 것을 말한다."""
|
|
220
221
|
readable = []
|
|
221
|
-
for
|
|
222
|
+
for given in repos:
|
|
223
|
+
repo = given
|
|
222
224
|
try:
|
|
223
|
-
read, write = gh.repo_access(run,
|
|
225
|
+
read, write, repo = gh.repo_access(run, given)
|
|
224
226
|
except gh.NoPermission:
|
|
225
227
|
io.say(f" {repo}: 찾지 못했거나 읽을 권한이 없습니다")
|
|
226
228
|
continue
|
|
@@ -231,6 +233,8 @@ def check_access(run: gh.Runner, repos: Sequence[str], io: Io) -> list[str]:
|
|
|
231
233
|
io.say(f" {repo}: 읽을 권한이 없습니다")
|
|
232
234
|
continue
|
|
233
235
|
readable.append(repo)
|
|
236
|
+
if repo != given:
|
|
237
|
+
io.say(f" {given} → {repo} (GitHub에 적힌 이름으로 넣습니다)")
|
|
234
238
|
if write:
|
|
235
239
|
io.say(f" {repo}: 읽기·쓰기 권한 있음")
|
|
236
240
|
else:
|
|
@@ -332,12 +336,16 @@ def _programs(io: Io, deps: Deps) -> None:
|
|
|
332
336
|
|
|
333
337
|
def _install(directory: Path, io: Io, deps: Deps, opts: Options) -> str:
|
|
334
338
|
_step(io, 3, "설치 (포트, Redis)")
|
|
335
|
-
|
|
336
|
-
|
|
339
|
+
saved = files.saved_port(directory)
|
|
340
|
+
port = opts.port or saved or files.DEFAULT_PORT
|
|
341
|
+
# 이 설정이 이미 쓰던 포트에서 pr-proof가 돌고 있으면 다시 돌린 configure의 자기 서버다. 저장한
|
|
342
|
+
# 적 없는 포트에서 도는 pr-proof는 다른 설정의 서버라 겹친다
|
|
343
|
+
while deps.port_busy(port) and not (port == saved and deps.pr_proof_on(port)):
|
|
344
|
+
who = "다른 pr-proof 서버가" if deps.pr_proof_on(port) else "다른 프로그램이"
|
|
337
345
|
if not io.interactive:
|
|
338
|
-
io.say(f" 포트 {port}를
|
|
346
|
+
io.say(f" 포트 {port}를 {who} 쓰고 있습니다. --port로 다른 번호를 주세요.")
|
|
339
347
|
raise Stop
|
|
340
|
-
answer = _ask_until(io, f" 포트 {port}를
|
|
348
|
+
answer = _ask_until(io, f" 포트 {port}를 {who} 쓰고 있습니다. 쓸 번호: ",
|
|
341
349
|
lambda a: None if a.isdigit() and 0 < int(a) < 65536
|
|
342
350
|
else "1에서 65535 사이의 번호를 적습니다") # fmt: skip
|
|
343
351
|
port = int(answer)
|
|
@@ -459,7 +467,7 @@ def _claude(io: Io, deps: Deps) -> None:
|
|
|
459
467
|
|
|
460
468
|
def _repos(directory: Path, io: Io, run: gh.Runner, opts: Options) -> list[str]:
|
|
461
469
|
_step(io, 6, "repo 등록과 권한 확인")
|
|
462
|
-
repos = list(dict.fromkeys(opts.repos))
|
|
470
|
+
repos = list(dict.fromkeys(pure.repo_name(r) for r in opts.repos))
|
|
463
471
|
try:
|
|
464
472
|
existing = pure.config_repos(_config_text(directory))
|
|
465
473
|
except pure.ConfigEditError as e:
|
|
@@ -473,7 +481,7 @@ def _repos(directory: Path, io: Io, run: gh.Runner, opts: Options) -> list[str]:
|
|
|
473
481
|
io, f" 처리할 repo (예: {pure.REPO_EXAMPLE}, 여럿이면 띄어 쓴다): ",
|
|
474
482
|
lambda a: _repos_problem(a.split()),
|
|
475
483
|
) # fmt: skip
|
|
476
|
-
repos = answer.split()
|
|
484
|
+
repos = list(dict.fromkeys(pure.repo_name(r) for r in answer.split()))
|
|
477
485
|
if problem := _repos_problem(repos or existing):
|
|
478
486
|
io.say(f" {problem}")
|
|
479
487
|
raise Stop
|
|
@@ -481,10 +489,15 @@ def _repos(directory: Path, io: Io, run: gh.Runner, opts: Options) -> list[str]:
|
|
|
481
489
|
if len(readable) < len(repos):
|
|
482
490
|
io.say(" 읽을 수 없는 repo는 허용 목록에 더하지 않았습니다. 이름과 권한을 확인하세요.")
|
|
483
491
|
raise Stop
|
|
492
|
+
repos = readable # 정식 이름
|
|
484
493
|
add_to_config(directory, repos, io, opts.dry_run)
|
|
485
|
-
if
|
|
486
|
-
|
|
487
|
-
|
|
494
|
+
others = [r for r in existing if pure.spelled_as(r, repos) is None]
|
|
495
|
+
if others:
|
|
496
|
+
check_access(run, others, io)
|
|
497
|
+
# 목록에 대소문자만 다르게 적혀 있던 것은 그 철자를 둔다(서버는 대소문자를 가리지 않고 맞춘다)
|
|
498
|
+
return list(
|
|
499
|
+
dict.fromkeys(existing + [r for r in repos if pure.spelled_as(r, existing) is None])
|
|
500
|
+
)
|
|
488
501
|
|
|
489
502
|
|
|
490
503
|
def _webhook_url(directory: Path, io: Io, deps: Deps, opts: Options) -> str:
|
|
@@ -569,7 +582,7 @@ def configure(opts: Options, io: Io, deps: Deps, directory: Path | None = None)
|
|
|
569
582
|
io.say("웹훅을 모두 등록하지는 못했습니다. 위의 값으로 손으로 등록하세요.")
|
|
570
583
|
if not checks_ok:
|
|
571
584
|
io.say("끝 확인에 실패한 줄이 있습니다. 고친 뒤 npx pr-proof configure를 다시 실행하세요.")
|
|
572
|
-
io.say("다음: npx
|
|
585
|
+
io.say(f"다음: {'npx . start' if files.in_clone() else 'npx pr-proof start'}")
|
|
573
586
|
io.say(f"계속 띄워 두려면: {OPERATIONS_URL}")
|
|
574
587
|
# 손으로 등록하라고 한 것(--manual-webhook)은 실패가 아니다
|
|
575
588
|
return 0 if checks_ok and (hooks_ok or opts.manual_webhook) else 1
|
|
@@ -594,14 +607,15 @@ def add(opts: Options, io: Io, deps: Deps, directory: Path | None = None) -> int
|
|
|
594
607
|
if not gh.auth_ok(run, token_mode=github_auth.uses_token(directory)):
|
|
595
608
|
io.say(f"GitHub 인증이 되지 않습니다 → {github_auth.hint(directory)}")
|
|
596
609
|
return 1
|
|
597
|
-
|
|
598
|
-
|
|
610
|
+
wanted = list(dict.fromkeys(pure.repo_name(r) for r in opts.repos))
|
|
611
|
+
readable = check_access(run, wanted, io)
|
|
612
|
+
if len(readable) < len(wanted):
|
|
599
613
|
io.say("읽을 수 없는 repo가 있어 아무것도 더하지 않았습니다.")
|
|
600
614
|
return 1
|
|
601
|
-
added = add_to_config(directory,
|
|
615
|
+
added = add_to_config(directory, readable, io, opts.dry_run)
|
|
602
616
|
if opts.webhook_url and opts.webhook_url != saved and not opts.dry_run:
|
|
603
617
|
files.write_private(directory / files.WEBHOOK_URL_FILE, opts.webhook_url, replace=True)
|
|
604
|
-
hooks_ok = ensure_hooks(run,
|
|
618
|
+
hooks_ok = ensure_hooks(run, readable, url, directory, io, opts)
|
|
605
619
|
except Stop:
|
|
606
620
|
return 1
|
|
607
621
|
if added and not opts.dry_run:
|
|
@@ -620,9 +634,10 @@ def remove(opts: Options, io: Io, deps: Deps, directory: Path | None = None) ->
|
|
|
620
634
|
return 1
|
|
621
635
|
text = path.read_text()
|
|
622
636
|
current = pure.config_repos(text)
|
|
623
|
-
|
|
624
|
-
for
|
|
625
|
-
|
|
637
|
+
names = list(dict.fromkeys(pure.repo_name(r) for r in opts.repos))
|
|
638
|
+
targets = list(dict.fromkeys(s for r in names if (s := pure.spelled_as(r, current))))
|
|
639
|
+
for repo in names:
|
|
640
|
+
if pure.spelled_as(repo, current) is None:
|
|
626
641
|
io.say(f" {repo}: 허용 목록에 없습니다. 아무것도 하지 않습니다.")
|
|
627
642
|
if not targets:
|
|
628
643
|
return 0
|
package/app/setup/files.py
CHANGED
|
@@ -70,18 +70,29 @@ def read_private(name: str, directory: Path | None = None) -> str | None:
|
|
|
70
70
|
return config.read_secret(name, directory)
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def
|
|
74
|
-
"""`pr-proof.env
|
|
73
|
+
def saved_port(directory: Path | None = None) -> int | None:
|
|
74
|
+
"""`pr-proof.env`에 적어 둔 API_PORT. 파일이 없거나 값이 없으면 None."""
|
|
75
75
|
path = (directory or config_dir()) / RUN_ENV_FILE
|
|
76
76
|
try:
|
|
77
77
|
lines = path.read_text().splitlines()
|
|
78
78
|
except OSError:
|
|
79
|
-
return
|
|
79
|
+
return None
|
|
80
80
|
for line in lines:
|
|
81
81
|
key, _, value = line.partition("=")
|
|
82
82
|
if key.strip() == PORT_KEY and value.strip().isdigit():
|
|
83
83
|
return int(value.strip())
|
|
84
|
-
return
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def read_port(directory: Path | None = None) -> int:
|
|
88
|
+
"""`pr-proof.env`의 API_PORT. 없거나 읽지 못하면 기본값."""
|
|
89
|
+
return saved_port(directory) or DEFAULT_PORT
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def in_clone() -> bool:
|
|
93
|
+
"""저장소를 clone한 폴더에서 도는지(`npx . <명령>`). 아니면 npm으로 받은 패키지다
|
|
94
|
+
(`npx pr-proof <명령>`). 입구(bin/pr-proof.js)의 venv 위치와 같은 기준이다."""
|
|
95
|
+
return (PACKAGE_ROOT / ".git").exists()
|
|
85
96
|
|
|
86
97
|
|
|
87
98
|
def write_port(port: int, directory: Path | None = None) -> None:
|
|
@@ -72,16 +72,20 @@ def login(run: Runner) -> str:
|
|
|
72
72
|
return run(["api", "user", "--jq", ".login"], None).strip()
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def repo_access(run: Runner, repo: str) -> tuple[bool, bool]:
|
|
76
|
-
"""(읽기,
|
|
75
|
+
def repo_access(run: Runner, repo: str) -> tuple[bool, bool, str]:
|
|
76
|
+
"""(읽기, 쓰기, GitHub이 적는 정식 이름). 저장소가 보이지 않으면 NoPermission.
|
|
77
|
+
|
|
78
|
+
정식 이름(`full_name`)은 대소문자가 사용자가 적은 것과 다를 수 있다. GitHub은 웹훅 소식에 정식
|
|
79
|
+
이름을 적어 보내므로 허용 목록에는 이 이름을 넣는다.
|
|
77
80
|
|
|
78
81
|
GitHub이 주는 것은 계정의 저장소 권한(`permissions.push`)이다. fine-grained 토큰에서 그 토큰에
|
|
79
82
|
준 권한이 모자란지는 실제로 쓰기 전에는 알 수 없다(README의 권한 목록을 본다).
|
|
80
83
|
"""
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
pull,
|
|
84
|
-
|
|
84
|
+
jq = "[.permissions.pull, .permissions.push, .full_name] | @tsv"
|
|
85
|
+
out = run(["api", f"repos/{repo}", "--jq", jq], None)
|
|
86
|
+
pull, push, name = [*out.strip().split("\t"), "", "", ""][:3]
|
|
87
|
+
# 이름을 바꾼 저장소는 옛 이름으로 물어도 새 이름이 온다. 그 이름이 웹훅 소식에 적힌다
|
|
88
|
+
return pull == "true", push == "true", name.strip() or repo
|
|
85
89
|
|
|
86
90
|
|
|
87
91
|
def list_hooks(run: Runner, repo: str) -> list[Hook]:
|
package/app/setup/setup_pure.py
CHANGED
|
@@ -46,11 +46,39 @@ class ConfigEditError(ValueError):
|
|
|
46
46
|
"""config.yaml의 repos를 줄 단위로 고칠 수 없다. 손으로 고쳐야 한다."""
|
|
47
47
|
|
|
48
48
|
|
|
49
|
+
# 브라우저나 git에서 복사한 GitHub 주소: https://github.com/a/b, github.com/a/b.git,
|
|
50
|
+
# git@github.com:a/b.git
|
|
51
|
+
_GITHUB_URL: Final = re.compile(
|
|
52
|
+
r"(?:(?:https?://)?(?:www\.)?github\.com/|git@github\.com:)([^/\s]+)/([^/\s?#]+)(?:[/?#].*)?",
|
|
53
|
+
re.IGNORECASE,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def repo_name(text: str) -> str:
|
|
58
|
+
"""사용자가 적은 repo를 `계정/저장소이름`으로. GitHub 주소를 붙여 넣은 것도 받는다(끝의 `.git`과
|
|
59
|
+
뒤의 경로는 뗀다). 주소가 아니면 앞뒤 공백만 뗀 그대로다(꼴은 `repo_problem`이 본다)."""
|
|
60
|
+
text = text.strip()
|
|
61
|
+
if found := _GITHUB_URL.fullmatch(text):
|
|
62
|
+
return f"{found.group(1)}/{found.group(2).removesuffix('.git')}"
|
|
63
|
+
return text
|
|
64
|
+
|
|
65
|
+
|
|
49
66
|
def repo_problem(text: str) -> str | None:
|
|
50
|
-
"""repo
|
|
51
|
-
|
|
67
|
+
"""repo가 `계정/저장소이름` 꼴도 GitHub 주소도 아니면 그 안내."""
|
|
68
|
+
name = repo_name(text)
|
|
69
|
+
if _REPO.fullmatch(name) and name.split("/")[1] not in (".", ".."):
|
|
52
70
|
return None
|
|
53
|
-
return
|
|
71
|
+
return (
|
|
72
|
+
f"repo는 `계정/저장소이름` 꼴이나 GitHub 주소로 적습니다 (예: {REPO_EXAMPLE}). "
|
|
73
|
+
f"받은 값: {text!r}"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def spelled_as(name: str, known: Sequence[str]) -> str | None:
|
|
78
|
+
"""known 중 name과 대소문자만 다른(또는 같은) 것. GitHub의 계정과 저장소 이름은 대소문자를
|
|
79
|
+
가리지 않는다."""
|
|
80
|
+
wanted = name.casefold()
|
|
81
|
+
return next((k for k in known if k.casefold() == wanted), None)
|
|
54
82
|
|
|
55
83
|
|
|
56
84
|
# --- config.yaml ---
|
|
@@ -129,7 +157,10 @@ def add_repos(text: str, repos: Sequence[str]) -> tuple[str, list[str]]:
|
|
|
129
157
|
돌려준다."""
|
|
130
158
|
before = _load(text)
|
|
131
159
|
current = list(before.get("repos") or [])
|
|
132
|
-
new = [
|
|
160
|
+
new = []
|
|
161
|
+
for r in dict.fromkeys(repos): # 대소문자만 다른 것은 이미 있는 것이다
|
|
162
|
+
if spelled_as(r, [*current, *new]) is None:
|
|
163
|
+
new.append(r)
|
|
133
164
|
if not new:
|
|
134
165
|
return text, []
|
|
135
166
|
lines = text.splitlines(keepends=True)
|
|
@@ -159,7 +190,8 @@ def remove_repos(text: str, repos: Sequence[str]) -> tuple[str, list[str]]:
|
|
|
159
190
|
읽힌다. `repos:`만 남으면 null이라 서버가 시작하지 못한다)."""
|
|
160
191
|
before = _load(text)
|
|
161
192
|
current = list(before.get("repos") or [])
|
|
162
|
-
|
|
193
|
+
# 목록에 적힌 철자로 찾는다(대소문자만 다르게 적어도 뺀다)
|
|
194
|
+
gone = list(dict.fromkeys(s for r in repos if (s := spelled_as(r, current)) is not None))
|
|
163
195
|
if not gone:
|
|
164
196
|
return text, []
|
|
165
197
|
left = [r for r in current if r not in gone]
|