mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Gate keeper draft.
This commit is contained in:
parent
a5adf4cc16
commit
09dbca6d4a
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user