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

Commit 319f5de

Browse files
committed
Admin GUI #109 #55 #25
1 parent 8904d03 commit 319f5de

34 files changed

+1701
-387
lines changed

CHANGELOG.md

Lines changed: 81 additions & 51 deletions
Large diffs are not rendered by default.

Gruntfile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ module.exports = function(grunt) {
55

66
jsbeautifier: {
77
files: ["Gruntfile.js",
8-
"**/*.vm",
9-
"**/*.xml",
8+
"src/**/*.vm",
9+
"src/**/*.xml",
1010
"pom.xml",
11-
"**/*.js",
11+
"src/**/*.js",
1212
"Gruntfile.js",
13-
"**/*.css"
13+
"src/**/*.css"
1414
],
1515
options: {
1616
html: {

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The plugin has its own implementation to create the RESCOPED_FROM and RESCOPED_T
4242

4343
The filter text as well as the URL support variables. These are:
4444

45+
* ${EVERYTHING_URL} Example: PULL_REQUEST_ID=1&PULL_REQUEST_TITLE=some%20thing...
4546
* ${PULL_REQUEST_ID} Example: 1
4647
* ${PULL_REQUEST_TITLE} Example: Anything
4748
* ${PULL_REQUEST_VERSION} Example: 1
@@ -102,13 +103,17 @@ Some rest resources are available. You can figure out the JSON structure by look
102103
* `DELETE /{uuid}` Deletes notification with *uuid*.
103104
* `GET` Get all notifications.
104105
* `GET /{uuid}` Get notification with *uuid*.
106+
* `GET /projectKey/{projectKey}` Get all notifications for the project.
107+
* `GET /projectKey/{projectKey}/repositorySlug/{repositorySlug}` Get all notifications for the project and repository.
105108
* `POST` Save a notification.
106109

107110
* `/bitbucket/rest/prnfb-admin/1.0/settings/buttons`
108111
* `DELETE /{uuid}` Deletes button with *uuid*.
109112
* `GET` Get all buttons that the current user is allowed to use.
110113
* `GET /{uuid}` Get button with *uuid*.
111114
* `GET /repository/{repositoryId}/pullrequest/{pullRequestId}` Get all buttons for repository that the current user is allowed to use.
115+
* `GET /projectKey/{projectKey}` Get all buttons for the project.
116+
* `GET /projectKey/{projectKey}/repositorySlug/{repositorySlug}` Get all buttons for the project and repository.
112117
* `POST` Save a button.
113118
* `POST /press` Press the button.
114119

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<gitHubToken>${GITHUB_OAUTH2TOKEN}</gitHubToken>
152152
<gitHubIssuePattern>#([0-9]*)</gitHubIssuePattern>
153153
<filePath>CHANGELOG.md</filePath>
154+
<removeIssueFromMessage>true</removeIssueFromMessage>
154155
<templateContent>
155156
<![CDATA[
156157
# Pull Request Notifier for Bitbucket Changelog

src/main/java/se/bjurr/prnfb/presentation/ButtonServlet.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package se.bjurr.prnfb.presentation;
22

33
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
4-
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
54
import static javax.ws.rs.core.Response.ok;
65
import static javax.ws.rs.core.Response.status;
76
import static javax.ws.rs.core.Response.Status.OK;
@@ -44,21 +43,25 @@ public ButtonServlet(ButtonsService buttonsService, SettingsService settingsServ
4443

4544
@POST
4645
@XsrfProtectionExcluded
47-
@Produces(TEXT_PLAIN)
46+
@Produces(APPLICATION_JSON)
4847
public Response create(ButtonDTO buttonDto) {
4948
if (!this.userCheckService.isAdminAllowed()) {
5049
return status(UNAUTHORIZED).build();
5150
}
5251
PrnfbButton prnfbButton = toPrnfbButton(buttonDto);
53-
this.settingsService.addOrUpdateButton(prnfbButton);
54-
return status(OK).build();
52+
PrnfbButton created = this.settingsService.addOrUpdateButton(prnfbButton);
53+
ButtonDTO createdDto = toButtonDto(created);
54+
55+
return status(OK)//
56+
.entity(createdDto)//
57+
.build();
5558
}
5659

5760
@DELETE
5861
@Path("{uuid}")
5962
@XsrfProtectionExcluded
6063
@Produces(APPLICATION_JSON)
61-
public Response delete(UUID prnfbButton) {
64+
public Response delete(@PathParam("uuid") UUID prnfbButton) {
6265
if (!this.userCheckService.isAdminAllowed()) {
6366
return status(UNAUTHORIZED).build();
6467
}
@@ -88,6 +91,30 @@ public Response get(@PathParam("repositoryId") Integer repositoryId, @PathParam(
8891
return ok(dtos, APPLICATION_JSON).build();
8992
}
9093

94+
@GET
95+
@Path("/projectKey/{projectKey}")
96+
@Produces(APPLICATION_JSON)
97+
public Response get(@PathParam("projectKey") String projectKey) {
98+
if (!this.userCheckService.isViewAllowed()) {
99+
return status(UNAUTHORIZED).build();
100+
}
101+
List<PrnfbButton> buttons = this.settingsService.getButtons(projectKey);
102+
List<ButtonDTO> dtos = toButtonDtoList(buttons);
103+
return ok(dtos, APPLICATION_JSON).build();
104+
}
105+
106+
@GET
107+
@Path("/projectKey/{projectKey}/repositorySlug/{repositorySlug}")
108+
@Produces(APPLICATION_JSON)
109+
public Response get(@PathParam("projectKey") String projectKey, @PathParam("repositorySlug") String repositorySlug) {
110+
if (!this.userCheckService.isViewAllowed()) {
111+
return status(UNAUTHORIZED).build();
112+
}
113+
List<PrnfbButton> buttons = this.settingsService.getButtons(projectKey, repositorySlug);
114+
List<ButtonDTO> dtos = toButtonDtoList(buttons);
115+
return ok(dtos, APPLICATION_JSON).build();
116+
}
117+
91118
@GET
92119
@Path("{uuid}")
93120
@Produces(APPLICATION_JSON)

src/main/java/se/bjurr/prnfb/presentation/NotificationServlet.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static com.google.common.base.Throwables.propagate;
44
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
5-
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
65
import static javax.ws.rs.core.Response.ok;
76
import static javax.ws.rs.core.Response.status;
87
import static javax.ws.rs.core.Response.Status.OK;
@@ -41,18 +40,21 @@ public NotificationServlet(SettingsService settingsService, UserCheckService use
4140

4241
@POST
4342
@XsrfProtectionExcluded
44-
@Produces(TEXT_PLAIN)
43+
@Produces(APPLICATION_JSON)
4544
public Response create(NotificationDTO notificationDto) {
4645
if (!this.userCheckService.isAdminAllowed()) {
4746
return status(UNAUTHORIZED).build();
4847
}
4948
try {
5049
PrnfbNotification prnfbNotification = toPrnfbNotification(notificationDto);
51-
this.settingsService.addOrUpdateNotification(prnfbNotification);
50+
PrnfbNotification created = this.settingsService.addOrUpdateNotification(prnfbNotification);
51+
NotificationDTO createdDto = toNotificationDto(created);
52+
return status(OK)//
53+
.entity(createdDto)//
54+
.build();
5255
} catch (Exception e) {
53-
propagate(e);
56+
throw propagate(e);
5457
}
55-
return status(OK).build();
5658
}
5759

5860
@DELETE
@@ -78,6 +80,30 @@ public Response get() {
7880
return ok(dtos).build();
7981
}
8082

83+
@GET
84+
@Path("/projectKey/{projectKey}")
85+
@Produces(APPLICATION_JSON)
86+
public Response get(@PathParam("projectKey") String projectKey) {
87+
if (!this.userCheckService.isViewAllowed()) {
88+
return status(UNAUTHORIZED).build();
89+
}
90+
List<PrnfbNotification> notifications = this.settingsService.getNotifications(projectKey);
91+
List<NotificationDTO> dtos = toNotificationDtoList(notifications);
92+
return ok(dtos).build();
93+
}
94+
95+
@GET
96+
@Path("/projectKey/{projectKey}/repositorySlug/{repositorySlug}")
97+
@Produces(APPLICATION_JSON)
98+
public Response get(@PathParam("projectKey") String projectKey, @PathParam("repositorySlug") String repositorySlug) {
99+
if (!this.userCheckService.isViewAllowed()) {
100+
return status(UNAUTHORIZED).build();
101+
}
102+
List<PrnfbNotification> notifications = this.settingsService.getNotifications(projectKey, repositorySlug);
103+
List<NotificationDTO> dtos = toNotificationDtoList(notifications);
104+
return ok(dtos).build();
105+
}
106+
81107
@GET
82108
@Path("{uuid}")
83109
@Produces(APPLICATION_JSON)

src/main/java/se/bjurr/prnfb/presentation/dto/ButtonDTO.java

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
@XmlAccessorType(FIELD)
1414
public class ButtonDTO {
1515

16-
private String title;
16+
private String name;
17+
private String projectKey;
18+
private String repositorySlug;
1719
private USER_LEVEL userLevel;
1820
private UUID uuid;
1921

@@ -29,11 +31,25 @@ public boolean equals(Object obj) {
2931
return false;
3032
}
3133
ButtonDTO other = (ButtonDTO) obj;
32-
if (this.title == null) {
33-
if (other.title != null) {
34+
if (this.projectKey == null) {
35+
if (other.projectKey != null) {
3436
return false;
3537
}
36-
} else if (!this.title.equals(other.title)) {
38+
} else if (!this.projectKey.equals(other.projectKey)) {
39+
return false;
40+
}
41+
if (this.repositorySlug == null) {
42+
if (other.repositorySlug != null) {
43+
return false;
44+
}
45+
} else if (!this.repositorySlug.equals(other.repositorySlug)) {
46+
return false;
47+
}
48+
if (this.name == null) {
49+
if (other.name != null) {
50+
return false;
51+
}
52+
} else if (!this.name.equals(other.name)) {
3753
return false;
3854
}
3955
if (this.userLevel != other.userLevel) {
@@ -49,14 +65,26 @@ public boolean equals(Object obj) {
4965
return true;
5066
}
5167

52-
public String getTitle() {
53-
return this.title;
68+
public String getName() {
69+
return this.name;
70+
}
71+
72+
public String getProjectKey() {
73+
return this.projectKey;
74+
}
75+
76+
public String getRepositorySlug() {
77+
return this.repositorySlug;
5478
}
5579

5680
public USER_LEVEL getUserLevel() {
5781
return this.userLevel;
5882
}
5983

84+
public UUID getUuid() {
85+
return this.uuid;
86+
}
87+
6088
public UUID getUUID() {
6189
return this.uuid;
6290
}
@@ -65,14 +93,24 @@ public UUID getUUID() {
6593
public int hashCode() {
6694
final int prime = 31;
6795
int result = 1;
68-
result = prime * result + ((this.title == null) ? 0 : this.title.hashCode());
96+
result = prime * result + ((this.projectKey == null) ? 0 : this.projectKey.hashCode());
97+
result = prime * result + ((this.repositorySlug == null) ? 0 : this.repositorySlug.hashCode());
98+
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
6999
result = prime * result + ((this.userLevel == null) ? 0 : this.userLevel.hashCode());
70100
result = prime * result + ((this.uuid == null) ? 0 : this.uuid.hashCode());
71101
return result;
72102
}
73103

74-
public void setTitle(String title) {
75-
this.title = title;
104+
public void setName(String name) {
105+
this.name = name;
106+
}
107+
108+
public void setProjectKey(String projectKey) {
109+
this.projectKey = projectKey;
110+
}
111+
112+
public void setRepositorySlug(String repositorySlug) {
113+
this.repositorySlug = repositorySlug;
76114
}
77115

78116
public void setUserLevel(USER_LEVEL userLevel) {
@@ -85,7 +123,8 @@ public void setUuid(UUID uuid) {
85123

86124
@Override
87125
public String toString() {
88-
return "ButtonDTO [title=" + this.title + ", userLevel=" + this.userLevel + ", uuid=" + this.uuid + "]";
126+
return "ButtonDTO [name=" + this.name + ", userLevel=" + this.userLevel + ", uuid=" + this.uuid + ", repositorySlug="
127+
+ this.repositorySlug + ", projectKey=" + this.projectKey + "]";
89128
}
90129

91130
}

src/main/java/se/bjurr/prnfb/presentation/dto/HeaderDTO.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import static javax.xml.bind.annotation.XmlAccessType.FIELD;
44

5-
import java.util.UUID;
6-
75
import javax.xml.bind.annotation.XmlAccessorType;
86
import javax.xml.bind.annotation.XmlRootElement;
97

@@ -12,7 +10,6 @@
1210
public class HeaderDTO {
1311

1412
private String name;
15-
private UUID uuid;
1613
private String value;
1714

1815
@Override
@@ -34,13 +31,6 @@ public boolean equals(Object obj) {
3431
} else if (!this.name.equals(other.name)) {
3532
return false;
3633
}
37-
if (this.uuid == null) {
38-
if (other.uuid != null) {
39-
return false;
40-
}
41-
} else if (!this.uuid.equals(other.uuid)) {
42-
return false;
43-
}
4434
if (this.value == null) {
4535
if (other.value != null) {
4636
return false;
@@ -55,10 +45,6 @@ public String getName() {
5545
return this.name;
5646
}
5747

58-
public UUID getUuid() {
59-
return this.uuid;
60-
}
61-
6248
public String getValue() {
6349
return this.value;
6450
}
@@ -68,7 +54,6 @@ public int hashCode() {
6854
final int prime = 31;
6955
int result = 1;
7056
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
71-
result = prime * result + ((this.uuid == null) ? 0 : this.uuid.hashCode());
7257
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
7358
return result;
7459
}
@@ -77,17 +62,13 @@ public void setName(String name) {
7762
this.name = name;
7863
}
7964

80-
public void setUuid(UUID uuid) {
81-
this.uuid = uuid;
82-
}
83-
8465
public void setValue(String value) {
8566
this.value = value;
8667
}
8768

8869
@Override
8970
public String toString() {
90-
return "HeaderDTO [name=" + this.name + ", uuid=" + this.uuid + ", value=" + this.value + "]";
71+
return "HeaderDTO [name=" + this.name + ", value=" + this.value + "]";
9172
}
9273

9374
}

0 commit comments

Comments
 (0)