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

retry with event subset for legacy stash versions #90

Merged
merged 1 commit into from
Jan 27, 2021
Merged

retry with event subset for legacy stash versions #90

merged 1 commit into from
Jan 27, 2021

Conversation

bakito
Copy link
Contributor

@bakito bakito commented Dec 30, 2020

stash 7.x supports more hook events that 6.x therefore the event setup should be possible by defining the stash version.

This PR implements the solution proposed here: https://discourse.drone.io/t/attempt-to-enable-repo-on-older-bitbucket-servers-fails/8486

The client is intentionally kept backwards compatible, to not break the drone server when go-scm is updated.

@bradrydzewski
Copy link
Member

bradrydzewski commented Dec 30, 2020

hey there, I appreciate the pull request. I have given this some more thought, and I think we can simplify this a bit without requiring the user provide their bitbucket server version. Also I'm not too keen to add a third party runtime dependency; this library currently does not have any runtime dependencies outside of the Go standard library.

I think the easiest solution would be to detect the error in legacy versions of the software and then retry:

	res, err := s.client.do(ctx, "POST", path, in, out)
+	if err != nil && isUnknownHookEvent(err) {
+		downgradeHookInput(in)
+		res, err = s.client.do(ctx, "POST", path, in, out)
+	}
	return convertHook(out), res, err
+func isUnknownHookEvent(err error) bool {
+	return strings.Contains(err, "pr:from_ref_updated is unknown")
+}
+
+func downgradeHookInput(in *hookInput) {
+	var events []string
+	for _, event := range in.Events {
+		if event != "pr:from_ref_updated" {
+			events = append(events, event)
+		} 
+	}
+	in.Events = events
+}

@bradrydzewski bradrydzewski marked this pull request as draft December 30, 2020 18:36
@bakito bakito changed the title Add version support for stash to allow version specific setup retry with event subset for legacy stash versions Dec 30, 2020
@bakito bakito marked this pull request as ready for review December 31, 2020 07:06
@bakito
Copy link
Contributor Author

bakito commented Dec 31, 2020

I could successfully verify the simplified implementation in my setup.

@bradrydzewski bradrydzewski merged commit 4a12b86 into drone:master Jan 27, 2021
@madhosoi
Copy link

Any schedule to have this fix deployed on version 2 or latest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants