コード例 #1
0
ファイル: gitlab.py プロジェクト: zotherstupidguy/git-spindle
    def issue(self, opts):
        """[<repo>] [--parent] [<issue>...]
           Show issue details or report an issue"""
        if opts['<repo>'] and opts['<repo>'].isdigit():
            # Let's assume it's an issue
            opts['<issue>'].insert(0, opts['<repo>'])
        repo = self.repository(opts)
        # There's no way to fetch an issue by iid. Abuse search.
        issues = repo.Issue()
        for issue in opts['<issue>']:
            issue = int(issue)
            issue = [x for x in issues if x.iid == issue][0]
            print(wrap(issue.title, attr.bright, attr.underline))
            print(issue.description)
            print(self.issue_url(issue))
        if not opts['<issue>']:
            body = """
# Reporting an issue on %s/%s
# Please describe the issue as clarly as possible. Lines starting with '#' will
# be ignored, the first line will be used as title for the issue.
#""" % (repo.namespace.name, repo.name)
            title, body = self.edit_msg(body, 'ISSUE_EDITMSG')
            if not body:
                err("Empty issue message")

            try:
                issue = glapi.ProjectIssue(self.gl, {'project_id': repo.id, 'title': title, 'description': body})
                issue.save()
                print("Issue %d created %s" % (issue.iid, self.issue_url(issue)))
            except:
                filename = self.backup_message(title, body, 'issue-message-')
                err("Failed to create an issue, the issue text has been saved in %s" % filename)
コード例 #2
0
    def issue(self, opts):
        """[<repo>] [--parent] [<issue>...]
           Show issue details or report an issue"""
        if opts['<repo>'] and opts['<repo>'].isdigit():
            # Let's assume it's an issue
            opts['<issue>'].insert(0, opts['<repo>'])
            opts['<repo>'] = None
        repo = self.repository(opts)
        for issue_no in opts['<issue>']:
            issues = repo.Issue(iid=issue_no)
            if len(issues):
                issue = issues[0]
                print(wrap(issue.title.encode(sys.stdout.encoding, errors='backslashreplace').decode(sys.stdout.encoding), attr.bright, attr.underline))
                print(issue.description.encode(sys.stdout.encoding, errors='backslashreplace').decode(sys.stdout.encoding))
                print(issue.web_url)
            else:
                print('No issue with id %s found in repository %s' % (issue_no, repo.path_with_namespace))
        if not opts['<issue>']:
            extra = """Reporting an issue on %s/%s
Please describe the issue as clearly as possible. Lines starting with '#' will
be ignored, the first line will be used as title for the issue.""" % (repo.namespace.path, repo.path)
            title, body = self.edit_msg(None, '', extra, 'ISSUE_EDITMSG')
            if not body:
                err("Empty issue message")

            try:
                issue = glapi.ProjectIssue(self.gl, {'project_id': repo.id, 'title': title, 'description': body})
                issue.save()
                print("Issue %d created %s" % (issue.iid, issue.web_url))
            except:
                filename = self.backup_message(title, body, 'issue-message-')
                err("Failed to create an issue, the issue text has been saved in %s" % filename)
コード例 #3
0
ファイル: gitlab.py プロジェクト: davidfraser/git-spindle
 def log(self, opts):
     """[<repo>]
        Display GitLab log for a repository"""
     repo = self.repository(opts)
     if not repo:
         return
     now = datetime.datetime.now()
     for event in reversed(repo.Event()):
         ts = datetime.datetime.strptime(event.created_at,
                                         '%Y-%m-%dT%H:%M:%S.%fZ')
         event.data = event.data or {}
         if ts.year == now.year:
             if (ts.month, ts.day) == (now.month, now.day):
                 ts = wrap(ts.strftime("%H:%M"), attr.faint)
             else:
                 ts = wrap(ts.strftime("%m/%d %H:%M"), attr.faint)
         else:
             ts = wrap(ts.strftime("%Y/%m/%d %H:%M"), attr.faint)
         if event.action_name == 'joined':
             print('%s %s joined' % (ts, event.author_username))
         elif event.target_type == 'Issue':
             issue = glapi.ProjectIssue(self.gl,
                                        event.target_id,
                                        project_id=event.project_id)
             print('%s %s %s issue %s (%s)' %
                   (ts, event.author_username, event.action_name, issue.iid,
                    issue.title))
         elif event.target_type == 'MergeRequest':
             issue = glapi.ProjectMergeRequest(self.gl,
                                               event.target_id,
                                               project_id=event.project_id)
             print('%s %s %s merge request %s (%s)' %
                   (ts, event.author_username, event.action_name, issue.iid,
                    issue.title))
         elif event.target_type == 'Note':
             print('%s %s created a comment' % (ts, event.author_username))
         elif 'total_commits_count' in event.data:
             if event.data['total_commits_count'] == 0:
                 print('%s %s deleted branch %s' %
                       (ts, event.author_username, event.data['ref'][11:]))
             else:
                 print('%s %s pushed %s commits to %s' %
                       (ts, event.author_username,
                        event.data['total_commits_count'],
                        event.data['ref'][11:]))
         elif 'ref' in event.data:
             print('%s %s created tag %s' %
                   (ts, event.author_username, event.data['ref'][10:]))
         else:
             print(
                 wrap(
                     "Cannot display event. Please file a bug at github.com/seveas/git-spindle\nincluding the following output:",
                     attr.bright))
             pprint(event.json())
コード例 #4
0
ファイル: gitlab.py プロジェクト: jonathanbarratt/git-spindle
    def issue(self, opts):
        """[<repo>] [--parent] [--message=<message>|--file=<file>|--template=<file>|--reuse-message=<commit>] [--edit] [<issue>...]
           Show issue details or report an issue"""
        if opts['<repo>'] and opts['<repo>'].isdigit():
            # Let's assume it's an issue
            opts['<issue>'].insert(0, opts['<repo>'])
            opts['<repo>'] = None
        repo = self.repository(opts)
        for issue_no in opts['<issue>']:
            issues = repo.Issue(iid=issue_no)
            if len(issues):
                issue = issues[0]
                print(wrap(issue.title, attr.bright, attr.underline))
                print(issue.description)
                print(issue.web_url)
            else:
                print('No issue with id %s found in repository %s' %
                      (issue_no, repo.path_with_namespace))
        if not opts['<issue>']:
            found, edit, template, message = self.determine_message(opts)
            if not found:
                edit = True
                message = """
# Reporting an issue on %s/%s
# Please describe the issue as clearly as possible. Lines starting with '#' will
# be ignored, the first line will be used as title for the issue.
#""" % (repo.namespace.path, repo.path)

            if edit:
                message = self.edit_msg(message, 'ISSUE_EDITMSG', False)

            title, body = (message + '\n').split('\n', 1)
            title = title.strip()
            body = body.strip()

            if not body:
                err("No issue message specified")

            if template and message == template:
                err("Template file was not changed")

            try:
                issue = glapi.ProjectIssue(self.gl, {
                    'project_id': repo.id,
                    'title': title,
                    'description': body
                })
                issue.save()
                print("Issue %d created %s" % (issue.iid, issue.web_url))
            except:
                filename = self.backup_message(title, body, 'issue-message-')
                err("Failed to create an issue, the issue text has been saved in %s"
                    % filename)