Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit b8600f3

Browse files
committed
Avoiding looking for legacy settings if no such keys
* Also adding Curl examples to README. * Documenting REST API. Logging legacy settings
1 parent 53eff48 commit b8600f3

File tree

4 files changed

+121
-81
lines changed

4 files changed

+121
-81
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
Changelog of Pull Request Notifier for Bitbucket.
44

55
## Unreleased
6+
### No issue
7+
Doc
8+
9+
[bf28a8fad66abda](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/bf28a8fad66abda) Tomas Bjerre *2016-05-12 17:22:42*
10+
11+
Reusing Podam factory, to use caching
12+
13+
[53eff487fbacd3b](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/53eff487fbacd3b) Tomas Bjerre *2016-05-12 17:18:11*
14+
15+
## 2.20
616
### GitHub [#116](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/116) Not saving configuration
717
Linting with JSHint
818

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,28 @@ Some rest resources are available. You can figure out the JSON structure by look
120120
* `POST` Save a button.
121121
* `POST {uuid}/press/repository/{repositoryId}/pullrequest/{pullRequestId}` Press the button.
122122

123+
A new notification to trigger on *COMMENTED* can be added like this.
124+
```
125+
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":""}]}'
126+
```
127+
128+
It will respond with something like this.
129+
```
130+
{"headers":[],"method":"GET","name":"Notification","triggerIfCanMerge":"ALWAYS","triggerIgnoreStateList":[],"triggers":["COMMENTED"],"url":"http://localhost:80/?abc","uuid":"b1306a3a-5a87-4145-80b7-660bc986dd25"}
131+
```
132+
133+
It can then be changed to trigger on *RESCOPED_FROM* and *RESCOPED_TO* like this.
134+
```
135+
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
136+
```
137+
138+
It will respond with something like this.
139+
```
140+
{"headers":[],"method":"GET","name":"Notification","triggerIfCanMerge":"ALWAYS","triggerIgnoreStateList":[],"triggers":["RESCOPED_FROM","RESCOPED_TO"],"url":"http://localhost:80/?abc","uuid":"b1306a3a-5a87-4145-80b7-660bc986dd25"}
141+
```
142+
143+
You may use Chrome and Developer Tools (press F12) to view rest calls while editing in GUI to find more examples.
144+
123145
### Jenkins
124146
Parameterized Jenkins jobs can be triggered remotely via:
125147
```
@@ -131,6 +153,8 @@ If you are using a CSRF protection in Jenkins, you can use the **Injection URL**
131153
* In the headers section, set header **.crumb** with value **${INJECTION_URL_VALUE}**.
132154

133155
## Developer instructions
156+
The .travis.yml is setting up Atlas SDK and building the plugin. It may help you setup your environment.
157+
134158
Prerequisites:
135159

136160
* 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
159183

160184
Make a release [(detailed instructions)](https://developer.atlassian.com/docs/common-coding-tasks/development-cycle/packaging-and-releasing-your-plugin):
161185
```
162-
mvn release:prepare
163-
mvn release:perform
186+
mvn -B release:prepare -DperformRelease=true release:perform
164187
```

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
<dependency>
105105
<groupId>junit</groupId>
106106
<artifactId>junit</artifactId>
107-
<version>4.12</version>
108107
<scope>test</scope>
109108
</dependency>
110109
<dependency>

src/main/java/se/bjurr/prnfb/service/SettingsService.java

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -250,88 +250,18 @@ private void doDeleteNotification(UUID uuid) {
250250
private PrnfbSettings doGetPrnfbSettings() {
251251
Object storedSettings = this.pluginSettings.get(STORAGE_KEY);
252252
if (storedSettings == null) {
253+
this.logger.info("No settings found for " + STORAGE_KEY + ", looking for legacy settings.");
253254
try {
254-
se.bjurr.prnfb.settings.legacy.PrnfbSettings oldSettings = SettingsStorage.getPrnfbSettings(this.pluginSettings);
255-
256-
String ks = oldSettings.getKeyStore().orNull();
257-
String ksp = oldSettings.getKeyStorePassword().orNull();
258-
String kst = oldSettings.getKeyStoreType();
259-
USER_LEVEL adminRestr = USER_LEVEL.SYSTEM_ADMIN;
260-
if (oldSettings.isAdminsAllowed()) {
261-
adminRestr = USER_LEVEL.ADMIN;
255+
se.bjurr.prnfb.settings.legacy.PrnfbSettings legacySettings = SettingsStorage.getPrnfbSettings(this.pluginSettings);
256+
if (this.pluginSettings.get(se.bjurr.prnfb.settings.legacy.SettingsStorage.STORAGE_KEY) != null
257+
|| this.pluginSettings.get(se.bjurr.prnfb.settings.legacy.SettingsStorage.STORAGE_KEY_PRNFS) != null) {
258+
this.logger.info("Using legacy settings.");
259+
return settingsFromLegacy(legacySettings);
262260
}
263-
if (oldSettings.isUsersAllowed()) {
264-
adminRestr = USER_LEVEL.EVERYONE;
265-
}
266-
267-
boolean shouldAcceptAnyCertificate = false;
268-
269-
List<PrnfbButton> newButtons = newArrayList();
270-
for (se.bjurr.prnfb.settings.legacy.PrnfbButton oldButton : oldSettings.getButtons()) {
271-
USER_LEVEL userLevel = USER_LEVEL.SYSTEM_ADMIN;
272-
if (oldButton.getVisibility() == BUTTON_VISIBILITY.ADMIN) {
273-
userLevel = USER_LEVEL.ADMIN;
274-
}
275-
if (oldButton.getVisibility() == BUTTON_VISIBILITY.EVERYONE) {
276-
userLevel = USER_LEVEL.EVERYONE;
277-
}
278-
newButtons.add(new PrnfbButton(UUID.randomUUID(), oldButton.getTitle(), userLevel, null, null));
279-
}
280-
281-
List<PrnfbNotification> newNotifications = newArrayList();
282-
for (se.bjurr.prnfb.settings.legacy.PrnfbNotification oldNotification : oldSettings.getNotifications()) {
283-
try {
284-
PrnfbNotificationBuilder builder = prnfbNotificationBuilder()//
285-
.withFilterRegexp(oldNotification.getFilterRegexp().orNull())//
286-
.withFilterString(oldNotification.getFilterString().orNull())//
287-
.withInjectionUrl(oldNotification.getInjectionUrl().orNull())//
288-
.withInjectionUrlRegexp(oldNotification.getInjectionUrlRegexp().orNull())//
289-
.withMethod(oldNotification.getMethod())//
290-
.withName(oldNotification.getName())//
291-
.withPassword(oldNotification.getPassword().orNull())//
292-
.withPostContent(oldNotification.getPostContent().orNull())//
293-
.withProxyPassword(oldNotification.getProxyPassword().orNull())//
294-
.withProxyPort(oldNotification.getProxyPort())//
295-
.withProxyServer(oldNotification.getProxyServer().orNull())//
296-
.withProxyUser(oldNotification.getProxyUser().orNull())//
297-
.withTriggerIfCanMerge(TRIGGER_IF_MERGE.valueOf(oldNotification.getTriggerIfCanMerge().name()))//
298-
.withUrl(oldNotification.getUrl())//
299-
.withUser(oldNotification.getUser().orNull());
300-
301-
for (Header h : oldNotification.getHeaders()) {
302-
builder.withHeader(h.getName(), h.getValue());
303-
}
304-
305-
for (PullRequestState t : oldNotification.getTriggerIgnoreStateList()) {
306-
builder.withTriggerIgnoreState(t);
307-
}
308-
309-
for (PrnfbPullRequestAction t : oldNotification.getTriggers()) {
310-
builder.withTrigger(t);
311-
}
312-
313-
newNotifications.add(builder.build());
314-
} catch (ValidationException e) {
315-
this.logger.error("", e);
316-
}
317-
}
318-
319-
return prnfbSettingsBuilder()//
320-
.setPrnfbSettingsData(//
321-
prnfbSettingsDataBuilder()//
322-
.setAdminRestriction(adminRestr)//
323-
.setKeyStore(ks)//
324-
.setKeyStorePassword(ksp)//
325-
.setKeyStoreType(kst)//
326-
.setShouldAcceptAnyCertificate(shouldAcceptAnyCertificate)//
327-
.build())//
328-
.setButtons(newButtons)//
329-
.setNotifications(newNotifications)//
330-
.build();
331-
332-
} catch (se.bjurr.prnfb.settings.legacy.ValidationException e) {
261+
} catch (Exception e) {
333262
this.logger.error("", e);
334263
}
264+
this.logger.info("Creating new default settings.");
335265
return prnfbSettingsBuilder()//
336266
.setPrnfbSettingsData(//
337267
prnfbSettingsDataBuilder()//
@@ -358,6 +288,84 @@ public T perform() throws RuntimeException {
358288
});
359289
}
360290

291+
private PrnfbSettings settingsFromLegacy(se.bjurr.prnfb.settings.legacy.PrnfbSettings oldSettings) {
292+
String ks = oldSettings.getKeyStore().orNull();
293+
String ksp = oldSettings.getKeyStorePassword().orNull();
294+
String kst = oldSettings.getKeyStoreType();
295+
USER_LEVEL adminRestr = USER_LEVEL.SYSTEM_ADMIN;
296+
if (oldSettings.isAdminsAllowed()) {
297+
adminRestr = USER_LEVEL.ADMIN;
298+
}
299+
if (oldSettings.isUsersAllowed()) {
300+
adminRestr = USER_LEVEL.EVERYONE;
301+
}
302+
303+
boolean shouldAcceptAnyCertificate = false;
304+
305+
List<PrnfbButton> newButtons = newArrayList();
306+
for (se.bjurr.prnfb.settings.legacy.PrnfbButton oldButton : oldSettings.getButtons()) {
307+
USER_LEVEL userLevel = USER_LEVEL.SYSTEM_ADMIN;
308+
if (oldButton.getVisibility() == BUTTON_VISIBILITY.ADMIN) {
309+
userLevel = USER_LEVEL.ADMIN;
310+
}
311+
if (oldButton.getVisibility() == BUTTON_VISIBILITY.EVERYONE) {
312+
userLevel = USER_LEVEL.EVERYONE;
313+
}
314+
newButtons.add(new PrnfbButton(UUID.randomUUID(), oldButton.getTitle(), userLevel, null, null));
315+
}
316+
317+
List<PrnfbNotification> newNotifications = newArrayList();
318+
for (se.bjurr.prnfb.settings.legacy.PrnfbNotification oldNotification : oldSettings.getNotifications()) {
319+
try {
320+
PrnfbNotificationBuilder builder = prnfbNotificationBuilder()//
321+
.withFilterRegexp(oldNotification.getFilterRegexp().orNull())//
322+
.withFilterString(oldNotification.getFilterString().orNull())//
323+
.withInjectionUrl(oldNotification.getInjectionUrl().orNull())//
324+
.withInjectionUrlRegexp(oldNotification.getInjectionUrlRegexp().orNull())//
325+
.withMethod(oldNotification.getMethod())//
326+
.withName(oldNotification.getName())//
327+
.withPassword(oldNotification.getPassword().orNull())//
328+
.withPostContent(oldNotification.getPostContent().orNull())//
329+
.withProxyPassword(oldNotification.getProxyPassword().orNull())//
330+
.withProxyPort(oldNotification.getProxyPort())//
331+
.withProxyServer(oldNotification.getProxyServer().orNull())//
332+
.withProxyUser(oldNotification.getProxyUser().orNull())//
333+
.withTriggerIfCanMerge(TRIGGER_IF_MERGE.valueOf(oldNotification.getTriggerIfCanMerge().name()))//
334+
.withUrl(oldNotification.getUrl())//
335+
.withUser(oldNotification.getUser().orNull());
336+
337+
for (Header h : oldNotification.getHeaders()) {
338+
builder.withHeader(h.getName(), h.getValue());
339+
}
340+
341+
for (PullRequestState t : oldNotification.getTriggerIgnoreStateList()) {
342+
builder.withTriggerIgnoreState(t);
343+
}
344+
345+
for (PrnfbPullRequestAction t : oldNotification.getTriggers()) {
346+
builder.withTrigger(t);
347+
}
348+
349+
newNotifications.add(builder.build());
350+
} catch (ValidationException e) {
351+
this.logger.error("", e);
352+
}
353+
}
354+
355+
return prnfbSettingsBuilder()//
356+
.setPrnfbSettingsData(//
357+
prnfbSettingsDataBuilder()//
358+
.setAdminRestriction(adminRestr)//
359+
.setKeyStore(ks)//
360+
.setKeyStorePassword(ksp)//
361+
.setKeyStoreType(kst)//
362+
.setShouldAcceptAnyCertificate(shouldAcceptAnyCertificate)//
363+
.build())//
364+
.setButtons(newButtons)//
365+
.setNotifications(newNotifications)//
366+
.build();
367+
}
368+
361369
private Predicate<HasUuid> withUuid(UUID uuid) {
362370
return new Predicate<HasUuid>() {
363371
@Override

0 commit comments

Comments
 (0)