Skip to content

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdag committed Mar 12, 2011
2 parents 45c4f0a + 6b12398 commit 45988aa
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 49 deletions.
12 changes: 10 additions & 2 deletions .gitli/.issues
Expand Up @@ -15,9 +15,9 @@ add edit command
1
0.1
5
add post-commit/publish hook when initializing the script to parse commit and automatically close issues... would be cool!
add post-commit hook?
1
0.2
0.3
6
more intelligent init...
1
Expand All @@ -30,3 +30,11 @@ add documentation
add a .gitli directory
1
0.1
9
add tests
1
0.3
10
add colorized output
1
0.2
2 changes: 1 addition & 1 deletion .gitli/.issues-current
@@ -1 +1 @@
0.1
0.2
2 changes: 1 addition & 1 deletion .gitli/.issues-last
@@ -1 +1 @@
8
10
1 change: 1 addition & 0 deletions .gitli/.issues-open
@@ -1 +1,2 @@
5
9
82 changes: 50 additions & 32 deletions README.rst
Expand Up @@ -3,7 +3,7 @@ gitli - Git Lightweight Issue Tracking System

:Authors:
Barthelemy Dagenais
:Version: 0.1
:Version: 0.2

gitli is a simple git extension to manage issues in single-developer projects.

Expand All @@ -19,11 +19,17 @@ Don't hesitate to create issues in the github bug tracker if you have a feature
request or encounter a bug though.


Requirements
------------

This script has been tested on Python 2.6, 2.7, 3.1, and 3.2.


Installation
------------

#. Make the git-li script executable (e.g., `chmod a+x git-li`).
#. Add the git-li script to your path (e.g., `export PATH=$PATH:/path/to/git-li`)
#. Make the git-li script executable (e.g., ``chmod a+x git-li``).
#. Add the git-li script to your path (e.g., ``export PATH=$PATH:/path/to/git-li``)
#. You are done.

Usage
Expand Down Expand Up @@ -59,7 +65,7 @@ values:
Task type: 1-Task, 2-Bug, 3-Enhancement [1]: 2
Milestone: [0.1]:
testgitli $ git li -v new 'My Third Issue'
Task type: 1-Task, 2-Bug, 3-Enhancement [1]: 3
Task type: 1-Task, 2-Bug, 3-Enhancement [1]: 1
Milestone: [0.1]: 0.2
testgitli $ git li new 'My Fourth Issue'

Expand All @@ -68,43 +74,50 @@ The list command:
::

testgitli $ git li list
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Enhancement] [0.2] - open
#4 My Fourth Issue [Task] [0.1] - open
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.2] - open
#4 My Fourth Issue [Task] [0.1] - open

To colorize the output, just enter: ``git config --global add gitli.color auto``

The close command:

::

testgitli $ git li close 4
testgitli $ git li list
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Enhancement] [0.2] - open
#4 My Fourth Issue [Task] [0.1] - closed
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.2] - open
#4 My Fourth Issue [Task] [0.1] - closed

The list command with filters:

::

testgitli $ git li list open
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Enhancement] [0.2] - open
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.2] - open
testgitli $ git li list close
#4 My Fourth Issue [Task] [0.1] - closed
#4 My Fourth Issue [Task] [0.1] - closed
testgitli $ git li open bug
testgitli $ git li list open bug
#2 My Second Issue [Bug] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
testgitli $ git li list open bug 0.1
#2 My Second Issue [Bug] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open

The reopen command:

::

testgitli $ git li reopen 4
testgitli $ git li list
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Enhancement] [0.2] - open
#4 My Fourth Issue [Task] [0.1] - open
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.2] - open
#4 My Fourth Issue [Task] [0.1] - open

Edit an issue (notice the use of default values):

Expand All @@ -115,10 +128,10 @@ Edit an issue (notice the use of default values):
Task type: 1-Task, 2-Bug, 3-Enhancement [3]: 1
Milestone: [0.2]: 0.1
testgitli $ git li list
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.1] - open
#4 My Fourth Issue [Task] [0.1] - open
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.1] - open
#4 My Fourth Issue [Task] [0.1] - open

Update the default milestone:

Expand All @@ -127,13 +140,18 @@ Update the default milestone:
testgitli $ git li milestone 0.2
testgitli $ git li new 'My Fifth Issue'
testgitli $ git li list
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.1] - open
#4 My Fourth Issue [Task] [0.1] - open
#5 My Fifth Issue [Task] [0.2] - open
#1 My First Issue [Task] [0.1] - open
#2 My Second Issue [Bug] [0.1] - open
#3 My Third Issue [Task] [0.1] - open
#4 My Fourth Issue [Task] [0.1] - open
#5 My Fifth Issue [Task] [0.2] - open

The show command:

::

testgitli $ git li show 5
#5 My Fifth Issue [Task] [0.2] - open
#5 My Fifth Issue [Task] [0.2] - open


License
Expand Down
69 changes: 56 additions & 13 deletions git-li
@@ -1,11 +1,20 @@
#!/usr/bin/env python
# coding: utf-8

# For python 2 compatibility
from __future__ import unicode_literals
import optparse
import sys
from os.path import split, join, exists
from os import getcwd, mkdir
from subprocess import check_output

if sys.version_info[0] < 3:
rinput = raw_input
else:
rinput = input

COLOR = ['git', 'config', '--get', 'gitli.color']
GITLIDIR = '.gitli'
ISSUES = '.issues'
OPEN = '.issues-open'
Expand All @@ -18,11 +27,36 @@ OSEPARATOR = '\n'
TTYPES = ['Task', 'Bug', 'Enhancement']


class BColors:
BLUE = '\033[1;34m'
GREEN = '\033[1;32m'
YELLOW = '\033[1;33m'
CYAN = '\033[1;36m'
WHITE = '\033[1;37m'
ENDC = '\033[0m'

def disable(self):
self.BLUE = ''
self.GREEN = ''
self.YELLOW = ''
self.CYAN = ''
self.WHITE = ''
self.ENDC = ''


def is_colored_output():
try:
value = check_output(COLOR).strip().lower().decode('utf-8')
return value in {'auto', 'on', 'true'}
except Exception:
return False


def ask_type(verbose=False, default=1):
if not verbose:
return 1

ttype = input('Task type: 1-Task, 2-Bug, 3-Enhancement [{0}]: '\
ttype = rinput('Task type: 1-Task, 2-Bug, 3-Enhancement [{0}]: '\
.format(default))
ttype = ttype.strip().lower()

Expand All @@ -49,7 +83,7 @@ def ask_milestone(path, verbose=False, default=None):
if not verbose:
return current_value

milestone = input('Milestone: [{0}]: '.format(current_value)).strip()
milestone = rinput('Milestone: [{0}]: '.format(current_value)).strip()
if not milestone:
milestone = current_value

Expand Down Expand Up @@ -142,15 +176,21 @@ def get_issues(path, filters, open_issues, milestones, tasks):
return issues


def print_issues(issues, open_issues):
def print_issues(issues, open_issues, bcolor):
for (number, title, task_id, milestone) in issues:
if number in open_issues:
open_text = 'open'
color = bcolor.YELLOW
else:
open_text = 'closed'
color = bcolor.GREEN

print('#{0} {1} [{2}] [{3}] - {4}'.format(number, title,
TTYPES[task_id - 1], milestone, open_text))
milestone_text = '[' + milestone + ']'
task_text = '[' + TTYPES[task_id - 1] + ']'

print('{5}#{0:<4}{9} {6}{1:<48}{9} {7}{2:<6} {3:<7}{9} - {8}{4}{9}'
.format(number, title, task_text, milestone_text, open_text,
bcolor.CYAN, bcolor.WHITE, bcolor.BLUE, color, bcolor.ENDC))


def init(path):
Expand Down Expand Up @@ -206,7 +246,7 @@ def close_issue(path, issue_number):
remove_open(path, issue_number)


def list_issues(path, filters=None):
def list_issues(path, filters=None, bcolor=BColors()):
if filters is None:
filters = []
else:
Expand All @@ -222,7 +262,7 @@ def list_issues(path, filters=None):

issues = get_issues(path, filters, open_issues, milestones, tasks)

print_issues(issues, open_issues)
print_issues(issues, open_issues, bcolor)


def reopen_issue(path, issue_number):
Expand All @@ -231,11 +271,11 @@ def reopen_issue(path, issue_number):
add_open(path, issue_number)


def show_issue(path, issue_number):
def show_issue(path, issue_number, bcolor=BColors()):
issue = get_issue(path, issue_number)
if issue is not None:
open_issues = get_open_issues(path)
print_issues([issue], open_issues)
print_issues([issue], open_issues, bcolor)
else:
print('Issue #{0} not found'.format(issue_number))

Expand All @@ -253,7 +293,7 @@ def edit_issue(path, issue_number):
print('Issue #{0} unknown'.format(issue_number))
return
else:
title = input('Enter a new title (enter nothing to keep the same): ')
title = rinput('Enter a new title (enter nothing to keep the same): ')
if not title.strip():
title = issue[1]
ttype = ask_type(True, issue[2])
Expand Down Expand Up @@ -302,6 +342,10 @@ if __name__ == '__main__':

(options, args) = parser.parse_args()

bcolor = BColors()
if not is_colored_output():
bcolor.disable()

if len(args) == 0:
parser.print_help()
sys.exit(1)
Expand All @@ -315,7 +359,6 @@ if __name__ == '__main__':
print("Unable to find a git repository. ")
sys.exit(1)


path = join(path, GITLIDIR)
if command == 'init':
init(path)
Expand All @@ -324,11 +367,11 @@ if __name__ == '__main__':
elif command == 'close':
close_issue(path, args[0].strip())
elif command == 'list':
list_issues(path, args)
list_issues(path, args, bcolor)
elif command == 'reopen':
reopen_issue(path, args[0].strip())
elif command == 'show':
show_issue(path, args[0].strip())
show_issue(path, args[0].strip(), bcolor)
elif command == 'edit':
edit_issue(path, args[0].strip())
elif command == 'milestone':
Expand Down

0 comments on commit 45988aa

Please sign in to comment.