internal/gitea:API 用戶端、認證與輸出基礎(#5) #11

Merged
ceo merged 1 commits from feature/issue5-gitea-client into main 2026-09-10 08:39:03 +08:00
Member

實作 issue #5(父項 #3)的基礎建設:

範圍

  • internal/gitea 用戶端(僅標準庫 net/http):New 建立用戶端(自動補 /api/v1)、GetJSON 單端點查詢、ListAll 依 limit=50(Gitea 上限)逐頁抓滿
  • 認證選序:--token → TEAI_TOKEN → tea 登入組態(--config/TEA_CONFIG/預設 ~/.config/tea/config.yml);依站點主機挑選匹配的 login(default 優先);token 不入輸出、日誌與錯誤訊息(有測試保證)
  • 共用輸出:--output json|table(預設 json)、--timeout(預設 30s)
  • 結束碼 0/2/3:用法錯誤 → 2;API 錯誤(*gitea.ErrAPI,含連線失敗、401、403、5xx)→ 3;nil → 0
  • CLI 全域選項剖析(--url/--token/--config/--output/--timeout),-h/-v 不受影響

驗收對應

  • go build ./...、go vet ./...、go test ./... 全綠;gofmt 乾淨
  • 覆蓋率:internal/cli 89.1%、internal/gitea 78.4%
  • 單元測試覆蓋認證來源選序(flag > env > config、TEA_CONFIG、空白跳過)與錯誤碼映射(usage→2、API→3、wrapped error 穿透)

git push 前已手動驗證二進位:version/no-args=0、未知命令=2、壞 --output/--timeout=2、--help 全域選項說明正常。

Closes #5

實作 issue #5(父項 #3)的基礎建設: ## 範圍 - **internal/gitea 用戶端**(僅標準庫 net/http):`New` 建立用戶端(自動補 /api/v1)、`GetJSON` 單端點查詢、`ListAll` 依 limit=50(Gitea 上限)逐頁抓滿 - **認證選序**:`--token` → `TEAI_TOKEN` → tea 登入組態(`--config`/TEA_CONFIG/預設 ~/.config/tea/config.yml);依站點主機挑選匹配的 login(default 優先);token 不入輸出、日誌與錯誤訊息(有測試保證) - **共用輸出**:`--output json|table`(預設 json)、`--timeout`(預設 30s) - **結束碼 0/2/3**:用法錯誤 → 2;API 錯誤(`*gitea.ErrAPI`,含連線失敗、401、403、5xx)→ 3;nil → 0 - CLI 全域選項剖析(--url/--token/--config/--output/--timeout),-h/-v 不受影響 ## 驗收對應 - go build ./...、go vet ./...、go test ./... 全綠;gofmt 乾淨 - 覆蓋率:internal/cli 89.1%、internal/gitea 78.4% - 單元測試覆蓋認證來源選序(flag > env > config、TEA_CONFIG、空白跳過)與錯誤碼映射(usage→2、API→3、wrapped error 穿透) git push 前已手動驗證二進位:version/no-args=0、未知命令=2、壞 --output/--timeout=2、--help 全域選項說明正常。 Closes #5
max added 1 commit 2026-09-10 08:20:16 +08:00
- internal/gitea:僅標準庫的 HTTP 用戶端;ListAll 以 limit=50 逐頁抓滿
- 認證選序 --token → TEAI_TOKEN → tea 組態(--config/TEA_CONFIG/預設路徑);
  token 不入輸出、日誌與錯誤訊息
- 共用輸出 --output json|table(預設 json)、--timeout(預設 30s)
- CLI 結束碼 0/2/3:用法錯誤 → 2、API 錯誤(*gitea.ErrAPI)→ 3
- 單元測試:認證選序、tea 組態解析、分頁、逾時/401/5xx 錯誤映射、輸出

實作 issue #5
max requested review from ceo 2026-09-10 08:20:20 +08:00
ceo approved these changes 2026-09-10 08:39:02 +08:00
ceo merged commit afdead46e2 into main 2026-09-10 08:39:03 +08:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alterminal/teai#11