27 # Find issues |
27 # Find issues |
28 issues_path = os.path.join(repo.root, issues_dir) |
28 issues_path = os.path.join(repo.root, issues_dir) |
29 if not os.path.exists(issues_path): return |
29 if not os.path.exists(issues_path): return |
30 |
30 |
31 issues = glob.glob(os.path.join(issues_path, '*')) |
31 issues = glob.glob(os.path.join(issues_path, '*')) |
32 |
32 |
33 # Process filter |
33 # Process filter |
34 if opts['filter']: |
34 if opts['filter']: |
35 filters = glob.glob(os.path.join(issues_path, filter_prefix + '*')) |
35 filters = glob.glob(os.path.join(issues_path, filter_prefix + '*')) |
36 config = ConfigParser.SafeConfigParser() |
36 config = ConfigParser.SafeConfigParser() |
37 config.read(filters) |
37 config.read(filters) |
38 if not config.has_section(opts['filter']): |
38 if not config.has_section(opts['filter']): |
39 ui.warning('No filter %s defined\n', opts['filter']) |
39 ui.warning('No filter %s defined\n', opts['filter']) |
40 else: |
40 else: |
41 properties += config.items(opts['filter']) |
41 properties += config.items(opts['filter']) |
42 |
42 |
43 _get_properties(opts['property']) |
43 _get_properties(opts['property']) |
44 |
44 |
45 for issue in issues: |
45 for issue in issues: |
46 mbox = mailbox.mbox(issue) |
46 mbox = mailbox.mbox(issue) |
47 property_match = True |
47 property_match = True |
48 for property,value in properties: |
48 for property,value in properties: |
49 property_match = property_match and (mbox[0][property] == value) |
49 property_match = property_match and (mbox[0][property] == value) |
53 if match_date and not date_match(util.parsedate(mbox[0]['date'])[0]): continue |
53 if match_date and not date_match(util.parsedate(mbox[0]['date'])[0]): continue |
54 ui.write("%s (%d) [%s]: %s\n" % (issue[len(issues_path)+1:], # +1 for trailing / |
54 ui.write("%s (%d) [%s]: %s\n" % (issue[len(issues_path)+1:], # +1 for trailing / |
55 len(mbox)-1, # number of replies (-1 for self) |
55 len(mbox)-1, # number of replies (-1 for self) |
56 mbox[0]['State'], |
56 mbox[0]['State'], |
57 mbox[0]['Subject'])) |
57 mbox[0]['Subject'])) |
58 |
58 |
59 |
59 |
60 def iadd(ui, repo, id = None, comment = 0): |
60 def iadd(ui, repo, id = None, comment = 0): |
61 """Adds a new issue, or comment to an existing issue ID or its comment COMMENT""" |
61 """Adds a new issue, or comment to an existing issue ID or its comment COMMENT""" |
62 |
62 |
63 comment = int(comment) |
63 comment = int(comment) |
64 |
64 |
65 # First, make sure issues have a directory |
65 # First, make sure issues have a directory |
66 issues_path = os.path.join(repo.root, issues_dir) |
66 issues_path = os.path.join(repo.root, issues_dir) |
67 if not os.path.exists(issues_path): os.mkdir(issues_path) |
67 if not os.path.exists(issues_path): os.mkdir(issues_path) |
69 if id: |
69 if id: |
70 issue_fn, issue_id = _find_issue(ui, repo, id) |
70 issue_fn, issue_id = _find_issue(ui, repo, id) |
71 if not issue_fn: |
71 if not issue_fn: |
72 ui.warn('No such issue\n') |
72 ui.warn('No such issue\n') |
73 return |
73 return |
74 |
74 |
75 user = ui.username() |
75 user = ui.username() |
76 |
76 |
77 default_issue_text = "From: %s\nDate: %s\n" % (user, util.datestr(format = date_format)) |
77 default_issue_text = "From: %s\nDate: %s\n" % (user, util.datestr(format = date_format)) |
78 if not id: |
78 if not id: |
79 default_issue_text += "State: %s\n" % state['default'] |
79 default_issue_text += "State: %s\n" % state['default'] |
89 return |
89 return |
90 |
90 |
91 # Create the message |
91 # Create the message |
92 msg = mailbox.mboxMessage(issue) |
92 msg = mailbox.mboxMessage(issue) |
93 msg.set_from('artemis', True) |
93 msg.set_from('artemis', True) |
94 |
94 |
95 # Pick random filename |
95 # Pick random filename |
96 if not id: |
96 if not id: |
97 issue_fn = issues_path |
97 issue_fn = issues_path |
98 while os.path.exists(issue_fn): |
98 while os.path.exists(issue_fn): |
99 issue_id = _random_id() |
99 issue_id = _random_id() |
119 ui.status('Added new issue %s\n' % issue_id) |
119 ui.status('Added new issue %s\n' % issue_id) |
120 |
120 |
121 |
121 |
122 def ishow(ui, repo, id, comment = 0, **opts): |
122 def ishow(ui, repo, id, comment = 0, **opts): |
123 """Shows issue ID, or possibly its comment COMMENT""" |
123 """Shows issue ID, or possibly its comment COMMENT""" |
124 |
124 |
125 comment = int(comment) |
125 comment = int(comment) |
126 issue, id = _find_issue(ui, repo, id) |
126 issue, id = _find_issue(ui, repo, id) |
127 if not issue: return |
127 if not issue: return |
128 mbox = mailbox.mbox(issue) |
128 mbox = mailbox.mbox(issue) |
129 |
129 |
185 return False, 0 |
185 return False, 0 |
186 elif len(issues) > 1: |
186 elif len(issues) > 1: |
187 ui.status("Multiple choices:\n") |
187 ui.status("Multiple choices:\n") |
188 for i in issues: ui.status(' ', i[len(issues_path)+1:], '\n') |
188 for i in issues: ui.status(' ', i[len(issues_path)+1:], '\n') |
189 return False, 0 |
189 return False, 0 |
190 |
190 |
191 return issues[0], issues[0][len(issues_path)+1:] |
191 return issues[0], issues[0][len(issues_path)+1:] |
192 |
192 |
193 def _get_properties(property_list): |
193 def _get_properties(property_list): |
194 return [p.split('=') for p in property_list] |
194 return [p.split('=') for p in property_list] |
195 |
195 |
196 def _write_message(ui, message, index = 0): |
196 def _write_message(ui, message, index = 0): |
197 if index: ui.write("Comment: %d\n" % index) |
197 if index: ui.write("Comment: %d\n" % index) |
198 if ui.verbose: |
198 if ui.verbose: |
199 ui.write(message.as_string().strip() + '\n') |
199 ui.write(message.as_string().strip() + '\n') |
200 else: |
200 else: |