Example #1
0
def execute(args):
	
	# First validate arguments
	issueID = identifiers.getFullIssueIdFromLeadingSubstr(args.id)
	if issueID == None:
		# ID is required... no good
		print "Could not find issue: " + args.id
		return None

	# Load the existing issue
	issue = IssueFile.readIssueFromDisk(
							config.ISSUES_DIR + "/" + issueID);
	
	# Are we going to use interactive editing?	
	if args.status == None and args.title == None and args.description == None:
		tmpFile = config.GHI_DIR + "/" + "ISSUE_EDIT";
		IssueFile.writeEditableIssueToDisk(tmpFile, issue)
		tmpFileHash = getCmd("git hash-object " + tmpFile)

		subprocess.call([config.GIT_EDITOR, tmpFile])
		issue = IssueFile.readEditableIssueFromDisk(tmpFile)
		
		# Check to see if the tmpFile is unchanged
		if (tmpFileHash == getCmd("git hash-object " + tmpFile)):
			print "No change in Issue data. Issue not updated"
			return None
	
	# Set the status
	if args.status:
		# There is a potential bug here in situations where there is 
		# more than one status with the same value name
		statusUpdate = None
		for k,v in config.STATUS_OPTS.iteritems():
			if args.status == v:
				statusUpdate = k
				break
		
		if statusUpdate != None:
			issue.setStatus(statusUpdate)
		else:
			print "Status does not exist!"
			return None
	
	# Set title
	if args.title:
		issue.setTitle(args.title)
	
	# Set description
	if args.description:
		issue.setDescription(args.description)
	
	# Make changes to index for commit
	issuepath = config.ISSUES_DIR + "/" + issueID
	IssueFile.writeIssueToDisk(issuepath, issue)
	commit_helper.addToIndex(issuepath)
	
	if args.commit:
		commit_helper.commit()
Example #2
0
def execute(args):
	issue = None
	
	# First validate arguments
	if (args.title == None and args.description == None):
		# If no arguments, drop into interactive mode
		tmpFile = config.GHI_DIR + "/" + "ISSUE_EDIT";
		issue = IssueProto()
		IssueFile.writeEditableIssueToDisk(tmpFile, issue)
		tmpFileHash = getCmd("git hash-object " + tmpFile)
		
		subprocess.call([config.GIT_EDITOR, tmpFile])
		issue = IssueFile.readEditableIssueFromDisk(tmpFile)
		
		# Check to see if the tmpFile is unchanged
		if (tmpFileHash == getCmd("git hash-object " + tmpFile)):
			print "Not enough data to create issue. No issue created."
			return None
	
	elif (args.title == None):
		# Title is required... no good
		print "An issue title is required. Try 'add' with no arguments for interactive mode"
		return None
	
	else:
		# Create new issue
		issue = IssueProto();
		
		# Set title
		issue.setTitle(args.title)
		
		# Set description
		if (args.description):
			issue.setDescription(args.description)

	if (issue):
		# Generate an issue ID
		issueID = str(identifiers.genNewIssueID())
		
		# Make changes to index for commit
		issuepath = config.ISSUES_DIR + "/" + issueID
		IssueFile.writeIssueToDisk(issuepath, issue)
		commit_helper.addToIndex(issuepath)
		
		if args.group:
			Group(args.group).addIssue(issueID)
			commit_helper.addToIndex(config.GROUPS_DIR + '/"' + args.group + '"')
		
		# Display the new issue ID to the user
		print issueID
		
		if args.commit:
			commit_helper.commit()
Example #3
0
def execute(args):
	if (args.id):
		issueID = getFullIssueIdFromLeadingSubstr(args.id)
		if issueID == None:
			print "Could not find issue: " + args.id
			return None
		
		# See if we can remove this issue at all without a --force
		issuePath = getPathFromId(issueID)
		if not args.force:
			issueStatus = getCmd("git status --porcelain -- " + issuePath)
			if issueStatus and issueStatus[0] =='A':
				print "Cannot remove issue without --force"
				return None
		
		# Remove the issue from any groups that contained it
		groupnames = group.getGroupsForIssueId(issueID)
		
		# If we're not forcing the remove, then we need to double-check
		# to make sure that we can actually remove the issue from each
		# group without breaking things... this seems like hack...
		# Why should we be having to check first before we execute later?
		# Should we just perform the change on the group objects and then
		# commit them?... maybe I'm missing something and this isn't a big deal.
		for name in groupnames:
			if not Group(name)._canRmIssueFromGroup(issueID,args.force):
				# Can't perform this operation without a force!
				print "Cannot remove issue from group '" + group + "' without --force"
				return None
				
		# All clear to remove the issue!... groups first if you please...
		for name in groupnames:
			Group(name).rmIssue(issueID, args.force) 
			
			# HACK HACK HACK
			# Should be executing a git command here to add the
			# subsequent group changes to the index, but I'm taking
			# a shortcut for the moment
		
		issueTitle = Issue(issueID).getTitle()
		
		# Remove the issue
		commit_helper.remove(issuePath, args.force)
		
		if args.commit:
			commit_helper.commit()
Example #4
0
def execute(args):
	# Are we deleting something?
	if args.d or args.D:
		
		# see if we're deleting an existing issue from a group
		issueToDelete = args.d if args.d else args.D
		issueID = identifiers.getFullIssueIdFromLeadingSubstr(issueToDelete)
		if issueID:
			force = False if args.d else True
			
			# If no groupname is given, then we will remove from all groups
			# ... notice the hack here where args.id is holding the groupname
			# due to the currently lame and hacky argparsing
			if not args.id:
				# Remove the issue from any groups that contained it
				groupnames = group.getGroupsForIssueId(issueID)
				
				if len(groupnames) == 0:
					print "No groups to delete issue from!"
					return None
				
				# If we're not forcing the remove, then we need to double-check
				# to make sure that we can actually remove the issue from each
				# group without breaking things
				for name in groupnames:
					if not Group(name)._canRmIssue(issueID,force):
						# Can't perform this operation without a force!
						print "Cannot delete issue from group '" + name + "' without force option, '-D'"
						return None
				
				# All clear to remove the issue!... groups first if you please...
				for name in groupnames: 
					Group(name).rmIssue(issueID,force)
					# HACK HACK HACK
					# Should be executing a git command here to add the
					# subsequent group changes to the index, but I'm taking
					# a shortcut for the moment

				return None
			
			# HACK HACK HACK
			# The command line parsing here is totally messed up and so
			# rather than using the groupname we have to pretend here
			# that the id is the groupname... the command line just
			# needs to be rewritten :(
			Group(args.id).rmIssue(issueID, force)
			
			# HACK HACK HACK
			# Should be executing a git command here to add the
			# subsequent group changes to the index, but I'm taking
			# a shortcut for the moment
			return None
		
		# see if we're deleting a group entirely
		if group.exists(args.d):
			print "groupname = " + args.d
			getCmd('git rm "' + Group(args.d).getPath() + '"')
			return None
		elif group.exists(args.D):
			print "groupname = " + args.D
			getCmd('git rm -f "' + Group(args.D).getPath() + '"')
			return None
		
		# tried to delete, but we couldn't figure out what...
		groupname = args.d if args.d else args.D
		print "Could not delete '" + groupname  + "' without force option, '-D'"
		return None
	
	if args.groupname == None and args.id == None:
		print "\n".join(group.getListOfAllGroups())
		return None
	
	if args.groupname == None:
		# We don't support this syntax yet
		print "Command not currently supported"
		return None
	
	# get the full issue ID & Add the issue to the group
	issueID = identifiers.getFullIssueIdFromLeadingSubstr(args.id)
	Group(args.groupname).addIssue(issueID)
	commit_helper.addToIndex('"' + Group(args.groupname).getPath() + '"')
	
	if args.commit:
		commit_helper.commit()