From 28df1289c448cc06bf79744ee854a8c0fb0850cb Mon Sep 17 00:00:00 2001 From: Norio Tamaru Date: Mon, 25 May 2026 15:13:06 +0900 Subject: [PATCH] Improve PR body clipboard handling --- README.md | 2 +- prompts/codex_task_template.md | 4 ++ scripts/publish_pr.ps1 | 68 +++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 56b212e..a55785b 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ PR作業の開始、公開準備、merge後の同期を補助します。 .\scripts\sync_after_merge.ps1 -Branch codex/example-task ``` -`publish_pr.ps1` は確認後に `git commit` と `git push` を実行します。PR作成とmergeは自動実行しません。 +`publish_pr.ps1` は確認後に `git commit` と `git push` を実行し、`pr_body.md` の生成、クリップボード確認、PR作成URLの表示を行います。クリップボード確認に失敗した場合は `pr_body.md` を開きます。PR作成とmergeは自動実行しません。 ## mock TCPサーバーの使い方 diff --git a/prompts/codex_task_template.md b/prompts/codex_task_template.md index c6f264a..e43ff28 100644 --- a/prompts/codex_task_template.md +++ b/prompts/codex_task_template.md @@ -26,6 +26,10 @@ - `logs/real_device/` は実機ログ保存用であり、pytest一時領域には使わない。 - 不明な通信仕様は推測で実装しない。 - 通信仕様に関わる変更が必要な場合は、根拠となる資料と確認事項を先に提示する。 +- PowerShellでの確認コマンドは、原則としてCodex側で実行する。 +- ユーザーに `git status`、`git branch --show-current`、`.\scripts\dev_check.ps1`、`.\scripts\git_preflight.ps1` などを毎回コピペさせない。 +- 実行に承認が必要な操作がある場合は、個別に何度も聞かず、作業内容をまとめて1回だけ確認する。 +- 実機通信、`git commit`、`git push`、PR作成、merge は明示許可がない限り実行しない。 ## 変更後の報告項目 diff --git a/scripts/publish_pr.ps1 b/scripts/publish_pr.ps1 index 9313a47..4244fe5 100644 --- a/scripts/publish_pr.ps1 +++ b/scripts/publish_pr.ps1 @@ -61,6 +61,58 @@ function Get-PullRequestUrl { return "https://github.com/$ownerRepo/compare/main...$encodedBranch" + "?expand=1&title=$encodedTitle" } +function Get-ClipboardText { + try { + return Get-Clipboard -Raw + } + catch { + return (Get-Clipboard | Out-String).TrimEnd() + } +} + +function Open-PrBody { + param( + [Parameter(Mandatory = $true)] + [string]$Path + ) + + try { + Start-Process notepad.exe -ArgumentList $Path + } + catch { + Write-Host "Could not open pr_body.md in notepad: $_" -ForegroundColor Yellow + } +} + +function Copy-PrBodyToClipboard { + param( + [Parameter(Mandatory = $true)] + [string]$Path + ) + + $bodyText = Get-Content -LiteralPath $Path -Raw + $verified = $false + + try { + if ((Get-Command Set-Clipboard -ErrorAction SilentlyContinue) -and (Get-Command Get-Clipboard -ErrorAction SilentlyContinue)) { + $bodyText | Set-Clipboard + $clipboardText = Get-ClipboardText + if ($clipboardText -eq $bodyText) { + $verified = $true + Write-Host "Clipboard verified." + } + } + } + catch { + $verified = $false + } + + if (-not $verified) { + Write-Host "Clipboard copy could not be verified. Opening pr_body.md." -ForegroundColor Yellow + Open-PrBody -Path $Path + } +} + Push-Location $repoRoot try { $branch = git branch --show-current @@ -134,21 +186,19 @@ try { & $prBodyScript -OutputPath $bodyPath } - try { - if (Get-Command Set-Clipboard -ErrorAction SilentlyContinue) { - Get-Content -LiteralPath $bodyPath -Raw | Set-Clipboard - Write-Host "Copied pr_body.md to clipboard." - } - } - catch { - Write-Host "Could not copy pr_body.md to clipboard: $_" -ForegroundColor Yellow - } + Copy-PrBodyToClipboard -Path $bodyPath $url = Get-PullRequestUrl -Branch $branch -PrTitle $Title Write-Host "" if ($url) { Write-Host "PR creation URL:" Write-Host $url + try { + Start-Process $url + } + catch { + Write-Host "Could not open PR creation URL in browser: $_" -ForegroundColor Yellow + } } else { Write-Host "PR URLを推定できませんでした。GitHub上で手動作成してください" -ForegroundColor Yellow