Skip to content

Commit

Permalink
Merge branch 'webhook' of https://github.com/jihwan0321/yobi into next
Browse files Browse the repository at this point in the history
Reviewed-by: Yi EungJun <[email protected]>
Reviewed-by: Deokhong Kim <[email protected]>
  • Loading branch information
Yi EungJun committed Jun 23, 2015
2 parents 1aedcfb + 2009772 commit 6ca0edd
Show file tree
Hide file tree
Showing 19 changed files with 786 additions and 16 deletions.
98 changes: 86 additions & 12 deletions app/assets/stylesheets/less/_page.less
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
color: #2cb400;
}
}

.d2-program:hover {
background-color:#5f5f5f;
text-decoration:none;
Expand Down Expand Up @@ -2140,7 +2140,7 @@ label.inline-list {
&.over { color:#f36c22; }
}
}

.progress-wrap {
overflow: hidden;
color: #999;
Expand Down Expand Up @@ -3069,7 +3069,7 @@ div.markdown-loader {
min-height: 140px;
padding: 15px 20px;
text-align: left;
clear: both;
clear: both;
}

div.markdown-preview {
Expand Down Expand Up @@ -3482,9 +3482,9 @@ label.issue-item-row {
text-decoration: none;
}

&.name {
&.name {
color : #333;

&:hover {
color:#333;
}
Expand Down Expand Up @@ -3534,15 +3534,15 @@ label.issue-item-row {
&.item-icon {
background-color:#F7F7F7;
color:#3592b5;
font-size: 9px;
font-size: 9px;
padding-top:2px;
line-height: 12px;
border-left:1px solid #EEE;

&:first-child {
border-left:none;
}

&.strong {
color:@primary;
}
Expand Down Expand Up @@ -3686,7 +3686,7 @@ label.issue-item-row {
min-height:30px;
}


.write-comment-box { padding:0; margin-top:20px; }
}

Expand Down Expand Up @@ -5665,7 +5665,7 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
text-decoration:none;
background-color:#fafafa;
}

&.open {
.box-shadow(inset 5px 0px 0px @state-open);
}
Expand Down Expand Up @@ -5849,7 +5849,7 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
margin-top: 15px;
font-weight: normal;
padding:0 15px;

strong {
color:#f36c22;
}
Expand Down Expand Up @@ -5956,7 +5956,7 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
margin-top:10px;
font-size: 13px;
color:#999;
padding-left:20px;
padding-left:20px;

&.np {
padding-left:0 !important;
Expand All @@ -5974,7 +5974,7 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
}
}

.user-link {
.user-link {
color: #3592b5 !important;
font-weight: bold;
}
Expand Down Expand Up @@ -6128,6 +6128,80 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
}
}

.webhook-editor-wrap {
.new-webhook-wrap {
margin:30px auto;

.form-legend {
display:block;
margin-bottom:10px;
}
.form-wrap {
position:relative;
display:inline-block;
vertical-align:top;
}
.input-webhook-payload {
width:355px;
}
.input-webhook-secret {
width:214px;
}
.btn-submit {
vertical-align: top;
min-width:100px;
}
}

.webhook-list-wrap {
margin: 0 auto;

.list-head {
border: 1px solid #ddd;
border-width: 0px 0px 2px;
background: #fafafa;

.payload-url, .secret {
padding-left: 8px;
line-height: 30px;
}
}
.list-item {
border-bottom:1px solid #ddd;

h6 {
padding-left: 8px;
}

.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.table {
table-layout: fixed;

.webhook-secret {
display: block;
font-size: 12px;
}
td {
border-top: none;
&.info {
width: 150px;
}
&.actions {
width: 80px;
text-align: right;
padding-right: 1px;
}
}
}
}
}
}

.category-exclusive {
margin-right:5px;
vertical-align: middle;
Expand Down
55 changes: 55 additions & 0 deletions app/controllers/ProjectApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,61 @@ public static Result detachLabel(String ownerId, String projectName, Long id) {
return status(Http.Status.NO_CONTENT);
}

/**
* @param ownerId the owner login id
* @param projectName the project name
* @return
*/
@IsAllowed(Operation.UPDATE)
public static Result webhooks(String ownerId, String projectName) {
Project project = Project.findByOwnerAndProjectName(ownerId, projectName);
if (project == null) {
// Return 404 Not Found if the project does not exist.
return notFound(ErrorViews.NotFound.render("error.notfound"));
}

return ok(views.html.project.webhooks.render(
"project.webhook",
Webhook.findByProject(project.id),
project));
}

@Transactional
@IsAllowed(Operation.UPDATE)
public static Result newWebhook(String ownerId, String projectName) {
Project project = Project.findByOwnerAndProjectName(ownerId, projectName);
if (project == null) {
// Return 404 Not Found if the project does not exist.
return notFound(ErrorViews.NotFound.render("error.notfound"));
}

Form<Webhook> addWebhookForm = form(Webhook.class).bindFromRequest();
if (addWebhookForm == null) {
Logger.warn("Failed creating webhook: got null form from newWebhook request");
return badRequest();
} else if (addWebhookForm.hasErrors()) {
return badRequest(ErrorViews.BadRequest.render());
}

Webhook.create(project.id,
addWebhookForm.field("payloadUrl").value(),
addWebhookForm.field("secret").value());

return redirect(routes.ProjectApp.webhooks(project.owner, project.name));
}

@Transactional
@IsAllowed(Operation.UPDATE)
public static Result deleteWebhook(String ownerId, String projectName, Long id) {
Webhook webhook = Webhook.find.byId(id);
if (webhook != null) {
webhook.delete();
return ok();
} else {
return notFound(ErrorViews.NotFound.render("error.notfound"));
}
}

@Transactional
@AnonymousCheck(requiresLogin = true, displaysFlashMessage = true)
@IsAllowed(Operation.DELETE)
Expand Down
8 changes: 8 additions & 0 deletions app/models/NotificationEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import models.resource.GlobalResource;
import models.resource.Resource;
import models.resource.ResourceConvertible;
import models.Webhook;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -863,6 +864,13 @@ public static void afterNewCommits(List<RevCommit> commits, List<String> refName
notiEvent.resourceType = project.asResource().getType();
notiEvent.resourceId = project.asResource().getId();
NotificationEvent.add(notiEvent);

List<Webhook> webhookList = Webhook.findByProject(project.id);
for (Webhook webhook : webhookList) {
// Send push event via webhook payload URLs.
String[] eventTypes = {"push"};
webhook.sendRequestToPayloadUrl(eventTypes, commits, refNames, sender, title);
}
}

public static NotificationEvent afterReviewed(PullRequest pullRequest, PullRequestReviewAction reviewAction) {
Expand Down
7 changes: 7 additions & 0 deletions app/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public class Project extends Model implements LabelOwner {
@OneToMany(mappedBy = "originalProject")
public List<Project> forkingProjects;

@OneToMany(mappedBy = "project")
public Set<Webhook> webhooks;

@OneToMany(mappedBy = "project")
public Set<Assignee> assignees;

Expand Down Expand Up @@ -653,6 +656,10 @@ public void delete() {
assignee.delete();
}

for (Webhook webhook : webhooks) {
webhook.delete();
}

for(Posting posting : posts) {
posting.delete();
}
Expand Down
Loading

0 comments on commit 6ca0edd

Please sign in to comment.