Example #1
0
def interpret(message, tracker):
    """
    Look for an issue and/or comment id in the commit message
    and return the appropriate object.
    """
    message = message[0].lower() + message[1:]
    last13 = message[-13:]
    last6 = message[-6:]
    if looks_hashy(last13[:6]) and looks_hashy(last13[7:]):
        issue_id = last13[:6]
        comment_id = last13[7:]
        try:
            issue = Issue(tracker, issue_id)
            redacted = message[:-13]
            return redacted, Comment(issue, comment_id)
        except BadReference:
            pass
    elif looks_hashy(last6):
        try:
            issue = Issue(tracker, last6)
            redacted = message[:-6]
            return redacted, Issue(tracker, last6)
        except BadReference:
            pass
    return message, None
Example #2
0
 def test_comment(self):
     issue = Issue(self.tracker)
     issue.save()
     c = Comment(issue)
     c.save()
     assert type(issue.comment(c.id)) is Comment
     assert issue.comment(c.id).fields == c.fields
Example #3
0
def new(args):
    """Create a new issue."""
    t = args['tracker']
    i = Issue(t)
    config = UserConfig()
    # set the author info
    i.author['name'] = config.user['name']
    i.author['email'] = config.user['email']

    # no editor for inline calls
    if args['message'] is not None:
        i.title = args['message']
        i.content = '.'
    else:
        # get the user's editor
        editor = args['editor'] if args['editor'] else config.core['editor']
        # the Template object opens templates in the editor and parses them.
        template = IssueTemplate('new.hpr')
        path = template.open(editor)
        fields = template.parse(path)
        i.title = fields['title']
        i.content = fields['content']

    if i.save():
        # commit the changes
        if config.core['autocommit']:
            t.autocommit(message='Created a new issue %s' % i.id[:6],
                         author=config.user)
        print 'Created issue %s' % i.id[:6]
Example #4
0
def new():
    """Render the new issue view."""
    tracker, config = setup()
    header = 'Create a new issue'
    if request.method == 'POST':
        issue = Issue(tracker)
        issue.content = request.form['content']
        issue.title = request.form['title']
        labels = request.form['labels']
        if labels:
            issue.labels = labels.split(',')
        else:
            issue.labels = []
        issue.author['name'] = config.user['name']
        issue.author['email'] = config.user['email']
        if issue.save():
            tracker.autocommit(message='Created a new issue %s' % issue.id[:6], 
                               author=config.user)
            return redirect(url_for('issues.view', id=issue.id)) 
        else:
            flash('There was an error saving your issue.')
            return render_template('new.html', selected='issues', 
                                   header=header, tracker=tracker)
    else:
        return render_template('new.html', selected='issues', 
                               header=header, tracker=tracker)
Example #5
0
    def test_save(self):
        issue = Issue(self.tracker)
        issue.title = "test title"
        issue.save()

        # Get the path to the issue and assert that it's there.
        path = self.tracker.get_issue_path(issue.id)
        assert os.path.exists(path)

        # Does the issue initialized from file match the original?
        issue_clone = Issue(self.tracker, issue.id)
        assert issue_clone.fields == issue.fields
Example #6
0
 def test_insert_many(self):
     '''Tests the `insert_many` method'''
     db = Database(self.env.tracker)
     issues = []
     for i in range(20):
         issue = Issue(self.env.tracker)
         issue.save()
         issues.append(issue)
     db.insert_many(issues)
     rows = db.select().execute()
     db_issues = [Issue(self.env.tracker, r['id']) for r in rows]
     # quick check to make sure they're all there.
     assert len(db_issues) == len(issues)
Example #7
0
 def test_insert_many(self):
     '''Tests the `insert_many` method'''
     db = Database(self.env.tracker)
     issues = []
     for i in range(20):
         issue = Issue(self.env.tracker)
         issue.save()
         issues.append(issue)
     db.insert_many(issues)
     rows = db.select().execute()
     db_issues = [Issue(self.env.tracker, r['id']) for r in rows]
     # quick check to make sure they're all there.
     assert len(db_issues) == len(issues)
Example #8
0
 def test_insert(self):
     '''Tests the `insert` method'''
     db = Database(self.env.tracker)
     # make and insert the issue
     issue1 = Issue(self.env.tracker)
     issue1.content = 'test'
     issue1.title = 'Test'
     issue1.save()
     db.insert(issue1)
     rows = db.select().execute()
     issue2 = [Issue(self.env.tracker, r['id']) for r in rows][0]
     # make sure the issues are equal which triggers the __eq__ method.
     assert issue1 == issue2
Example #9
0
def new(args):
    """Create a new issue."""
    t = args['tracker']
    i = Issue(t)
    config = UserConfig()
    # set the author info
    i.author['name'] = config.user['name']
    i.author['email'] = config.user['email']

    # no editor for inline calls
    if args['message'] is not None:
        i.title = args['message']
        i.content = '.'
    else:
        # get the user's editor
        editor = args['editor'] if args['editor'] else config.core['editor']
        # the Template object opens templates in the editor and parses them.
        template = IssueTemplate('new.hpr')
        path = template.open(editor)
        fields = template.parse(path)
        i.title = fields['title']
        i.content = fields['content']

    if i.save():
        # commit the changes
        if config.core['autocommit']:
            t.autocommit(message='Created a new issue %s' % i.id[:6],
                         author=config.user)
        print 'Created issue %s' % i.id[:6]
Example #10
0
    def test_issue(self):
        t = Tracker.new(self.path)
        i1 = Issue(t)
        i1.save()
        i2 = t.issue(i1.id)
        # verify that issue() returns an Issue
        assert type(i2) is Issue
        # verify that the issues match
        assert i1.fields == i2.fields

        # invalid SHAs should raise BadReference
        invalid_sha = get_uuid()
        try:
            t.issue(invalid_sha)
        except BadReference:
            pass
Example #11
0
 def issue(self, sha):
     """
     Return the Issue object with the given SHA1.
     
     :param sha: the issue's SHA1 identifier.
     """
     return Issue(self, sha)
Example #12
0
    def select(self,
               order_by='updated',
               status=None,
               label=None,
               limit=None,
               offset=None,
               reverse=True):
        """
        Return issues, with options to limit, offset, sort, and filter the result set.

        :param order_by: order the results by this column.
        :param status: return results with this status.
        :param limit: maximum number of results to return.
        :param offset: skip the first n-results. 
        :param reverse: results are returned in ascending order if True, 
                        descending if False.
        """
        if order_by == 'updated' or order_by == 'created':
            # Time is stored as float, so they sort in reverse of what we want.
            reverse = not reverse
        if self.has_db:
            order = asc if reverse else desc
            query = self.db.select(order_by=order(order_by),
                                   limit=limit,
                                   offset=offset)
            if status:
                query = query.where(self.table.c.status == status)
            if label:
                query = query.where(self.table.c.labels.like('%' + label +
                                                             '%'))
            rows = query.execute()
            issues = [Issue(self.tracker, r['id']) for r in rows]
        else:
            issues = [
                Issue(self.tracker, sha)
                for sha in self.tracker._get_issue_shas()
            ]
            issues.sort(key=lambda x: getattr(x, order_by), reverse=reverse)
            offset = 0 if offset is None else offset
            if limit is not None:
                issues = issues[offset:(offset + limit)]
            else:
                issues = issues[offset:]
        return issues
Example #13
0
 def test_comments(self):
     issue = Issue(self.tracker)
     issue.save()
     # Make some comments
     comments = [Comment(issue) for i in range(20)]
     for c in comments:
         c.save()
     assert type(issue.comments()) is list
     assert len(issue.comments()) == 20
     assert len(issue.comments(n=15)) == 15
Example #14
0
 def test_comment(self):
     issue = Issue(self.tracker)
     issue.save()
     c = Comment(issue)
     c.save()
     assert type(issue.comment(c.id)) is Comment
     assert issue.comment(c.id).fields == c.fields
Example #15
0
 def test_insert(self):
     '''Tests the `insert` method'''
     db = Database(self.env.tracker)
     # make and insert the issue
     issue1 = Issue(self.env.tracker)
     issue1.content = 'test'
     issue1.title = 'Test'
     issue1.save()
     db.insert(issue1)
     rows = db.select().execute()
     issue2 = [Issue(self.env.tracker, r['id']) for r in rows][0]
     # make sure the issues are equal which triggers the __eq__ method.
     assert issue1 == issue2
Example #16
0
 def test_comments(self):
     issue = Issue(self.tracker)
     issue.save()
     # Make some comments
     comments = [Comment(issue) for i in range(20)]
     for c in comments:
         c.save()
     assert type(issue.comments()) is list
     assert len(issue.comments()) == 20
     assert len(issue.comments(n=15)) == 15
Example #17
0
    def test_save(self):
        issue = Issue(self.tracker)
        issue.title = 'test title'
        issue.save()

        # Get the path to the issue and assert that it's there.
        path = self.tracker.get_issue_path(issue.id)
        assert os.path.exists(path)

        # Does the issue initialized from file match the original?
        issue_clone = Issue(self.tracker, issue.id)
        assert issue_clone.fields == issue.fields
Example #18
0
 def search(self, sstr, status=None, n=20):
     """
     Return issues whose title, content, or comments contain the search
     string.
     
     :param sstr: search string, the string to query the database for.
     :param status: if not None, search only issues with the given status.
     :param n: the number of issues.
     """
     if self.has_db:
         sstr = '%' + sstr + '%'
         rows = self.db.conn.execute(
             """SELECT * FROM issues WHERE
                                            title    LIKE ? OR
                                            content  LIKE ? OR
                                            comments LIKE ?
                                     """, (sstr, sstr, sstr))
         rows = rows.fetchmany(n)
         return [Issue(self.tracker, r['id']) for r in rows][::1]
     else:
         raise NotImplementedError
Example #19
0
 def setUp(self):
     self.env = TestEnv()
     self.tracker = self.env.tracker
     self.issue = Issue(self.tracker)
Example #20
0
 def make_issue(self, fields=None):
     '''Make an issue'''
     issue = Issue()
     if fields is not None:
         issue.fields = dict(issue.fields.items() + fields.items())
     return issue
Example #21
0
 def test_ne(self):
     issue1 = Issue(self.tracker)
     issue1.save()
     issue2 = Issue(self.tracker)
     issue2.save()
     assert issue1 != issue2
Example #22
0
 def test_issues(self):
     t = Tracker.new(self.path)
     # make a bunch of issues
     issues = [Issue(t) for i in range(50)]
Example #23
0
 def test_setattr(self):
     issue = Issue(self.tracker)
     issue.title = "test title"
     # Does the __setattr__ method work?
     # i.e.: setting issue.title shoud set issue.fields['title']
     assert issue.title == issue.fields["title"]
Example #24
0
 def test_getattribute(self):
     issue = Issue(self.tracker)
     issue.fields["title"] = "test title"
     # Does the __getattribute__ method work?
     # i.e.: issue.title should return issue.fields['title']
     assert issue.fields["title"] == issue.title
Example #25
0
 def test_setattr(self):
     issue = Issue(self.tracker)
     issue.title = 'test title'
     # Does the __setattr__ method work?
     # i.e.: setting issue.title shoud set issue.fields['title']
     assert issue.title == issue.fields['title']
Example #26
0
 def test_timestamps(self):
     issue = Issue(self.tracker)
     issue.title = "test title"
     issue.save()
     assert issue.created == issue.updated
Example #27
0
 def test_eq(self):
     issue1 = Issue(self.tracker)
     issue1.save()
     issue2 = Issue(self.tracker, issue1.id)
     assert issue1 == issue2
Example #28
0
 def test_ne(self):
     issue1 = Issue(self.tracker)
     issue1.save()
     issue2 = Issue(self.tracker)
     issue2.save()
     assert issue1 != issue2
Example #29
0
 def test_eq(self):
     issue1 = Issue(self.tracker)
     issue1.save()
     issue2 = Issue(self.tracker, issue1.id)
     assert issue1 == issue2
Example #30
0
 def test_getattribute(self):
     issue = Issue(self.tracker)
     issue.fields['title'] = 'test title'
     # Does the __getattribute__ method work?
     # i.e.: issue.title should return issue.fields['title']
     assert issue.fields['title'] == issue.title
Example #31
0
 def _get_issues(self):
     """Returns a list of all issue objects."""
     return [Issue(self, sha) for sha in self._get_issue_shas()]
Example #32
0
 def make_issue(self, fields=None):
     '''Make an issue'''
     issue = Issue()
     if fields is not None:
         issue.fields = dict(issue.fields.items() + fields.items())
     return issue
Example #33
0
 def test_timestamps(self):
     issue = Issue(self.tracker)
     issue.title = 'test title'
     issue.save()
     assert issue.created == issue.updated