diff --git a/CHANGELOG.md b/CHANGELOG.md index c5221bc3..1d1fa82f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ Changelog of Pull Request Notifier for Bitbucket. ## Unreleased +### No issue + Doc + + [bf28a8fad66abda](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/bf28a8fad66abda) Tomas Bjerre *2016-05-12 17:22:42* + + Reusing Podam factory, to use caching + + [53eff487fbacd3b](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/53eff487fbacd3b) Tomas Bjerre *2016-05-12 17:18:11* + +## 2.20 ### GitHub [#116](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/116) Not saving configuration Linting with JSHint diff --git a/README.md b/README.md index e202b639..acb10aa1 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,28 @@ Some rest resources are available. You can figure out the JSON structure by look * `POST` Save a button. * `POST {uuid}/press/repository/{repositoryId}/pullrequest/{pullRequestId}` Press the button. +A new notification to trigger on *COMMENTED* can be added like this. +``` +curl -u admin:admin 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/notifications' -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' --data-binary '{"uuid":"","name":"","projectKey":"","repositorySlug":"","filterString":"","filterRegexp":"","triggers":["COMMENTED"],"injectionUrl":"","injectionUrlRegexp":"","user":"","password":"","proxyUser":"","proxyPassword":"","proxyServer":"","proxyPort":"","url":"http://localhost:80/?abc","method":"GET","postContent":"","headers":[{"name":"","value":""}]}' +``` + +It will respond with something like this. +``` +{"headers":[],"method":"GET","name":"Notification","triggerIfCanMerge":"ALWAYS","triggerIgnoreStateList":[],"triggers":["COMMENTED"],"url":"http://localhost:80/?abc","uuid":"b1306a3a-5a87-4145-80b7-660bc986dd25"} +``` + +It can then be changed to trigger on *RESCOPED_FROM* and *RESCOPED_TO* like this. +``` +curl -u admin:admin 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/notifications' -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' --data-binary '{"uuid":"b1306a3a-5a87-4145-80b7-660bc986dd25","name":"Notification","projectKey":"","repositorySlug":"","filterString":"","filterRegexp":"","triggerIfCanMerge":"ALWAYS","triggers":["RESCOPED_FROM","RESCOPED_TO"],"injectionUrl":"","injectionUrlRegexp":"","user":"","password":"","proxyUser":"","proxyPassword":"","proxyServer":"","proxyPort":"","url":"http://localhost:80/?abc","method":"GET","postContent":"","headers":[{"name":"","value":""}]}' --compressed +``` + +It will respond with something like this. +``` +{"headers":[],"method":"GET","name":"Notification","triggerIfCanMerge":"ALWAYS","triggerIgnoreStateList":[],"triggers":["RESCOPED_FROM","RESCOPED_TO"],"url":"http://localhost:80/?abc","uuid":"b1306a3a-5a87-4145-80b7-660bc986dd25"} +``` + +You may use Chrome and Developer Tools (press F12) to view rest calls while editing in GUI to find more examples. + ### Jenkins Parameterized Jenkins jobs can be triggered remotely via: ``` @@ -131,6 +153,8 @@ If you are using a CSRF protection in Jenkins, you can use the **Injection URL** * In the headers section, set header **.crumb** with value **${INJECTION_URL_VALUE}**. ## Developer instructions +The .travis.yml is setting up Atlas SDK and building the plugin. It may help you setup your environment. + Prerequisites: * Atlas SDK [(installation instructions)](https://developer.atlassian.com/docs/getting-started/set-up-the-atlassian-plugin-sdk-and-build-a-project). @@ -159,6 +183,5 @@ atlas-debug Make a release [(detailed instructions)](https://developer.atlassian.com/docs/common-coding-tasks/development-cycle/packaging-and-releasing-your-plugin): ``` -mvn release:prepare -mvn release:perform +mvn -B release:prepare -DperformRelease=true release:perform ``` diff --git a/pom.xml b/pom.xml index e9736164..9ea2a793 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,6 @@ junit junit - 4.12 test diff --git a/src/main/java/se/bjurr/prnfb/service/SettingsService.java b/src/main/java/se/bjurr/prnfb/service/SettingsService.java index 26ee5e64..4cd5f13e 100644 --- a/src/main/java/se/bjurr/prnfb/service/SettingsService.java +++ b/src/main/java/se/bjurr/prnfb/service/SettingsService.java @@ -250,88 +250,18 @@ private void doDeleteNotification(UUID uuid) { private PrnfbSettings doGetPrnfbSettings() { Object storedSettings = this.pluginSettings.get(STORAGE_KEY); if (storedSettings == null) { + this.logger.info("No settings found for " + STORAGE_KEY + ", looking for legacy settings."); try { - se.bjurr.prnfb.settings.legacy.PrnfbSettings oldSettings = SettingsStorage.getPrnfbSettings(this.pluginSettings); - - String ks = oldSettings.getKeyStore().orNull(); - String ksp = oldSettings.getKeyStorePassword().orNull(); - String kst = oldSettings.getKeyStoreType(); - USER_LEVEL adminRestr = USER_LEVEL.SYSTEM_ADMIN; - if (oldSettings.isAdminsAllowed()) { - adminRestr = USER_LEVEL.ADMIN; + se.bjurr.prnfb.settings.legacy.PrnfbSettings legacySettings = SettingsStorage.getPrnfbSettings(this.pluginSettings); + if (this.pluginSettings.get(se.bjurr.prnfb.settings.legacy.SettingsStorage.STORAGE_KEY) != null + || this.pluginSettings.get(se.bjurr.prnfb.settings.legacy.SettingsStorage.STORAGE_KEY_PRNFS) != null) { + this.logger.info("Using legacy settings."); + return settingsFromLegacy(legacySettings); } - if (oldSettings.isUsersAllowed()) { - adminRestr = USER_LEVEL.EVERYONE; - } - - boolean shouldAcceptAnyCertificate = false; - - List newButtons = newArrayList(); - for (se.bjurr.prnfb.settings.legacy.PrnfbButton oldButton : oldSettings.getButtons()) { - USER_LEVEL userLevel = USER_LEVEL.SYSTEM_ADMIN; - if (oldButton.getVisibility() == BUTTON_VISIBILITY.ADMIN) { - userLevel = USER_LEVEL.ADMIN; - } - if (oldButton.getVisibility() == BUTTON_VISIBILITY.EVERYONE) { - userLevel = USER_LEVEL.EVERYONE; - } - newButtons.add(new PrnfbButton(UUID.randomUUID(), oldButton.getTitle(), userLevel, null, null)); - } - - List newNotifications = newArrayList(); - for (se.bjurr.prnfb.settings.legacy.PrnfbNotification oldNotification : oldSettings.getNotifications()) { - try { - PrnfbNotificationBuilder builder = prnfbNotificationBuilder()// - .withFilterRegexp(oldNotification.getFilterRegexp().orNull())// - .withFilterString(oldNotification.getFilterString().orNull())// - .withInjectionUrl(oldNotification.getInjectionUrl().orNull())// - .withInjectionUrlRegexp(oldNotification.getInjectionUrlRegexp().orNull())// - .withMethod(oldNotification.getMethod())// - .withName(oldNotification.getName())// - .withPassword(oldNotification.getPassword().orNull())// - .withPostContent(oldNotification.getPostContent().orNull())// - .withProxyPassword(oldNotification.getProxyPassword().orNull())// - .withProxyPort(oldNotification.getProxyPort())// - .withProxyServer(oldNotification.getProxyServer().orNull())// - .withProxyUser(oldNotification.getProxyUser().orNull())// - .withTriggerIfCanMerge(TRIGGER_IF_MERGE.valueOf(oldNotification.getTriggerIfCanMerge().name()))// - .withUrl(oldNotification.getUrl())// - .withUser(oldNotification.getUser().orNull()); - - for (Header h : oldNotification.getHeaders()) { - builder.withHeader(h.getName(), h.getValue()); - } - - for (PullRequestState t : oldNotification.getTriggerIgnoreStateList()) { - builder.withTriggerIgnoreState(t); - } - - for (PrnfbPullRequestAction t : oldNotification.getTriggers()) { - builder.withTrigger(t); - } - - newNotifications.add(builder.build()); - } catch (ValidationException e) { - this.logger.error("", e); - } - } - - return prnfbSettingsBuilder()// - .setPrnfbSettingsData(// - prnfbSettingsDataBuilder()// - .setAdminRestriction(adminRestr)// - .setKeyStore(ks)// - .setKeyStorePassword(ksp)// - .setKeyStoreType(kst)// - .setShouldAcceptAnyCertificate(shouldAcceptAnyCertificate)// - .build())// - .setButtons(newButtons)// - .setNotifications(newNotifications)// - .build(); - - } catch (se.bjurr.prnfb.settings.legacy.ValidationException e) { + } catch (Exception e) { this.logger.error("", e); } + this.logger.info("Creating new default settings."); return prnfbSettingsBuilder()// .setPrnfbSettingsData(// prnfbSettingsDataBuilder()// @@ -358,6 +288,84 @@ public T perform() throws RuntimeException { }); } + private PrnfbSettings settingsFromLegacy(se.bjurr.prnfb.settings.legacy.PrnfbSettings oldSettings) { + String ks = oldSettings.getKeyStore().orNull(); + String ksp = oldSettings.getKeyStorePassword().orNull(); + String kst = oldSettings.getKeyStoreType(); + USER_LEVEL adminRestr = USER_LEVEL.SYSTEM_ADMIN; + if (oldSettings.isAdminsAllowed()) { + adminRestr = USER_LEVEL.ADMIN; + } + if (oldSettings.isUsersAllowed()) { + adminRestr = USER_LEVEL.EVERYONE; + } + + boolean shouldAcceptAnyCertificate = false; + + List newButtons = newArrayList(); + for (se.bjurr.prnfb.settings.legacy.PrnfbButton oldButton : oldSettings.getButtons()) { + USER_LEVEL userLevel = USER_LEVEL.SYSTEM_ADMIN; + if (oldButton.getVisibility() == BUTTON_VISIBILITY.ADMIN) { + userLevel = USER_LEVEL.ADMIN; + } + if (oldButton.getVisibility() == BUTTON_VISIBILITY.EVERYONE) { + userLevel = USER_LEVEL.EVERYONE; + } + newButtons.add(new PrnfbButton(UUID.randomUUID(), oldButton.getTitle(), userLevel, null, null)); + } + + List newNotifications = newArrayList(); + for (se.bjurr.prnfb.settings.legacy.PrnfbNotification oldNotification : oldSettings.getNotifications()) { + try { + PrnfbNotificationBuilder builder = prnfbNotificationBuilder()// + .withFilterRegexp(oldNotification.getFilterRegexp().orNull())// + .withFilterString(oldNotification.getFilterString().orNull())// + .withInjectionUrl(oldNotification.getInjectionUrl().orNull())// + .withInjectionUrlRegexp(oldNotification.getInjectionUrlRegexp().orNull())// + .withMethod(oldNotification.getMethod())// + .withName(oldNotification.getName())// + .withPassword(oldNotification.getPassword().orNull())// + .withPostContent(oldNotification.getPostContent().orNull())// + .withProxyPassword(oldNotification.getProxyPassword().orNull())// + .withProxyPort(oldNotification.getProxyPort())// + .withProxyServer(oldNotification.getProxyServer().orNull())// + .withProxyUser(oldNotification.getProxyUser().orNull())// + .withTriggerIfCanMerge(TRIGGER_IF_MERGE.valueOf(oldNotification.getTriggerIfCanMerge().name()))// + .withUrl(oldNotification.getUrl())// + .withUser(oldNotification.getUser().orNull()); + + for (Header h : oldNotification.getHeaders()) { + builder.withHeader(h.getName(), h.getValue()); + } + + for (PullRequestState t : oldNotification.getTriggerIgnoreStateList()) { + builder.withTriggerIgnoreState(t); + } + + for (PrnfbPullRequestAction t : oldNotification.getTriggers()) { + builder.withTrigger(t); + } + + newNotifications.add(builder.build()); + } catch (ValidationException e) { + this.logger.error("", e); + } + } + + return prnfbSettingsBuilder()// + .setPrnfbSettingsData(// + prnfbSettingsDataBuilder()// + .setAdminRestriction(adminRestr)// + .setKeyStore(ks)// + .setKeyStorePassword(ksp)// + .setKeyStoreType(kst)// + .setShouldAcceptAnyCertificate(shouldAcceptAnyCertificate)// + .build())// + .setButtons(newButtons)// + .setNotifications(newNotifications)// + .build(); + } + private Predicate withUuid(UUID uuid) { return new Predicate() { @Override