-
Notifications
You must be signed in to change notification settings - Fork 748
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
feat(bitbucketserver): multiple improvements to bitbucketserver event source #2921
feat(bitbucketserver): multiple improvements to bitbucketserver event source #2921
Conversation
299a80a
to
461fbe8
Compare
Testing these changes in our environment. When they have baked for a little bit I will change this PR to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daniel-codefresh - could you take a look?
49094db
to
37958b8
Compare
Fixed incorrect protobuf struct tag options 37958b8. Though these types should be auto generated, not doing so makes modifications error prone. |
132bc9c
to
964d305
Compare
964d305
to
818996b
Compare
@daniel-codefresh this is ready for review. |
Hey @daniel-codefresh I hope you had a great holidays and happy new year. I am wondering if you would be able to review this? |
14187f8
to
a81564e
Compare
Is anyone available to review this @whynowy? |
5843a9c
to
b0ed545
Compare
@@ -32,6 +32,9 @@ type WebhookContext struct { | |||
// Default value: 1048576 (1MB). | |||
// +optional | |||
MaxPayloadSize *int64 `json:"maxPayloadSize,omitempty" protobuf:"bytes,9,opt,name=maxPayloadSize"` | |||
// CheckInterval is a duration in which to wait before checking that the webhooks exist, e.g. 1s, 30m, 2h... (defaults to 1m) | |||
// +optional | |||
CheckInterval string `json:"checkInterval" protobuf:"bytes,10,opt,name=checkInterval"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use *metav1.Duration
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it but I get this error when running make codegen
.
The swagger spec at "api/openapi-spec/swagger.json" is invalid against swagger specification 2.0.
See errors below:
- some references could not be resolved in spec. First found: object has no key "io.k8s.apimachinery.pkg.apis.meta.v1.Duration"
I was copying an existing duration example from here, as I did not see any uses of a Duration
type, probably for this reason maybe?
CheckInterval string `json:"checkInterval,omitempty" protobuf:"bytes,3,opt,name=checkInterval"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can fix this later.
Just realized it's added to the generic WebhookContext
, which is used by many event sources. This is not right, please move to bigbuckets specific types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, I will move this.
if err != nil { | ||
return fmt.Errorf("failed to get bitbucketserver token. err: %w", err) | ||
} | ||
if !bitbucketserverEventSource.DeleteHookOnFinish && len(router.hookIDs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning early to make the code more readable by removing a level of nesting. I should split this up into two if statements though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done. ✅
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
bitbucketClient := newBitbucketServerClient(ctx, bitbucketConfig, bitbucketToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ctx
will be cancelled when this function exits, will the bitbucketConfig
still be able to used for delete the webhook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I created a second client that will be used by PostInactivate
. I also ensured that the customClient
uses the ctx
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I don't think this is a good approach, maybe just extract the way to get a client to a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your instructions aren't clear here. I will take a second look though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again, I feel this is the right approach using a separate instance of the bitbucket client for deleting which does not use the canceled context and adding the bitbucket clients to the Router
struct which can be accessed by the different functions is a common approach to using clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes pushed and responded to comments. Thanks for reviewing.
if err != nil { | ||
return fmt.Errorf("failed to get bitbucketserver token. err: %w", err) | ||
} | ||
if !bitbucketserverEventSource.DeleteHookOnFinish && len(router.hookIDs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning early to make the code more readable by removing a level of nesting. I should split this up into two if statements though.
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
bitbucketClient := newBitbucketServerClient(ctx, bitbucketConfig, bitbucketToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I created a second client that will be used by PostInactivate
. I also ensured that the customClient
uses the ctx
.
@@ -32,6 +32,9 @@ type WebhookContext struct { | |||
// Default value: 1048576 (1MB). | |||
// +optional | |||
MaxPayloadSize *int64 `json:"maxPayloadSize,omitempty" protobuf:"bytes,9,opt,name=maxPayloadSize"` | |||
// CheckInterval is a duration in which to wait before checking that the webhooks exist, e.g. 1s, 30m, 2h... (defaults to 1m) | |||
// +optional | |||
CheckInterval string `json:"checkInterval" protobuf:"bytes,10,opt,name=checkInterval"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it but I get this error when running make codegen
.
The swagger spec at "api/openapi-spec/swagger.json" is invalid against swagger specification 2.0.
See errors below:
- some references could not be resolved in spec. First found: object has no key "io.k8s.apimachinery.pkg.apis.meta.v1.Duration"
I was copying an existing duration example from here, as I did not see any uses of a Duration
type, probably for this reason maybe?
CheckInterval string `json:"checkInterval,omitempty" protobuf:"bytes,3,opt,name=checkInterval"` |
2f216ee
to
fa58b2d
Compare
@whynowy this is ready for review again. |
fa58b2d
to
b8338ad
Compare
@@ -32,6 +32,9 @@ type WebhookContext struct { | |||
// Default value: 1048576 (1MB). | |||
// +optional | |||
MaxPayloadSize *int64 `json:"maxPayloadSize,omitempty" protobuf:"bytes,9,opt,name=maxPayloadSize"` | |||
// CheckInterval is a duration in which to wait before checking that the webhooks exist, e.g. 1s, 30m, 2h... (defaults to 1m) | |||
// +optional | |||
CheckInterval string `json:"checkInterval" protobuf:"bytes,10,opt,name=checkInterval"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can fix this later.
Just realized it's added to the generic WebhookContext
, which is used by many event sources. This is not right, please move to bigbuckets specific types.
@@ -93,6 +98,40 @@ func (router *Router) HandleRoute(writer http.ResponseWriter, request *http.Requ | |||
return | |||
} | |||
|
|||
// When SkipBranchRefsChangedOnOpenPR is enabled and webhook event type is repo:refs_changed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there so specific logic hardcoded?
If there's a requirement like you mentioned in the PR description, instead of doing this, you can use filter feature in the Sensor take the events you are interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I met with Pipekit folks about this and we determined that a filter would not work, because of the API call and self-signed certificate required. This addition goes a long way for Argo to replace the multibranch pipeline in Jenkins, also note that this behaviour is opt-in not opt-out so they have to specifically enable it.
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
bitbucketClient := newBitbucketServerClient(ctx, bitbucketConfig, bitbucketToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I don't think this is a good approach, maybe just extract the way to get a client to a function?
4a7608b
to
7886c94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the conflict.
c53f9d4
to
63d9a44
Compare
Done and also squashed commits for a clean merge. |
@whynowy hoping this gets merged before another conflict in go.mod. |
Sorry, you have to do it again... Ping me on slack after you do it. |
…t source This Pull Request contains 3 improvements to the Bitbucket Server Event source. 1. Customizable Apply Webhook Check Interval Currently the apply webhook check runs every 60 seconds which could be to often. This is now configurable. 2. Manage Webhooks for Entire Projects When a list of Bitbucket Server Projects are provided the event source will ensure a webhook exists in all repositories in the provided project. 3. Ability to Skip Refs Changed when a Pull Request is Open A new option has been added that adds a check when a wehook is received, when a repo:refs_changed event is received a check will be ran to skip publishing the event if a Pull Request is opened. This is to get around the issue that Bitbucket will send this event even when a Pull Request is opened and there is already a pr:from_ref_updated event that would launch multiple workflow. This allows us to have a branch, pull request and tag workflows. Signed-off-by: Ryan Currah <[email protected]>
63d9a44
to
58fa25b
Compare
when dis bad boy gonna be released? |
… source (#2921) Signed-off-by: Derek Wang <[email protected]>
There are no breaking changes in the pull request, the event source will behave the same by default. One bigger internal change is that the Bitbucket Server client is now created once, set on the Route struct.
This Pull Request contains 3 improvements to the Bitbucket Server Event source.
Currently the apply webhook check runs every 60 seconds which could be to often. This is now configurable.
When a list of Bitbucket Server Projects are provided the event source will ensure a webhook exists in all repositories in the provided project.
Refs Changed
event type when a Pull Request is Open for the same commit.This feature aims to reduce redundant workflow triggers caused by Bitbucket's event handling. Specifically, when a Pull Request is opened and a new commit is pushed, Bitbucket sends two events:
repo:refs_changed
and eitherpr:from_ref_created
(for a new PR) orpr:from_ref_updated
(for an existing PR). This results in multiple workflows being launched for both Branch and Pull Request events.To address this, the Pull Request adds a boolean option named
skipBranchRefsChangedOnOpenPR
. This option, when enabled, performs a check to determine if a Pull Request is open for a specific branch commit associated with arepo:refs_changed
event. If a PR is open for that commit, the new feature will skip sending therepo:refs_changed
event. This effectively prevents the triggering of multiple workflows for the same commit in the scenario where a Pull Request is opened.