Skip to content
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

Refactor delete command code to be a bit more DRY #585

Merged
merged 1 commit into from Jan 10, 2020
Merged

Refactor delete command code to be a bit more DRY #585

merged 1 commit into from Jan 10, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jan 9, 2020

Changes

While implementing multiple delete I noticed that each delete command was implementing its own error handling and messaging even though each was doing exactly the same thing. This made working on the code more error-prone - I had to double check that I'd added each of my changes correctly across every repetition of the delete behaviour.

So this commit introduces a helper type, Deleter, that does most of the repetitive work and is now reused across all the delete commands.

Submitter Checklist

While implementing multiple delete I noticed that each delete
command was implementing its own error handling and messaging
even though each was doing exactly the same thing. This made
working on the code cumbersome - I had to double check that I'd
added each of my changes correactly across every repition of
the delete command.

So this commit introduces a helper type, Deleter, that does most
of the repetitive work and is reused across all the delete commands.
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 9, 2020
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

My only remark/question is : why the struct ? a function call would work too 😝

deleter.Delete(s, "ClusterTask", tNames, func(…))

That said, the function signature is then a bit weird 😛

Other than that, looks really good to me 😻

@tekton-robot
Copy link
Contributor

The following is the coverage report on pkg/.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/clustertask/delete.go 96.3% 94.4% -1.9
pkg/cmd/condition/delete.go 96.6% 95.0% -1.6
pkg/cmd/eventlistener/delete.go 96.6% 95.0% -1.6
pkg/cmd/pipeline/delete.go 89.1% 93.9% 4.8
pkg/cmd/pipelinerun/delete.go 96.6% 95.0% -1.6
pkg/cmd/task/delete.go 89.1% 93.9% 4.8
pkg/cmd/taskrun/delete.go 96.6% 95.0% -1.6
pkg/cmd/triggerbinding/delete.go 96.6% 95.0% -1.6
pkg/cmd/triggertemplate/delete.go 96.6% 95.0% -1.6
pkg/helper/deleter/deleter.go Do not exist 50.0%

@ghost
Copy link
Author

ghost commented Jan 9, 2020

why the struct ?

Mostly because the function signature would be a bit gnarly when deleting both a resource and its relations I think.

@ghost
Copy link
Author

ghost commented Jan 9, 2020

/test pull-tekton-cli-unit-tests

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 9, 2020
}

return multierr.Combine(errs...)
d := deleter.New("PipelineRun", func(pipelineRunName string) error {
Copy link
Member

@danielhelfand danielhelfand Jan 9, 2020

Choose a reason for hiding this comment

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

Not that this should happen in this pr, but it may be a good idea to have TaskRuns be a related resource for PipelineRuns.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2020
@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danielhelfand, vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [danielhelfand,vdemeester]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants