feat:新增 organizations 指令(#45)
tea organizations 對等的日常操作:
- organizations list:GET /user/orgs,輸出 name/full_name/website/
location/description/visibility(與 teai orgs 工作流命令同一
端點,但輸出完整欄位)
- organizations create:POST /orgs,--name 必填,可選 --full-name/
--description/--website/--location/--visibility;寫入需 --yes
- organizations delete:DELETE /orgs/{org},組織名為位置參數
(tea 相容);寫入需 --yes
驗收測試涵蓋端點、payload、--yes 閘門(未確認不發請求)與
值域檢查;並以本機建置對 Gitea 實測 list 輸出欄位與 tea 一致。
This commit is contained in:
@@ -470,3 +470,64 @@ func (o *Ops) CallAPIDirect(ctx context.Context, method, path, rawQuery string,
|
||||
}
|
||||
return o.Client.DoRaw(ctx, method, path, rawQuery, data)
|
||||
}
|
||||
|
||||
// ---- organizations(#45,tea organizations 對等)----
|
||||
|
||||
// Organization 是帳號所屬/可存取組織的精簡欄位
|
||||
// (GET /user/orgs、POST /orgs 回應共用)。name 是帳號名、
|
||||
// full_name 是顯示名稱(如 "Alterminal Co., Ltd."),兩者不同。
|
||||
type Organization struct {
|
||||
UserName string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
FullName string `json:"full_name"`
|
||||
Website string `json:"website"`
|
||||
Location string `json:"location"`
|
||||
Description string `json:"description"`
|
||||
Visibility string `json:"visibility"`
|
||||
}
|
||||
|
||||
// Account 回傳組織帳號名:先 username,缺漏時回退 name
|
||||
// (同 workflow.Org.Account 的取值順序)。
|
||||
func (o *Organization) Account() string {
|
||||
if o.UserName != "" {
|
||||
return o.UserName
|
||||
}
|
||||
return o.Name
|
||||
}
|
||||
|
||||
// ListMyOrganizations 列出自己可存取的組織(GET /user/orgs,分頁)。
|
||||
// tea organizations list 的對等端點;teai orgs(工作流)輸出帳號清單,
|
||||
// 本指令輸出完整欄位供日常操作使用。
|
||||
func (o *Ops) ListMyOrganizations(ctx context.Context) ([]Organization, error) {
|
||||
var orgs []Organization
|
||||
if err := o.Client.ListAll(ctx, "/user/orgs", gitea.ListOptions{}, &orgs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return orgs, nil
|
||||
}
|
||||
|
||||
// CreateOrganization 建立組織(POST /orgs)。name 必填;其餘欄位可空。
|
||||
// visibility:public|limited|private(空值交由服務端預設)。
|
||||
func (o *Ops) CreateOrganization(ctx context.Context, name, fullName, description, website, location, visibility string) (*Organization, error) {
|
||||
payload := map[string]any{
|
||||
"username": name,
|
||||
"full_name": fullName,
|
||||
"description": description,
|
||||
"website": website,
|
||||
"location": location,
|
||||
}
|
||||
if visibility != "" {
|
||||
payload["visibility"] = visibility
|
||||
}
|
||||
var org Organization
|
||||
if err := o.Client.DoJSON(ctx, "POST", "/orgs", "", payload, &org); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &org, nil
|
||||
}
|
||||
|
||||
// DeleteOrganization 刪除組織(DELETE /orgs/{org})。
|
||||
func (o *Ops) DeleteOrganization(ctx context.Context, org string) error {
|
||||
path := "/orgs/" + url.PathEscape(org)
|
||||
return o.Client.DoJSON(ctx, "DELETE", path, "", nil, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user