From d0334434c54da507dfefb9f01f5911398aeeb229 Mon Sep 17 00:00:00 2001 From: ceo Date: Sun, 13 Sep 2026 08:45:48 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Anext/mine=20=E6=BC=8F=E6=8E=89?= =?UTF-8?q?=E7=A9=BA=E5=80=89=E5=BA=AB=E4=B8=AD=E7=9A=84=E5=88=86=E6=B4=BE?= =?UTF-8?q?=20issue=EF=BC=88#43=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iterOrgRepos(issue 掃描,供 Mine 與 members --has-work)不再跳過 empty=true 的倉庫——Gitea 允許空倉庫持有 open issue(「初始化項目」 型工作),行為基準 gitea.py 的 for_all_repositories 掃 issue 時 本來就不檢查 empty;teai 先前過度套用了空倉庫跳過條件,導致 teai next 對 colony-tick-demo issue #1 回 null。 PR 掃描(iterOpenPulls)、stalled、milestone overview 維持跳過 空倉庫不變(與 gitea.py 一致)。附回歸測試兩則。 --- internal/workflow/scan.go | 8 ++++-- internal/workflow/scan_test.go | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/internal/workflow/scan.go b/internal/workflow/scan.go index 9415ec4..0a7e552 100644 --- a/internal/workflow/scan.go +++ b/internal/workflow/scan.go @@ -136,7 +136,11 @@ func (s *Scanner) Members(hasWork bool) ([]string, error) { return out, nil } -// iterOrgRepos 產出 (org, repoName);空倉庫跳過(沒有內容可掃)。 +// iterOrgRepos 產出 (org, repoName)。空倉庫(empty)**不**跳過:Gitea 允許 +// 空倉庫持有 open issue(如「初始化項目」型工作),gitea.py 的 +// for_all_repositories(list_my_followup_issues/for_all_organizations) +// 掃 issue 時不檢查 empty;只有 PR 掃描(iterOpenPulls)、stalled 與 +// milestone overview 才跳過空倉庫。 func (s *Scanner) iterOrgRepos() ([][2]string, error) { orgs, err := s.Orgs() if err != nil { @@ -149,7 +153,7 @@ func (s *Scanner) iterOrgRepos() ([][2]string, error) { return nil, err } for _, repo := range repos { - if repo.Name == "" || repo.Empty { + if repo.Name == "" { continue } out = append(out, [2]string{org, repo.Name}) diff --git a/internal/workflow/scan_test.go b/internal/workflow/scan_test.go index bba9e9e..278a44f 100644 --- a/internal/workflow/scan_test.go +++ b/internal/workflow/scan_test.go @@ -164,6 +164,51 @@ func TestNextLayerFallbackToIssue(t *testing.T) { } } +// TestNextPicksIssueInEmptyRepo 回歸測試(#43):空倉庫(empty=true)中 +// 分派給目前帳號的 open issue 應被第三層拾取——gitea.py 的 +// for_all_repositories 掃 issue 不跳過空倉庫(「初始化項目」型工作)。 +func TestNextPicksIssueInEmptyRepo(t *testing.T) { + s, fc := newTestScanner() + fc.repos["alterminal"] = []Repo{ + {Name: "teai"}, + {Name: "colony-tick-demo", Empty: true}, + } + fc.issues["alterminal/colony-tick-demo"] = []Issue{ + { + Number: 1, Title: "初始化項目", UpdatedAt: "2026-09-08T00:00:00Z", + Assignees: []User{*mkUser("alex")}, + Repository: &Repository{FullName: "alterminal/colony-tick-demo"}, + HTMLURL: "https://gitea.alterminal.com/alterminal/colony-tick-demo/issues/1", + }, + } + work, err := s.Next() + if err != nil { + t.Fatal(err) + } + if work == nil || work.Type != "issue" || work.Number != 1 || work.Repo != "alterminal/colony-tick-demo" { + t.Errorf("應拾取空倉庫中的 issue #1,得到 %+v", work) + } +} + +// TestMineIncludesEmptyRepoIssues 回歸測試(#43):mine 同樣不因倉庫為空而漏列。 +func TestMineIncludesEmptyRepoIssues(t *testing.T) { + s, fc := newTestScanner() + fc.repos["alterminal"] = []Repo{ + {Name: "teai"}, + {Name: "colony-tick-demo", Empty: true}, + } + fc.issues["alterminal/colony-tick-demo"] = []Issue{ + {Number: 1, Title: "初始化項目", UpdatedAt: "2026-09-08T00:00:00Z", Assignees: []User{*mkUser("alex")}}, + } + issues, err := s.Mine() + if err != nil { + t.Fatal(err) + } + if len(issues) != 1 || issues[0].Num() != 1 { + t.Errorf("mine 應列出空倉庫中的 issue #1,得到 %d 件", len(issues)) + } +} + func TestNextNone(t *testing.T) { s, _ := newTestScanner() work, err := s.Next()