Skip to content

[SDK] Implement ListStageCommands() in SDK #5639

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 3 commits into from
Mar 10, 2025
Merged

Conversation

t-kikuc
Copy link
Member

@t-kikuc t-kikuc commented Mar 10, 2025

What this PR does:

as title

Why we need it:

Enable handling commands without polling by a plugin developer

Which issue(s) this PR fixes:

Part of #5367

Example Usage

Approval:

func someApprovalStage(ctx context.Context, client *Client) {
	cnt := 0
	for cmd, err := range client.ListStageCommands(ctx, model.Command_APPROVE_STAGE) {
		if err != nil {
			lp.Error(...)
			break // or return error
		}
		cnt += 1 // validateApproverNum()

		if cnt > 10 {
			lp.Info("Received all required approvals")
			break
		}
	}
}

Skip:

	// Sync the skip command.
	var (
		status = model.StageStatus_STAGE_SUCCESS
		doneCh = make(chan struct{})
	)
	defer close(doneCh)
	go func() {
		for cmd, err := range client.__ListStageCommands(ctx, model.Command_APPROVE_STAGE){
			if err != nil{
				lp.Error(...)
				break // or return error 
			}
			if err == nil {
				status = model.StageStatus_STAGE_SKIPPED
				// Stop the context to cancel all running analyses.
				cancel()
				return
			}
		}

(cf.

// Sync the skip command.
var (
status = model.StageStatus_STAGE_SUCCESS
doneCh = make(chan struct{})
)
defer close(doneCh)
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if !e.checkSkippedByCmd(ctx) {
continue
}
status = model.StageStatus_STAGE_SKIPPED
// Stop the context to cancel all running analyses.
cancel()
return
case <-doneCh:
return
}
}
}()
)

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

khanhtc1202
khanhtc1202 previously approved these changes Mar 10, 2025
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LNeatTM 🔥

@t-kikuc
Copy link
Member Author

t-kikuc commented Mar 10, 2025

We'll update the version of Go in another PR soon before merging the PR.

@t-kikuc t-kikuc closed this Mar 10, 2025
@t-kikuc t-kikuc reopened this Mar 10, 2025
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

Attention: Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.

Project coverage is 25.43%. Comparing base (0a5f895) to head (e95e38b).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
pkg/plugin/sdk/client.go 0.00% 31 Missing ⚠️
pkg/plugin/sdk/deployment.go 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5639      +/-   ##
==========================================
- Coverage   26.68%   25.43%   -1.26%     
==========================================
  Files         477      477              
  Lines       50777    50844      +67     
==========================================
- Hits        13552    12931     -621     
- Misses      36156    36908     +752     
+ Partials     1069     1005      -64     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I commented on comments and namings.

@@ -688,3 +688,32 @@ func (o StageStatus) toModelEnum() model.StageStatus {
return model.StageStatus_STAGE_FAILURE
}
}

type StageCommand struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add comments as others?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I fixed it on e95e38b

Comment on lines 699 to 702
const (
CommandType_APPROVE_STAGE CommandType = iota
CommandType_SKIP_STAGE
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use PascalCase for naming.

Suggested change
const (
CommandType_APPROVE_STAGE CommandType = iota
CommandType_SKIP_STAGE
)
const (
CommandTypeApproveStage CommandType = iota
CommandTypeSkipStage
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I fixed it on e95e38b

Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@t-kikuc
Copy link
Member Author

t-kikuc commented Mar 10, 2025

@khanhtc1202 Sorry, please approve again 🙏  I fixed nits

@t-kikuc t-kikuc enabled auto-merge (squash) March 10, 2025 07:55
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@t-kikuc t-kikuc merged commit d7af69c into master Mar 10, 2025
16 of 18 checks passed
@t-kikuc t-kikuc deleted the plugin/list-stage-commands branch March 10, 2025 08:02
@github-actions github-actions bot mentioned this pull request Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants