Пример #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()
Пример #2
0
def _sortIssues(issueIDs, sortBy):
    if sortBy == None:
        return None
    
    if sortBy == 'id':
        # We don't need to do anything here. Since the issues are stored with the id as the
        # filename, then they will be automatically sorted.
        return issueIDs
    
    issuesPathPrefix = config.ISSUES_DIR[len(config.GIT_ROOT) + 1:] # +1 to remove '/'
    issueSortTuple =[]
    
    if sortBy == 'title':
        for issueID in issueIDs:
            issueSortTuple.extend([[Issue(issueID).getTitle(), getFullIssueIdFromLeadingSubstr(issueID)]])
    
    elif sortBy == 'status':
        # Organize the issues into status groups
        for sk in config.STATUS_OPTS:
            issues = getCmd('git grep -n ^' + str(sk) + '$ -- ' + config.ISSUES_DIR)
            if issues != None:
                for i in issues.splitlines():
                    issueSortTuple.extend([[sk, i.split(':')[0][len(issuesPathPrefix) + 1:]]]) # +1 to remove '/'
    
    elif sortBy == 'date' or sortBy == 'cdate':
        for issueID in issueIDs:
            issueSortTuple.extend([[Issue(issueID).getCreatedDate(), getFullIssueIdFromLeadingSubstr(issueID)]])
            
    elif sortBy == 'mdate':
        for issueID in issueIDs:
            issueSortTuple.extend([[Issue(issueID).getModifiedDate(), getFullIssueIdFromLeadingSubstr(issueID)]])
            
    # Sort by Date
    issueSortTuple.sort(key=lambda issue: issue[0])
    
    if len(issueSortTuple) > 0:
        return map (lambda issueID: issueID[1], issueSortTuple)
    
    return None
Пример #3
0
def _getFilteredListofIssueIDs(args):
    if args.id:
        issueId = identifiers.getFullIssueIdFromLeadingSubstr(args.id)
        if issueId == None:
            # See if this is a group ID
            if group.exists(args.id):
                return Group(args.id).getIssueIds()
            else:
                return None
            
        return [issueId]
    
    else:
        return _getAllIssueIDs()
Пример #4
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()
Пример #5
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()