Skip to content

The Unified and Autonomous Development Platform

Gate keeper draft.

robin shine09dbca6d4aeb
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/Assess.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/Assess.java
new file mode 100644
index 0000000000..faced8a539
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/Assess.java
@@ -0,0 +1,65 @@
+package com.pmease.gitop.core.model;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+
+import org.hibernate.annotations.FetchMode;
+
+import com.pmease.commons.persistence.AbstractEntity;
+
+@SuppressWarnings("serial")
+@Entity
+@Table(uniqueConstraints={
+ @UniqueConstraint(columnNames={"account", "commit"})
+})
+public class Assess extends AbstractEntity {
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=false)
+ @org.hibernate.annotations.ForeignKey(name="FK_ASS_ACC")
+ private Account account;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=false)
+ @org.hibernate.annotations.ForeignKey(name="FK_ASS_COM")
+ private InvolvedCommit commit;
+
+ private boolean approved;
+
+ public Account getAccount() {
+ return account;
+ }
+
+ public void setAccount(Account account) {
+ this.account = account;
+ }
+
+ public InvolvedCommit getCommit() {
+ return commit;
+ }
+
+ public void setCommit(InvolvedCommit commit) {
+ this.commit = commit;
+ }
+
+ /**
+ * Whether the account accepts or rejects the commit.
+ * <p>
+ * @return
+ * true if approved; false if rejected
+ */
+ public boolean isApproved() {
+ return approved;
+ }
+
+ public void setApproved(boolean approved) {
+ this.approved = approved;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java
index ef5e71d1eb..1e9a0e150f 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java
@@ -1,5 +1,7 @@
package com.pmease.gitop.core.model;
+import java.util.Date;
+
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -12,4 +14,22 @@ public class InvolvedCommit extends AbstractEntity {
@Column(nullable=false, unique=true)
private String revision;
+ private Date date;
+
+ public String getRevision() {
+ return revision;
+ }
+
+ public void setRevision(String revision) {
+ this.revision = revision;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/PullRequest.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/MergeRequest.java
similarity index 75%
rename from gitop.core/src/main/java/com/pmease/gitop/core/model/PullRequest.java
rename to gitop.core/src/main/java/com/pmease/gitop/core/model/MergeRequest.java
index e5421a2dd2..c6e92db1d8 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/PullRequest.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/MergeRequest.java
@@ -1,10 +1,13 @@
package com.pmease.gitop.core.model;
+import java.util.Collection;
+
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
import org.hibernate.annotations.FetchMode;
@@ -12,7 +15,7 @@ import com.pmease.commons.persistence.AbstractEntity;
@SuppressWarnings("serial")
@Entity
-public class PullRequest extends AbstractEntity {
+public class MergeRequest extends AbstractEntity {
@Column(nullable=false)
private String title;
@@ -25,10 +28,13 @@ public class PullRequest extends AbstractEntity {
@ManyToOne(fetch=FetchType.EAGER)
@org.hibernate.annotations.Fetch(FetchMode.SELECT)
- @JoinColumn(nullable=true)
+ @JoinColumn(nullable=false)
@org.hibernate.annotations.ForeignKey(name="FK_PR_SBRCH")
private InvolvedBranch sourceBranch;
+ @OneToMany(mappedBy="request")
+ private Collection<MergeRequestUpdate> updates;
+
public String getTitle() {
return title;
}
@@ -53,4 +59,12 @@ public class PullRequest extends AbstractEntity {
this.sourceBranch = sourceBranch;
}
+ public Collection<MergeRequestUpdate> getUpdates() {
+ return updates;
+ }
+
+ public void setUpdates(Collection<MergeRequestUpdate> updates) {
+ this.updates = updates;
+ }
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/MergeRequestUpdate.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/MergeRequestUpdate.java
new file mode 100644
index 0000000000..ad4111a737
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/MergeRequestUpdate.java
@@ -0,0 +1,61 @@
+package com.pmease.gitop.core.model;
+
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+
+import org.hibernate.annotations.FetchMode;
+
+import com.pmease.commons.persistence.AbstractEntity;
+
+@SuppressWarnings("serial")
+@Entity
+@Table(uniqueConstraints={
+ @UniqueConstraint(columnNames={"request", "commit"})
+})
+public class MergeRequestUpdate extends AbstractEntity {
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=false)
+ @org.hibernate.annotations.ForeignKey(name="FK_UPDATE_REQ")
+ private MergeRequest request;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=false)
+ @org.hibernate.annotations.ForeignKey(name="FK_UPDATE_COM")
+ private InvolvedCommit commit;
+
+ private Date date;
+
+ public MergeRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(MergeRequest request) {
+ this.request = request;
+ }
+
+ public InvolvedCommit getCommit() {
+ return commit;
+ }
+
+ public void setCommit(InvolvedCommit commit) {
+ this.commit = commit;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java
index 251e6e44eb..81e5c447c6 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java
@@ -1,5 +1,8 @@
package com.pmease.gitop.core.model;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -12,6 +15,7 @@ import org.hibernate.annotations.FetchMode;
import com.pmease.commons.persistence.AbstractEntity;
import com.pmease.gitop.core.model.gatekeeper.GateKeeper;
+import com.pmease.gitop.core.model.gatekeeper.GateKeeper.CheckResult;
@Entity
@org.hibernate.annotations.Cache(
@@ -33,8 +37,8 @@ public class Repository extends AbstractEntity {
@org.hibernate.annotations.ForeignKey(name="FK_REPO_ACC")
private Account account;
- @Column(nullable=true)
- private GateKeeper gateKeeper;
+ @Column(nullable=false)
+ private List<GateKeeper> gateKeepers = new ArrayList<GateKeeper>();
public String getName() {
return name;
@@ -60,12 +64,29 @@ public class Repository extends AbstractEntity {
this.account = account;
}
- public GateKeeper getGateKeeper() {
- return gateKeeper;
+ public List<GateKeeper> getGateKeepers() {
+ return gateKeepers;
}
- public void setGateKeeper(GateKeeper gateKeeper) {
- this.gateKeeper = gateKeeper;
+ public void setGateKeepers(List<GateKeeper> gateKeepers) {
+ this.gateKeepers = gateKeepers;
}
+ public CheckResult checkMerge(MergeRequest request) {
+ boolean undetermined = false;
+
+ for (GateKeeper each: getGateKeepers()) {
+ CheckResult result = each.check(request);
+ if (result == CheckResult.REJECT)
+ return CheckResult.REJECT;
+ else if (result == CheckResult.UNDETERMINED)
+ undetermined = true;
+ }
+
+ if (undetermined)
+ return CheckResult.UNDETERMINED;
+ else
+ return CheckResult.ACCEPT;
+ }
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/AndGateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/AndGateKeeper.java
deleted file mode 100644
index 3b7c73d755..0000000000
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/AndGateKeeper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.pmease.gitop.core.model.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.pmease.gitop.core.model.InvolvedCommit;
-
-public class AndGateKeeper implements GateKeeper {
-
- private List<GateKeeper> gateKeepers = new ArrayList<GateKeeper>();
-
- public List<GateKeeper> getGateKeepers() {
- return gateKeepers;
- }
-
- public void setGateKeepers(List<GateKeeper> gateKeepers) {
- this.gateKeepers = gateKeepers;
- }
-
- @Override
- public CHECK_RESULT check(InvolvedCommit commit) {
- boolean undetermined = false;
-
- for (GateKeeper each: getGateKeepers()) {
- CHECK_RESULT result = each.check(commit);
- if (result == CHECK_RESULT.REJECT)
- return result;
- else if (result == CHECK_RESULT.UNDETERMINED)
- undetermined = true;
- }
-
- if (undetermined)
- return CHECK_RESULT.UNDETERMINED;
- else
- return CHECK_RESULT.ACCEPT;
- }
-
-}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/ApprovedByTeam.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/ApprovedByTeam.java
new file mode 100644
index 0000000000..6eef3810e4
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/ApprovedByTeam.java
@@ -0,0 +1,22 @@
+package com.pmease.gitop.core.model.gatekeeper;
+
+import com.pmease.gitop.core.model.MergeRequest;
+
+public class ApprovedByTeam implements GateKeeper {
+
+ private String teamName;
+
+ public String getTeamName() {
+ return teamName;
+ }
+
+ public void setTeamName(String teamName) {
+ this.teamName = teamName;
+ }
+
+ @Override
+ public CheckResult check(MergeRequest mergeRequest) {
+ return null;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java
index a0cc35c742..22b9e26faf 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java
@@ -1,10 +1,11 @@
package com.pmease.gitop.core.model.gatekeeper;
-import com.pmease.gitop.core.model.InvolvedCommit;
+import com.pmease.gitop.core.model.MergeRequest;
public interface GateKeeper {
- public enum CHECK_RESULT {ACCEPT, REJECT, UNDETERMINED}
+ public enum CheckResult {ACCEPT, REJECT, UNDETERMINED};
- CHECK_RESULT check(InvolvedCommit commit);
+ CheckResult check(MergeRequest mergeRequest);
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/OrGateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/OrGateKeeper.java
deleted file mode 100644
index 6b73bf51a0..0000000000
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/OrGateKeeper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.pmease.gitop.core.model.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.pmease.gitop.core.model.InvolvedCommit;
-
-public class OrGateKeeper implements GateKeeper {
-
- private List<GateKeeper> gateKeepers = new ArrayList<GateKeeper>();
-
- public List<GateKeeper> getGateKeepers() {
- return gateKeepers;
- }
-
- public void setGateKeepers(List<GateKeeper> gateKeepers) {
- this.gateKeepers = gateKeepers;
- }
-
- @Override
- public CHECK_RESULT check(InvolvedCommit commit) {
- boolean undetermined = false;
-
- for (GateKeeper each: getGateKeepers()) {
- CHECK_RESULT result = each.check(commit);
- if (result == CHECK_RESULT.ACCEPT)
- return result;
- else if (result == CHECK_RESULT.UNDETERMINED)
- undetermined = true;
- }
-
- if (undetermined)
- return CHECK_RESULT.UNDETERMINED;
- else
- return CHECK_RESULT.REJECT;
- }
-
-}