-
Notifications
You must be signed in to change notification settings - Fork 232
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
Implement parsing/handling for missing pull request webhook events for BitBucket Server (Stash) driver #130
Conversation
Base: scm.Reference{ | ||
Name: from.ToRef.DisplayID, | ||
Path: from.ToRef.ID, | ||
Sha: from.ToRef.LatestCommit, |
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 think these should be correct. However, I didn't find use for anything else except .Base.Sha
in Drone server
https://github.com/harness/drone/blob/master/service/hook/parser/parse.go#L275
So, should this addition be omitted from the PR?
case "pr:from_ref_updated": | ||
// The request includes field "previousFromHash", which could be compared | ||
// to the FromRef.Latestcommit to ensure there is actually a change, | ||
// but there is unlikely need for that. |
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.
Should these comments be added to the git commit instead? They would be available via e.g. blame feature in Github.
ID string `json:"id"` // "refs\/heads\/master" | ||
DisplayID string `json:"displayId"` // "master" | ||
Type string `json:"type"` // "BRANCH" | ||
LatestCommit string `json:"latestCommit"` // "860c4eb4ed0f969b47144234ba13c31c498cca69" |
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.
Only fields . PreviousTarget
and .PreviousTarget.LatestCommit
are currently used. Should I remove everything else from here?
Additionally, if not, should I keep the examples of the data in comments or should I drop those?
👋 hey there, I think in order to provide a review we would need unit tests. This is largely a data mapping exercise and the unit tests include sample webhooks (with real world data) before and after parsing, which are critical to the review process. |
scm/driver/stash/webhook.go
Outdated
// action only when the target reference has changed (name or hash). | ||
if src.PullRequest.ToRef.DisplayID == src.PreviousTarget.DisplayID && | ||
src.PullRequest.ToRef.LatestCommit == src.PreviousTarget.LatestCommit { | ||
return nil, nil |
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 presume this is checking to differentiate between title / description change vs a code change? If this is just a title or description change we can set the action to Updated as opposed to returning a nil.
if src.PullRequest.ToRef.DisplayID == src.PreviousTarget.DisplayID &&
src.PullRequest.ToRef.LatestCommit == src.PreviousTarget.LatestCommit {
+ dst.Action = scm.ActionUpdate
} else {
dst.Action = scm.ActionSync
}
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.
It is. I'll make that change. I wasn't sure what the ActionUpdate
was used for.
Although, the same event can include updates to the title/description and changes to the target branch. Should that be mentioned here?
@bradrydzewski Sure, I was planning to do that next, likely tomorrow. I just wanted to publish what I have done so far for others to read or comment on the things which are not specific to the implementation (i.e., what to include or where to put comments). |
I added some test data for the events. I copied the json data from bitbucket server, but I replaced author info to match what was used before. I noticed that the newer data includes links to different things. So, I think these TODOs might be fixed?
I can add updated |
Also test coverage seems to be a bit lower for Stash than others 🤔
EDIT: untested lines are errors and unimplemented functions, so all good 🙂 |
hey @raphendyr - I see this is still marked as work in progress, please let us know when you would like us to review :) |
Sorry, my head was stuck waiting possible answers to my questions and without answers, I got stuck there. |
Hey @raphendyr i have spent some time getting familiar with this PR and the change. Code wise it looks solid and all of the testing is great to have, and made reading through the code much easier. Additionally, if not, should I keep the examples of the data in comments or should I drop those?`
please add these. it brings it in line with the other transports.
please leave these in comments in the file, as it aides in reading. So leave everything as it is, but could you squash the commits. Many thanks for your patience, we have been busy else where. TP |
@tphoney Thanks for the feedback. As per your request, I'll squash the commits to a single commit. |
* handle rebases to a pull request * handle target branch changes of a pull request * handle deletion of a pull request
Many thanks @raphendyr for your patience and your excellent code. 🍻 |
I looked into getting PR events working with the Stash driver to support my teams current workflow. My goal was to address issues mentioned in #116, but I did find few other missing events too.
I open this PR for comments. I have tested these changes with a single user and a single repo in my local BitBucket server, so I'm not yet sure if a PR from a fork work as expected. In addition, I have not written any tests yet.
I'm particularly looking feedback on the parts of the code, which I have added GitHub comments for.
Fixes #116