From c7acc2e1fa86102bb87e715c8fe4e336329fbcc6 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 23 Jan 2013 08:42:20 -0500
Subject: [PATCH] Include issue tracker hooks in builds

---
 src/com/gitblit/models/RepositoryModel.java |   93 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 87 insertions(+), 6 deletions(-)

diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java
index 44aba1d..a2dab3c 100644
--- a/src/com/gitblit/models/RepositoryModel.java
+++ b/src/com/gitblit/models/RepositoryModel.java
@@ -17,6 +17,7 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -43,7 +44,7 @@
 	// field names are reflectively mapped in EditRepository page
 	public String name;
 	public String description;
-	public String owner;
+	public List<String> owners;
 	public Date lastChange;
 	public boolean hasCommits;
 	public boolean showRemoteBranches;
@@ -75,6 +76,14 @@
 	public boolean allowForks;
 	public Set<String> forks;
 	public String originRepository;
+	public boolean verifyCommitter;
+	public String gcThreshold;
+	public int gcPeriod;
+	public int maxActivityCommits;
+	
+	public transient boolean isCollectingGarbage;
+	public Date lastGC;
+	public String sparkleshareId;
 	
 	public RepositoryModel() {
 		this("", "", "", new Date(0));
@@ -83,12 +92,15 @@
 	public RepositoryModel(String name, String description, String owner, Date lastchange) {
 		this.name = name;
 		this.description = description;
-		this.owner = owner;
 		this.lastChange = lastchange;
 		this.accessRestriction = AccessRestrictionType.NONE;
 		this.authorizationControl = AuthorizationControl.NAMED;
 		this.federationSets = new ArrayList<String>();
-		this.federationStrategy = FederationStrategy.FEDERATE_THIS;		
+		this.federationStrategy = FederationStrategy.FEDERATE_THIS;	
+		this.projectPath = StringUtils.getFirstPathElement(name);
+		this.owners = new ArrayList<String>();
+		
+		addOwner(owner);
 	}
 	
 	public List<String> getLocalBranches() {
@@ -121,6 +133,19 @@
 	public void resetDisplayName() {
 		displayName = null;
 	}
+	
+	@Override
+	public int hashCode() {
+		return name.hashCode();
+	}
+	
+	@Override
+	public boolean equals(Object o) {
+		if (o instanceof RepositoryModel) {
+			return name.equals(((RepositoryModel) o).name);
+		}
+		return false;
+	}
 
 	@Override
 	public String toString() {
@@ -135,6 +160,17 @@
 		return StringUtils.compareRepositoryNames(name, o.name);
 	}
 	
+	public boolean isFork() {
+		return !StringUtils.isEmpty(originRepository);
+	}
+	
+	public boolean isOwner(String username) {
+		if (StringUtils.isEmpty(username) || ArrayUtils.isEmpty(owners)) {
+			return false;
+		}
+		return owners.contains(username.toLowerCase());
+	}
+	
 	public boolean isPersonalRepository() {
 		return !StringUtils.isEmpty(projectPath) && projectPath.charAt(0) == '~';
 	}
@@ -143,12 +179,23 @@
 		return !StringUtils.isEmpty(projectPath) && projectPath.equalsIgnoreCase("~" + username);
 	}
 	
+	public boolean allowAnonymousView() {
+		return !accessRestriction.atLeast(AccessRestrictionType.VIEW);
+	}
+	
+	public boolean isSparkleshared() {
+		return !StringUtils.isEmpty(sparkleshareId);
+	}
+	
 	public RepositoryModel cloneAs(String cloneName) {
 		RepositoryModel clone = new RepositoryModel();
+		clone.originRepository = name;
 		clone.name = cloneName;
+		clone.projectPath = StringUtils.getFirstPathElement(cloneName);
+		clone.isBare = true;
 		clone.description = description;
-		clone.accessRestriction = accessRestriction;
-		clone.authorizationControl = authorizationControl;
+		clone.accessRestriction = AccessRestrictionType.PUSH;
+		clone.authorizationControl = AuthorizationControl.NAMED;
 		clone.federationStrategy = federationStrategy;
 		clone.showReadme = showReadme;
 		clone.showRemoteBranches = false;
@@ -157,6 +204,40 @@
 		clone.useTickets = useTickets;
 		clone.skipSizeCalculation = skipSizeCalculation;
 		clone.skipSummaryMetrics = skipSummaryMetrics;
+		clone.sparkleshareId = sparkleshareId; 
 		return clone;
 	}
-}
\ No newline at end of file
+
+	public void addOwner(String username) {
+		if (!StringUtils.isEmpty(username)) {
+			String name = username.toLowerCase();
+			// a set would be more efficient, but this complicates JSON
+			// deserialization so we enforce uniqueness with an arraylist
+			if (!owners.contains(name)) {
+				owners.add(name);
+			}
+		}
+	}
+
+	public void removeOwner(String username) {
+		if (!StringUtils.isEmpty(username)) {
+			owners.remove(username.toLowerCase());
+		}
+	}
+
+	public void addOwners(Collection<String> usernames) {
+		if (!ArrayUtils.isEmpty(usernames)) {
+			for (String username : usernames) {
+				addOwner(username);
+			}
+		}
+	}
+
+	public void removeOwners(Collection<String> usernames) {
+		if (!ArrayUtils.isEmpty(owners)) {
+			for (String username : usernames) {
+				removeOwner(username);
+			}
+		}
+	}
+}

--
Gitblit v1.9.1