fix(agentic): match PR review commits by PR number
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
689b2e90e5
commit
eea8f2374e
2 changed files with 41 additions and 2 deletions
|
|
@ -120,14 +120,14 @@ func handleCompletionVerify(c *core.Core, msg core.Message) core.Result {
|
|||
func handleCompletionCommit(c *core.Core, msg core.Message) core.Result {
|
||||
switch ev := msg.(type) {
|
||||
case messages.PRMerged:
|
||||
workspaceDir := findWorkspaceByPR(ev.Repo, "")
|
||||
workspaceDir := findWorkspaceByPRWithInfo(ev.Repo, "", ev.PRNum, ev.PRURL)
|
||||
if workspaceDir != "" {
|
||||
if c.Action("agentic.commit").Exists() {
|
||||
c.Action("agentic.commit").Run(context.Background(), workspaceActionOptions(workspaceDir))
|
||||
}
|
||||
}
|
||||
case messages.PRNeedsReview:
|
||||
workspaceDir := findWorkspaceByPR(ev.Repo, "")
|
||||
workspaceDir := findWorkspaceByPRWithInfo(ev.Repo, "", ev.PRNum, ev.PRURL)
|
||||
if workspaceDir != "" {
|
||||
if c.Action("agentic.commit").Exists() {
|
||||
c.Action("agentic.commit").Run(context.Background(), workspaceActionOptions(workspaceDir))
|
||||
|
|
@ -200,6 +200,10 @@ func resolveWorkspace(name string) string {
|
|||
}
|
||||
|
||||
func findWorkspaceByPR(repo, branch string) string {
|
||||
return findWorkspaceByPRWithInfo(repo, branch, 0, "")
|
||||
}
|
||||
|
||||
func findWorkspaceByPRWithInfo(repo, branch string, prNum int, prURL string) string {
|
||||
for _, path := range WorkspaceStatusPaths() {
|
||||
workspaceDir := core.PathDir(path)
|
||||
statusResult := ReadStatusResult(workspaceDir)
|
||||
|
|
@ -213,6 +217,15 @@ func findWorkspaceByPR(repo, branch string) string {
|
|||
if branch != "" && workspaceStatus.Branch != branch {
|
||||
continue
|
||||
}
|
||||
if prNum > 0 {
|
||||
if workspaceStatus.PRURL != "" && extractPullRequestNumber(workspaceStatus.PRURL) == prNum {
|
||||
return workspaceDir
|
||||
}
|
||||
if prURL != "" && workspaceStatus.PRURL == prURL {
|
||||
return workspaceDir
|
||||
}
|
||||
continue
|
||||
}
|
||||
if branch == "" || workspaceStatus.Branch == branch {
|
||||
return workspaceDir
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,6 +193,32 @@ func TestHandlers_RegisterHandlers_Good_CompletionPipeline(t *testing.T) {
|
|||
}, time.Second, 10*time.Millisecond)
|
||||
}
|
||||
|
||||
func TestHandlers_FindWorkspaceByPR_Good_MatchesPRNumber(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Setenv("CORE_WORKSPACE", root)
|
||||
|
||||
firstWorkspace := core.JoinPath(WorkspaceRoot(), "core", "go-io", "task-1")
|
||||
secondWorkspace := core.JoinPath(WorkspaceRoot(), "core", "go-io", "task-2")
|
||||
require.True(t, fs.EnsureDir(firstWorkspace).OK)
|
||||
require.True(t, fs.EnsureDir(secondWorkspace).OK)
|
||||
|
||||
require.NoError(t, writeStatus(firstWorkspace, &WorkspaceStatus{
|
||||
Status: "completed",
|
||||
Repo: "go-io",
|
||||
Branch: "agent/first",
|
||||
PRURL: "https://forge.lthn.ai/core/go-io/pulls/12",
|
||||
}))
|
||||
require.NoError(t, writeStatus(secondWorkspace, &WorkspaceStatus{
|
||||
Status: "completed",
|
||||
Repo: "go-io",
|
||||
Branch: "agent/second",
|
||||
PRURL: "https://forge.lthn.ai/core/go-io/pulls/13",
|
||||
}))
|
||||
|
||||
result := findWorkspaceByPRWithInfo("go-io", "", 13, "https://forge.lthn.ai/core/go-io/pulls/13")
|
||||
assert.Equal(t, secondWorkspace, result)
|
||||
}
|
||||
|
||||
func TestHandlers_IngestDisabled_Bad(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Setenv("CORE_WORKSPACE", root)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue