Commit 97b50e81 authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support requestUrl and requestQuesyString properties (#238).

parent 3bbacbd8
package org.gitlab4j.api.systemhooks;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class AbstractSystemHookEvent implements SystemHookEvent {
private String requestUrl;
private String requestQuesryString;
@Override
public void setRequestUrl(String requestUrl) {
this.requestUrl = requestUrl;
}
@Override
@JsonIgnore
public String getRequestUrl() {
return (requestUrl);
}
@Override
public void setRequestQueryString(String requestQuesryString) {
this.requestQuesryString = requestQuesryString;
}
@Override
@JsonIgnore
public String getRequestQueryString() {
return (requestQuesryString);
}
}
...@@ -8,11 +8,11 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -8,11 +8,11 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class GroupMemberSystemHookEvent implements SystemHookEvent { public class GroupMemberSystemHookEvent extends AbstractSystemHookEvent {
public static final String NEW_GROUP_MEMBER_EVENT = "user_add_to_group"; public static final String NEW_GROUP_MEMBER_EVENT = "user_add_to_group";
public static final String GROUP_MEMBER_REMOVED_EVENT = "user_remove_from_group"; public static final String GROUP_MEMBER_REMOVED_EVENT = "user_remove_from_group";
private Date createdAt; private Date createdAt;
private Date updatedAt; private Date updatedAt;
private String eventName; private String eventName;
......
...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class GroupSystemHookEvent implements SystemHookEvent { public class GroupSystemHookEvent extends AbstractSystemHookEvent {
public static final String GROUP_CREATE_EVENT = "group_create"; public static final String GROUP_CREATE_EVENT = "group_create";
public static final String GROUP_DESTROY_EVENT = "group_destroy"; public static final String GROUP_DESTROY_EVENT = "group_destroy";
...@@ -26,7 +26,6 @@ public class GroupSystemHookEvent implements SystemHookEvent { ...@@ -26,7 +26,6 @@ public class GroupSystemHookEvent implements SystemHookEvent {
private String oldPath; private String oldPath;
private String oldFullPath; private String oldFullPath;
public Date getCreatedAt() { public Date getCreatedAt() {
return createdAt; return createdAt;
} }
......
...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class KeySystemHookEvent implements SystemHookEvent { public class KeySystemHookEvent extends AbstractSystemHookEvent {
public static final String KEY_CREATE_EVENT = "key_create"; public static final String KEY_CREATE_EVENT = "key_create";
public static final String KEY_DESTROY_EVENT = "key_destroy"; public static final String KEY_DESTROY_EVENT = "key_destroy";
......
...@@ -10,7 +10,7 @@ import org.gitlab4j.api.models.Visibility; ...@@ -10,7 +10,7 @@ import org.gitlab4j.api.models.Visibility;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class ProjectSystemHookEvent implements SystemHookEvent { public class ProjectSystemHookEvent extends AbstractSystemHookEvent {
public static final String PROJECT_CREATE_EVENT = "project_create"; public static final String PROJECT_CREATE_EVENT = "project_create";
public static final String PROJECT_DESTROY_EVENT = "project_destroy"; public static final String PROJECT_DESTROY_EVENT = "project_destroy";
......
...@@ -10,7 +10,7 @@ import org.gitlab4j.api.webhook.EventProject; ...@@ -10,7 +10,7 @@ import org.gitlab4j.api.webhook.EventProject;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class RepositorySystemHookEvent implements SystemHookEvent { public class RepositorySystemHookEvent extends AbstractSystemHookEvent {
public static final String REPOSITORY_UPDATE_EVENT = "repository_update"; public static final String REPOSITORY_UPDATE_EVENT = "repository_update";
...@@ -26,7 +26,6 @@ public class RepositorySystemHookEvent implements SystemHookEvent { ...@@ -26,7 +26,6 @@ public class RepositorySystemHookEvent implements SystemHookEvent {
private List<RepositoryChange> changes; private List<RepositoryChange> changes;
private List<String> refs; private List<String> refs;
public String getEventName() { public String getEventName() {
return (eventName); return (eventName);
} }
......
package org.gitlab4j.api.systemhooks; package org.gitlab4j.api.systemhooks;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
...@@ -28,7 +29,14 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; ...@@ -28,7 +29,14 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonSubTypes.Type(value = RepositorySystemHookEvent.class, name = RepositorySystemHookEvent.REPOSITORY_UPDATE_EVENT) @JsonSubTypes.Type(value = RepositorySystemHookEvent.class, name = RepositorySystemHookEvent.REPOSITORY_UPDATE_EVENT)
}) })
public interface SystemHookEvent { public interface SystemHookEvent {
public String getEventName();
String getEventName();
void setRequestUrl(String requestUrl);
@JsonIgnore String getRequestUrl();
void setRequestQueryString(String requestQuesryString);
@JsonIgnore String getRequestQueryString();
} }
// All of the following class definitions are needed to make the above work. // All of the following class definitions are needed to make the above work.
......
...@@ -82,6 +82,8 @@ public class SystemHookManager extends HookManager { ...@@ -82,6 +82,8 @@ public class SystemHookManager extends HookManager {
event = jacksonJson.unmarshal(SystemHookEvent.class, reader); event = jacksonJson.unmarshal(SystemHookEvent.class, reader);
} }
event.setRequestUrl(request.getRequestURL().toString());
event.setRequestQueryString(request.getQueryString());
fireEvent(event); fireEvent(event);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -10,7 +10,7 @@ import org.gitlab4j.api.models.Visibility; ...@@ -10,7 +10,7 @@ import org.gitlab4j.api.models.Visibility;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class TeamMemberSystemHookEvent implements SystemHookEvent { public class TeamMemberSystemHookEvent extends AbstractSystemHookEvent {
public static final String NEW_TEAM_MEMBER_EVENT = "user_add_to_team"; public static final String NEW_TEAM_MEMBER_EVENT = "user_add_to_team";
public static final String TEAM_MEMBER_REMOVED_EVENT = "user_remove_from_team"; public static final String TEAM_MEMBER_REMOVED_EVENT = "user_remove_from_team";
......
...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class UserSystemHookEvent implements SystemHookEvent { public class UserSystemHookEvent extends AbstractSystemHookEvent {
public static final String USER_CREATE_EVENT = "user_create"; public static final String USER_CREATE_EVENT = "user_create";
public static final String USER_DESTROY_EVENT = "user_destroy"; public static final String USER_DESTROY_EVENT = "user_destroy";
......
package org.gitlab4j.api.webhook;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class AbstractEvent implements Event {
private String requestUrl;
private String requestQuesryString;
@Override
public void setRequestUrl(String requestUrl) {
this.requestUrl = requestUrl;
}
@Override
@JsonIgnore
public String getRequestUrl() {
return (requestUrl);
}
@Override
public void setRequestQueryString(String requestQuesryString) {
this.requestQuesryString = requestQuesryString;
}
@Override
@JsonIgnore
public String getRequestQueryString() {
return (requestQuesryString);
}
}
...@@ -28,6 +28,9 @@ public abstract class AbstractPushEvent { ...@@ -28,6 +28,9 @@ public abstract class AbstractPushEvent {
private List<EventCommit> commits; private List<EventCommit> commits;
private Integer totalCommitsCount; private Integer totalCommitsCount;
private String requestUrl;
private String requestQuesryString;
public String getEventName() { public String getEventName() {
return (eventName); return (eventName);
} }
...@@ -140,6 +143,24 @@ public abstract class AbstractPushEvent { ...@@ -140,6 +143,24 @@ public abstract class AbstractPushEvent {
this.totalCommitsCount = totalCommitsCount; this.totalCommitsCount = totalCommitsCount;
} }
public void setRequestUrl(String requestUrl) {
this.requestUrl = requestUrl;
}
@JsonIgnore
public String getRequestUrl() {
return (requestUrl);
}
public void setRequestQueryString(String requestQuesryString) {
this.requestQuesryString = requestQuesryString;
}
@JsonIgnore
public String getRequestQueryString() {
return (requestQuesryString);
}
/** /**
* Gets the branch name from the ref. Will return null if the ref does not start with "refs/heads/". * Gets the branch name from the ref. Will return null if the ref does not start with "refs/heads/".
* *
......
...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlAccessorType; ...@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class BuildEvent implements Event { public class BuildEvent extends AbstractEvent {
/** X-Gitlab-Event header value pre GitLab v9.3.0 */ /** X-Gitlab-Event header value pre GitLab v9.3.0 */
public static final String BUILD_HOOK_X_GITLAB_EVENT = "Build Hook"; public static final String BUILD_HOOK_X_GITLAB_EVENT = "Build Hook";
......
package org.gitlab4j.api.webhook; package org.gitlab4j.api.webhook;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
...@@ -17,5 +18,15 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; ...@@ -17,5 +18,15 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonSubTypes.Type(value = WikiPageEvent.class, name = WikiPageEvent.OBJECT_KIND) @JsonSubTypes.Type(value = WikiPageEvent.class, name = WikiPageEvent.OBJECT_KIND)
}) })
public interface Event { public interface Event {
public String getObjectKind(); String getObjectKind();
void setRequestUrl(String url);
@JsonIgnore
String getRequestUrl();
void setRequestQueryString(String queryString);
@JsonIgnore
String getRequestQueryString();
} }
...@@ -7,7 +7,7 @@ import org.gitlab4j.api.models.Assignee; ...@@ -7,7 +7,7 @@ import org.gitlab4j.api.models.Assignee;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class IssueEvent implements Event { public class IssueEvent extends AbstractEvent {
public static final String X_GITLAB_EVENT = "Issue Hook"; public static final String X_GITLAB_EVENT = "Issue Hook";
public static final String OBJECT_KIND = "issue"; public static final String OBJECT_KIND = "issue";
......
...@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlAccessorType; ...@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class MergeRequestEvent implements Event { public class MergeRequestEvent extends AbstractEvent {
public static final String X_GITLAB_EVENT = "Merge Request Hook"; public static final String X_GITLAB_EVENT = "Merge Request Hook";
public static final String OBJECT_KIND = "merge_request"; public static final String OBJECT_KIND = "merge_request";
......
...@@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; ...@@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class NoteEvent implements Event { public class NoteEvent extends AbstractEvent {
public static final String X_GITLAB_EVENT = "Note Hook"; public static final String X_GITLAB_EVENT = "Note Hook";
public static final String OBJECT_KIND = "note"; public static final String OBJECT_KIND = "note";
......
...@@ -10,7 +10,7 @@ import org.gitlab4j.api.models.ArtifactsFile; ...@@ -10,7 +10,7 @@ import org.gitlab4j.api.models.ArtifactsFile;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class PipelineEvent implements Event { public class PipelineEvent extends AbstractEvent {
public static final String X_GITLAB_EVENT = "Pipeline Hook"; public static final String X_GITLAB_EVENT = "Pipeline Hook";
public static final String OBJECT_KIND = "pipeline"; public static final String OBJECT_KIND = "pipeline";
......
...@@ -16,7 +16,8 @@ public class PushEvent extends AbstractPushEvent implements Event { ...@@ -16,7 +16,8 @@ public class PushEvent extends AbstractPushEvent implements Event {
} }
public void setObjectKind(String objectKind) { public void setObjectKind(String objectKind) {
if (!OBJECT_KIND.equals(objectKind)) if (!OBJECT_KIND.equals(objectKind)) {
throw new RuntimeException("Invalid object_kind (" + objectKind + "), must be '" + OBJECT_KIND + "'"); throw new RuntimeException("Invalid object_kind (" + objectKind + "), must be '" + OBJECT_KIND + "'");
}
} }
} }
...@@ -8,6 +8,7 @@ import java.util.logging.Level; ...@@ -8,6 +8,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpUtils;
import org.gitlab4j.api.GitLabApi; import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException; import org.gitlab4j.api.GitLabApiException;
...@@ -93,6 +94,8 @@ public class WebHookManager extends HookManager { ...@@ -93,6 +94,8 @@ public class WebHookManager extends HookManager {
event = jacksonJson.unmarshal(Event.class, reader); event = jacksonJson.unmarshal(Event.class, reader);
} }
event.setRequestUrl(request.getRequestURL().toString());
event.setRequestQueryString(request.getQueryString());
fireEvent(event); fireEvent(event);
} catch (Exception e) { } catch (Exception e) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment