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

fix: when branch name is invalid, report a error message #328

Merged
merged 6 commits into from
Oct 27, 2021

Conversation

mangoGoForward
Copy link
Member

What type of PR is this?

/kind bug
/kind hacktoberfest
/kind hacktoberfest-accepted

What this PR does / why we need it:

Before save resource, we should check branch name whether is valid, and build the label selector to query target PipelineRuns, we should check the branch name of request also.

Which issue(s) this PR fixes:

Fixes #104

@ks-ci-bot
Copy link
Collaborator

@mangoGoForward: The label(s) kind/hacktoberfest, kind/hacktoberfest-accepted cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this?

/kind bug
/kind hacktoberfest
/kind hacktoberfest-accepted

What this PR does / why we need it:

Before save resource, we should check branch name whether is valid, and build the label selector to query target PipelineRuns, we should check the branch name of request also.

Which issue(s) this PR fixes:

Fixes #104

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ks-ci-bot ks-ci-bot added kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 22, 2021
@mangoGoForward
Copy link
Member Author

/assign @LinuxSuRen

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #328 (c842524) into master (9727751) will increase coverage by 0.04%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #328      +/-   ##
=========================================
+ Coverage    7.70%   7.75%   +0.04%     
=========================================
  Files          94      94              
  Lines       21443   21449       +6     
=========================================
+ Hits         1652    1663      +11     
+ Misses      19667   19662       -5     
  Partials      124     124              
Flag Coverage Δ
unittests 7.75% <87.50%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/kapis/devops/v1alpha3/pipeline/handler.go 0.00% <0.00%> (ø)
...lers/jenkins/pipelinerun/pipelinerun_controller.go 12.33% <100.00%> (+1.15%) ⬆️
...kg/kapis/devops/v1alpha3/pipeline/branch_filter.go 100.00% <100.00%> (ø)
pkg/kapis/devops/v1alpha3/pipelinerun/util.go 37.93% <100.00%> (+2.21%) ⬆️
...trollers/devopsproject/devopsproject_controller.go 40.62% <0.00%> (-2.61%) ⬇️
...rs/devopscredential/devopscredential_controller.go 36.48% <0.00%> (+3.37%) ⬆️
controllers/s2ibinary/s2ibinary_controller.go 38.00% <0.00%> (+5.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9727751...c842524. Read the comment docs.

@JohnNiang
Copy link
Member

Thanks for your quick fixing.

/area devops
/cc @kubesphere/sig-devops

Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

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

I'm wondering if there's a better way to check the label, such as
I found a solution from the kubernetes project, we might be able to reuse it.

https://github.com/kubernetes/apimachinery/blob/a7973b273a7e6665f300fbadacab2f70fca0f3c3/pkg/util/validation/validation.go#L167

@ks-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mangoGoForward
To complete the pull request process, please ask for approval from linuxsuren after the PR has been reviewed.

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

Needs approval from an approver in each of these files:

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

@ks-ci-bot ks-ci-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 22, 2021
@mangoGoForward
Copy link
Member Author

I'm wondering if there's a better way to check the label, such as I found a solution from the kubernetes project, we might be able to reuse it.

https://github.com/kubernetes/apimachinery/blob/a7973b273a7e6665f300fbadacab2f70fca0f3c3/pkg/util/validation/validation.go#L167

Thanks a lot, I have changed, could you help me to review it?

@JohnNiang
Copy link
Member

I'm wondering if there's a better way to check the label, such as I found a solution from the kubernetes project, we might be able to reuse it.

https://github.com/kubernetes/apimachinery/blob/a7973b273a7e6665f300fbadacab2f70fca0f3c3/pkg/util/validation/validation.go#L167

Thanks a lot, I have changed, could you help me to review it?

Nice job!

But I'm curious about is, why not use k8s.io/apimachinery/pkg/util/validation.IsValidLabelValue function directly, but handwritten. : P

@ks-ci-bot ks-ci-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 23, 2021
@mangoGoForward
Copy link
Member Author

I'm wondering if there's a better way to check the label, such as I found a solution from the kubernetes project, we might be able to reuse it.

https://github.com/kubernetes/apimachinery/blob/a7973b273a7e6665f300fbadacab2f70fca0f3c3/pkg/util/validation/validation.go#L167

Thanks a lot, I have changed, could you help me to review it?

Nice job!

But I'm curious about is, why not use k8s.io/apimachinery/pkg/util/validation.IsValidLabelValue function directly, but handwritten. : P

The penny drops, and the code is more elegant.

@JohnNiang
Copy link
Member

/lgtm

@ks-ci-bot ks-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2021
@ks-ci-bot ks-ci-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 25, 2021
Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

Thanks for your effort. But I still meet some issues. Please check the following screenshot:

image

I test it with the following images:

kubespheredev/devops-apiserver:dev-v3.2.0-rc.1-c842524
kubespheredev/devops-controller:dev-v3.2.0-rc.1-c842524

@LinuxSuRen
Copy link
Member

IMO, if there's no perfect solution for some special character in the git branch, then we can exclude (AKA do not show) them. So, we can claim that no support for those git branches which are Chinese words.

How does that sound like? @mangoGoForward @JohnNiang

@mangoGoForward
Copy link
Member Author

IMO, if there's no perfect solution for some special character in the git branch, then we can exclude (AKA do not show) them. So, we can claim that no support for those git branches which are Chinese words.

How does that sound like? @mangoGoForward @JohnNiang

I think so, when I try to translate git branch name to english when it is invalid, but found that I don't know the words is Chinese, and if it is other language such as Japanese, it also can not solve.

@LinuxSuRen
Copy link
Member

So, I'd like to suggest we exclude those branches that have invalid characters (not match with the Kubernetes label naming rule). I believe the following code lines:

if err := json.Unmarshal([]byte(branchesJSON), &branches); err != nil {

@mangoGoForward
Copy link
Member Author

So, I'd like to suggest we exclude those branches that have invalid characters (not match with the Kubernetes label naming rule). I believe the following code lines:

if err := json.Unmarshal([]byte(branchesJSON), &branches); err != nil {

Done

Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

/lgtm

Thanks for your patient.

image

I'm wondering if you have the same email address between GitHub and your git config. Your avatars' color is gray, and it might be caused by the email setting. This would block the merge process if you don't mind it.

By the way, you can join our WeChat group of the DevOps SIG if you are interested in it. My WeChat ID is linuxsuren.

@ks-ci-bot ks-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 26, 2021
@mangoGoForward
Copy link
Member Author

/lgtm

Thanks for your patient.

image

I'm wondering if you have the same email address between GitHub and your git config. Your avatars' color is gray, and it might be caused by the email setting. This would block the merge process if you don't mind it.

By the way, you can join our WeChat group of the DevOps SIG if you are interested in it. My WeChat ID is linuxsuren.

Thanks, Both use same email address between Github and git config correctly. And I'm glad to join the group.

Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

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

Hi @mangoGoForward , I've left a potential solution in #104 (comment). Please take a moment to have a look.

@LinuxSuRen
Copy link
Member

LinuxSuRen commented Oct 27, 2021

Hi @mangoGoForward , I've left a potential solution in #104 (comment). Please take a moment to have a look.

hi @JohnNiang , I prefer to take your solution in a new PR instead of this one. This PR can avoid the necessary errors with small changes. But it will make big changes with your solution.

@JohnNiang
Copy link
Member

Hi @mangoGoForward , I've left a potential solution in #104 (comment). Please take a moment to have a look.

hi @JohnNiang , I prefer to take your solution in a new PR instead of this one. This PR can avoid the necessary errors with small changes. But it will make big changes with your solution.

Agree with you.

/lgtm

@LinuxSuRen LinuxSuRen merged commit 0d4153b into kubesphere:master Oct 27, 2021
@mangoGoForward mangoGoForward deleted the fix/invalid-branch-name branch July 22, 2022 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When the branch name of devop is Chinese, an error will be reported
4 participants