-
Notifications
You must be signed in to change notification settings - Fork 519
Feat: Add OKR business domain #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package okr | ||
|
|
||
| // RespAlignment 对齐关系 | ||
| type RespAlignment struct { | ||
| ID string `json:"id"` | ||
| CreateTime string `json:"create_time"` | ||
| UpdateTime string `json:"update_time"` | ||
| FromOwner RespOwner `json:"from_owner"` | ||
| ToOwner RespOwner `json:"to_owner"` | ||
| FromEntityType string `json:"from_entity_type"` | ||
| FromEntityID string `json:"from_entity_id"` | ||
| ToEntityType string `json:"to_entity_type"` | ||
| ToEntityID string `json:"to_entity_id"` | ||
| } | ||
|
|
||
| // RespCategory 分类 | ||
| type RespCategory struct { | ||
| ID string `json:"id"` | ||
| CreateTime string `json:"create_time"` | ||
| UpdateTime string `json:"update_time"` | ||
| CategoryType string `json:"category_type"` | ||
| Enabled *bool `json:"enabled,omitempty"` | ||
| Color *string `json:"color,omitempty"` | ||
| Name CategoryName `json:"name"` | ||
| } | ||
|
|
||
| // RespCycle 周期 | ||
| type RespCycle struct { | ||
| ID string `json:"id"` | ||
| CreateTime string `json:"create_time"` | ||
| UpdateTime string `json:"update_time"` | ||
| TenantCycleID string `json:"tenant_cycle_id"` | ||
| Owner RespOwner `json:"owner"` | ||
| StartTime string `json:"start_time"` | ||
| EndTime string `json:"end_time"` | ||
| CycleStatus *string `json:"cycle_status,omitempty"` | ||
| Score *float64 `json:"score,omitempty"` | ||
| } | ||
|
|
||
| // RespIndicator 指标 | ||
| type RespIndicator struct { | ||
| ID string `json:"id"` | ||
| CreateTime string `json:"create_time"` | ||
| UpdateTime string `json:"update_time"` | ||
| Owner RespOwner `json:"owner"` | ||
| EntityType *string `json:"entity_type,omitempty"` | ||
| EntityID *string `json:"entity_id,omitempty"` | ||
| IndicatorStatus *string `json:"indicator_status,omitempty"` | ||
| StatusCalculateType *string `json:"status_calculate_type,omitempty"` | ||
| StartValue *float64 `json:"start_value,omitempty"` | ||
| TargetValue *float64 `json:"target_value,omitempty"` | ||
| CurrentValue *float64 `json:"current_value,omitempty"` | ||
| CurrentValueCalculateType *string `json:"current_value_calculate_type,omitempty"` | ||
| Unit *RespIndicatorUnit `json:"unit,omitempty"` | ||
| } | ||
|
|
||
| // RespIndicatorUnit 指标单位 | ||
| type RespIndicatorUnit struct { | ||
| UnitType *string `json:"unit_type,omitempty"` | ||
| UnitValue *string `json:"unit_value,omitempty"` | ||
| } | ||
|
|
||
| // RespKeyResult 关键结果 | ||
| type RespKeyResult struct { | ||
| ID string `json:"id"` | ||
| CreateTime string `json:"create_time"` | ||
| UpdateTime string `json:"update_time"` | ||
| Owner RespOwner `json:"owner"` | ||
| ObjectiveID string `json:"objective_id"` | ||
| Position *int32 `json:"position,omitempty"` | ||
| Content *string `json:"content,omitempty"` | ||
| Score *float64 `json:"score,omitempty"` | ||
| Weight *float64 `json:"weight,omitempty"` | ||
| Deadline *string `json:"deadline,omitempty"` | ||
| } | ||
|
|
||
| // RespObjective 目标 | ||
| type RespObjective struct { | ||
| ID string `json:"id"` | ||
| CreateTime string `json:"create_time"` | ||
| UpdateTime string `json:"update_time"` | ||
| Owner RespOwner `json:"owner"` | ||
| CycleID string `json:"cycle_id"` | ||
| Position *int32 `json:"position,omitempty"` | ||
| Content *string `json:"content,omitempty"` | ||
| Score *float64 `json:"score,omitempty"` | ||
| Notes *string `json:"notes,omitempty"` | ||
| Weight *float64 `json:"weight,omitempty"` | ||
| Deadline *string `json:"deadline,omitempty"` | ||
| CategoryID *string `json:"category_id,omitempty"` | ||
| KeyResults []RespKeyResult `json:"key_results,omitempty"` | ||
| } | ||
|
|
||
| // RespOwner OKR 所有者 | ||
| type RespOwner struct { | ||
| OwnerType string `json:"owner_type"` | ||
| UserID *string `json:"user_id,omitempty"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package okr | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/larksuite/cli/shortcuts/common" | ||
| larkcore "github.com/larksuite/oapi-sdk-go/v3/core" | ||
| ) | ||
|
|
||
| // OKRCycleDetail lists all objectives and their key results under a given OKR cycle. | ||
| var OKRCycleDetail = common.Shortcut{ | ||
| Service: "okr", | ||
| Command: "+cycle-detail", | ||
| Description: "List objectives and key results under an OKR cycle", | ||
| Risk: "read", | ||
| Scopes: []string{"okr:okr.content:readonly"}, | ||
| AuthTypes: []string{"user", "bot"}, | ||
| HasFormat: true, | ||
| Flags: []common.Flag{ | ||
| {Name: "cycle-id", Desc: "OKR cycle id (int64)", Required: true}, | ||
| }, | ||
| Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { | ||
| cycleID := runtime.Str("cycle-id") | ||
| if cycleID == "" { | ||
| return common.FlagErrorf("--cycle-id is required") | ||
| } | ||
| if id, err := strconv.ParseInt(cycleID, 10, 64); err != nil || id <= 0 { | ||
| return common.FlagErrorf("--cycle-id must be a positive int64") | ||
| } | ||
| return nil | ||
| }, | ||
| DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { | ||
| cycleID := runtime.Str("cycle-id") | ||
| params := map[string]interface{}{ | ||
| "page_size": 100, | ||
| } | ||
| return common.NewDryRunAPI(). | ||
| GET("/open-apis/okr/v2/cycles/:cycle_id/objectives"). | ||
| Params(params). | ||
| Set("cycle_id", cycleID). | ||
| Desc("Auto-paginates objectives in the cycle, then calls GET /open-apis/okr/v2/objectives/:objective_id/key_results for each objective to fetch key results") | ||
| }, | ||
| Execute: func(ctx context.Context, runtime *common.RuntimeContext) error { | ||
| cycleID := runtime.Str("cycle-id") | ||
|
|
||
| // Paginate objectives under the cycle. | ||
| queryParams := make(larkcore.QueryParams) | ||
| queryParams.Set("page_size", "100") | ||
|
|
||
| var objectives []Objective | ||
| page := 0 | ||
| for { | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
| if page > 0 { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return ctx.Err() | ||
| case <-time.After(500 * time.Millisecond): | ||
| } | ||
| } | ||
| page++ | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| path := fmt.Sprintf("/open-apis/okr/v2/cycles/%s/objectives", cycleID) | ||
| data, err := runtime.DoAPIJSON("GET", path, queryParams, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| itemsRaw, _ := data["items"].([]interface{}) | ||
| for _, item := range itemsRaw { | ||
| raw, err := json.Marshal(item) | ||
| if err != nil { | ||
| continue | ||
| } | ||
| var obj Objective | ||
| if err := json.Unmarshal(raw, &obj); err != nil { | ||
| continue | ||
| } | ||
| objectives = append(objectives, obj) | ||
| } | ||
|
|
||
| hasMore, pageToken := common.PaginationMeta(data) | ||
| if !hasMore || pageToken == "" { | ||
| break | ||
| } | ||
| queryParams.Set("page_token", pageToken) | ||
| } | ||
|
|
||
| // For each objective, paginate key results and convert to response format. | ||
| respObjectives := make([]*RespObjective, 0, len(objectives)) | ||
| for i := range objectives { | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
| obj := &objectives[i] | ||
|
|
||
| krQuery := make(larkcore.QueryParams) | ||
| krQuery.Set("page_size", "100") | ||
|
|
||
| var keyResults []KeyResult | ||
| krPage := 0 | ||
| for { | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
| if krPage > 0 { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return ctx.Err() | ||
| case <-time.After(500 * time.Millisecond): | ||
| } | ||
| } | ||
| krPage++ | ||
|
|
||
| path := fmt.Sprintf("/open-apis/okr/v2/objectives/%s/key_results", obj.ID) | ||
| data, err := runtime.DoAPIJSON("GET", path, krQuery, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| itemsRaw, _ := data["items"].([]interface{}) | ||
| for _, item := range itemsRaw { | ||
| raw, err := json.Marshal(item) | ||
| if err != nil { | ||
| continue | ||
| } | ||
| var kr KeyResult | ||
| if err := json.Unmarshal(raw, &kr); err != nil { | ||
| continue | ||
| } | ||
| keyResults = append(keyResults, kr) | ||
| } | ||
|
|
||
| hasMore, pageToken := common.PaginationMeta(data) | ||
| if !hasMore || pageToken == "" { | ||
| break | ||
| } | ||
| krQuery.Set("page_token", pageToken) | ||
| } | ||
|
|
||
| respObj := obj.ToResp() | ||
| if respObj == nil { | ||
| continue | ||
| } | ||
| respKRs := make([]RespKeyResult, 0, len(keyResults)) | ||
| for j := range keyResults { | ||
| if r := keyResults[j].ToResp(); r != nil { | ||
| respKRs = append(respKRs, *r) | ||
| } | ||
| } | ||
| respObj.KeyResults = respKRs | ||
| respObjectives = append(respObjectives, respObj) | ||
| } | ||
|
|
||
| result := map[string]interface{}{ | ||
| "cycle_id": cycleID, | ||
| "objectives": respObjectives, | ||
| "total": len(respObjectives), | ||
| } | ||
|
|
||
| runtime.OutFormat(result, nil, func(w io.Writer) { | ||
| fmt.Fprintf(w, "Cycle %s: %d objective(s)\n", cycleID, len(respObjectives)) | ||
| for _, o := range respObjectives { | ||
| fmt.Fprintf(w, "Objective [%s]: %s \n Notes: %s \n score=%.2f weight=%.2f\n", o.ID, ptrStr(o.Content), ptrStr(o.Notes), ptrFloat64(o.Score), ptrFloat64(o.Weight)) | ||
| for _, kr := range o.KeyResults { | ||
| fmt.Fprintf(w, " - KR [%s]: %s \n score=%.2f weight=%.2f\n", kr.ID, ptrStr(kr.Content), ptrFloat64(kr.Score), ptrFloat64(kr.Weight)) | ||
| } | ||
| } | ||
| }) | ||
| return nil | ||
| }, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.