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

Enhancement/restapi update #391

Open
wants to merge 4 commits into
base: release/1.x
Choose a base branch
from

Conversation

BUGinator86
Copy link

Updated Pullrequest to also include tests for requests with bitbucket projectkey and slug.
Also put creation of payload in HttpNotifier classes to make it possible to create different payloads for different versions of stash/bitbucket.
Introduces ExtendedApacheHttpNotifier for extended payload and new selector that creates the ExtendedApacheHttpNotifier only if a BitBucket projectkey and slug is provided.
Else the behaviour is the same as before.

Testing done

Submitter checklist

  • [x ] Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • [x ] Ensure that the pull request title represents the desired changelog entry
  • [x ] Please describe what you did
  • [x ] Link to relevant issues in GitHub or Jira
  • [x ] Link to relevant pull requests, esp. upstream and downstream changes
  • [x ] Ensure you have provided tests - that demonstrates feature works or fixes the issue

@BUGinator86 BUGinator86 requested a review from a team as a code owner May 30, 2024 19:52
Copy link
Contributor

@sghill sghill left a comment

Choose a reason for hiding this comment

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

Thank you for the effort in testing and designing something that works on multiple versions of Bitbucket! I added a few comments around retaining API compatibility so the latest update won't break compilation for folks, but other than that I think the direction is really solid.

if (res.getStatusLine().getStatusCode() != 204) {
return NotificationResult.newFailure(EntityUtils.toString(res.getEntity()));
} else {
return NotificationResult.newSuccess();
}
} catch (Exception e) {
LOGGER.warn("{} failed to send {} to Bitbucket Server at {}", context.getRunId(), payload, uri, e);
LOGGER.warn("{} failed to send {} to Bitbucket Server at {}", context.getRunId(), payload, uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why drop logging the exception here?

@@ -94,7 +97,7 @@ else if (credentials instanceof StringCredentials) {
req.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + ((StringCredentials)credentials).getSecret().getPlainText());
}
else {
throw new AuthenticationException("Unsupported credials");
throw new AuthenticationException("Unsupported credentials");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, appreciate this update 👍

@@ -1,4 +1,4 @@
package org.jenkinsci.plugins.stashNotifier;
package org.jenkinsci.plugins.stashNotifier.NotifierSelectors;
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate the effort to keep similar implementations together, but unfortunately this is a breaking change.

Can we leave it in the original package to minimize the work consumers will have to do?

@@ -8,9 +8,16 @@ public class BuildStatusUriFactory {
private BuildStatusUriFactory() {
}

public static URI create(String baseUri, String commit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave this method around and create a new overload for the extra parameters?


public NotificationContext(PrintStream logger, String runId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave the old constructor too? Happy to mark it deprecated, just would prefer the next release doesn't cause compilation issues if possible.

public class DefaultHttpNotifierSelector implements HttpNotifierSelector {
private final List<HttpNotifier> httpNotifiers;

public DefaultHttpNotifierSelector(List<HttpNotifier> notifiers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there more than two implementations?

I like the idea here a lot. I think it would be quite a bit simpler by having the constructor take the Default and Extended notifiers directly, rather than iterating a list for a known value.

*/
@NonNull HttpNotifier select(@NonNull SelectionContext context);
HttpNotifier select(@NonNull SelectionContext context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we bring back the NonNull declaration?

class DefaultApacheHttpNotifier implements HttpNotifier {
public class DefaultApacheHttpNotifier implements HttpNotifier {
protected static final int MAX_FIELD_LENGTH = 255;
protected static final int MAX_URL_FIELD_LENGTH = 450;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to see these additional validations 👍

@@ -51,32 +52,34 @@
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;

class DefaultApacheHttpNotifier implements HttpNotifier {
public class DefaultApacheHttpNotifier implements HttpNotifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of adding a DelegatingHttpNotifier that makes the decision of which notifier to use based on the context? I've found that a simple pattern that makes it easy to retain API compatibility.

class DelegatingHttpNotifier implements HttpNotifier {
    private final HttpNotifier standard;
    private final HttpNotifier extended;

    NotificationResult send (context, ...) {
        return context.supportsExtended() ? extended.send(...) : standard.send(...)
    } 
}

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