Exemplo n.º 1
0
    def add_comments_for_issue(self, issue_num, journals, attachments):
        """
        Add comments
        """
        if journals is None:
            msg('no journals')
            return

        comment_template = self.jinja_env.get_template('comment.md')

        for j in journals:
            notes = j.get('notes', None)
            if not notes:
                continue

            author_name = j.get('user', {}).get('name', None)
            author_github_username = self.format_name_for_github(author_name)
            comment_attachments = []

            # Find attachments that were added with this comment
            for d in j.get('details'):
                if d.get('property') == 'attachment':
                    attachment = next((x for x in attachments
                                       if str(x.get('id')) == d.get('name')),
                                      None)

                    if attachment is not None:
                        comment_attachments.append(attachment)

            note_dict = { 'description' : translate_for_github(notes)\
                         , 'note_date' : j.get('created_on', None)\
                         , 'author_name' : author_name\
                         , 'author_github_username' : author_github_username\
                         , 'attachments' : comment_attachments\
                         }
            comment_info = comment_template.render(note_dict)

            comment_obj = None
            try:
                comment_obj = self.get_comments_service().create(
                    issue_num, comment_info)
            except requests.exceptions.HTTPError as e:
                msgt('Error creating comment: %s' % e.message)
                continue

            if comment_obj:
                dashes()
                msg('comment created')

                msg('comment id: %s' % comment_obj.id)
                msg('api issue_url: %s' % comment_obj.issue_url)
                msg('api comment url: %s' % comment_obj.url)
                msg('html_url: %s' % comment_obj.html_url)
    def add_comments_for_issue(self, issue_num, journals):
        """
        Add comments
        """
        if journals is None:
            msg("no journals")
            return

        comment_template = self.jinja_env.get_template("comment.md")

        for j in journals:
            notes = j.get("notes", None)
            if not notes:
                continue

            author_name = j.get("user", {}).get("name", None)
            author_github_username = self.format_name_for_github(author_name)

            note_dict = {
                "description": translate_for_github(notes),
                "note_date": j.get("created_on", None),
                "author_name": author_name,
                "author_github_username": author_github_username,
            }
            comment_info = comment_template.render(note_dict)

            comment_obj = None
            try:
                comment_obj = self.get_comments_service().create(issue_num, comment_info)
            except requests.exceptions.HTTPError as e:
                msgt("Error creating comment: %s" % e.message)
                continue

            if comment_obj:
                dashes()
                msg("comment created")

                msg("comment id: %s" % comment_obj.id)
                msg("api issue_url: %s" % comment_obj.issue_url)
                msg("api comment url: %s" % comment_obj.url)
                msg("html_url: %s" % comment_obj.html_url)
Exemplo n.º 3
0
    def add_comments_for_issue(self, issue_num, journals):
        """
        Add comments
        """
        if journals is None:
            msg('no journals')
            return

        comment_template = self.jinja_env.get_template('comment.md')

        for j in journals:
            notes = j.get('notes', None)
            if not notes:
                continue

            author_name = j.get('user', {}).get('name', None)
            author_github_username = self.format_name_for_github(author_name)

            note_dict = { 'description' : translate_for_github(notes)\
                         , 'note_date' : j.get('created_on', None)\
                         , 'author_name' : author_name\
                         , 'author_github_username' : author_github_username\
                         }
            comment_info =  comment_template.render(note_dict)

            comment_obj = None
            try:
                comment_obj = self.get_comments_service().create(issue_num, comment_info)
            except requests.exceptions.HTTPError as e:
                # do we keep on going here or stop?
                msgt('Error creating comment: %s' % e.message)
                continue

            if comment_obj:
                dashes()
                msg('comment created')

                msg('comment id: %s' % comment_obj.id)
                msg('api issue_url: %s' % comment_obj.issue_url)
                msg('api comment url: %s' % comment_obj.url)
                msg('html_url: %s' % comment_obj.html_url)
Exemplo n.º 4
0
    def add_comments_for_issue(self, issue_num, journals):
        """
        Add comments
        """
        if journals is None:
            msg('no journals')
            return

        comment_template = self.jinja_env.get_template('comment.md')

        for j in journals:
            notes = j.get('notes', None)
            if not notes:
                continue

            author_name = j.get('user', {}).get('name', None)
            author_github_username = self.format_name_for_github(author_name)

            note_dict = { 'description' : translate_for_github(notes)\
                         , 'note_date' : j.get('created_on', None)\
                         , 'author_name' : author_name\
                         , 'author_github_username' : author_github_username\
                         }
            comment_info = comment_template.render(note_dict)

            comment_obj = None
            try:
                comment_obj = self.get_comments_service().create(
                    issue_num, comment_info)
            except requests.exceptions.HTTPError as e:
                msgt('Error creating comment: %s' % e.message)
                continue

            if comment_obj:
                dashes()
                msg('comment created')

                msg('comment id: %s' % comment_obj.id)
                msg('api issue_url: %s' % comment_obj.issue_url)
                msg('api comment url: %s' % comment_obj.url)
                msg('html_url: %s' % comment_obj.html_url)
    def make_github_issue(self, redmine_json_fname, **kwargs):
        """
        Create a GitHub issue from JSON for a Redmine issue.

        - Format the GitHub description to include original redmine info: author, link back to redmine ticket, etc
        - Add/Create Labels
        - Add/Create Milestones
        """
        if not os.path.isfile(redmine_json_fname):
            msgx("ERROR.  make_github_issue. file not found: %s" % redmine_json_fname)

        include_comments = kwargs.get("include_comments", True)
        include_assignee = kwargs.get("include_assignee", True)

        json_str = open(redmine_json_fname, "rU").read()
        rd = json.loads(json_str)  # The redmine issue as a python dict

        # msg(json.dumps(rd, indent=4))
        msg("Attempt to create issue: [#%s][%s]" % (rd.get("id"), rd.get("subject")))

        # (1) Format the github issue description
        #
        #
        template = self.jinja_env.get_template("description.md")

        author_name = rd.get("author", {}).get("name", None)
        author_github_username = self.format_name_for_github(author_name)

        desc_dict = {
            "description": translate_for_github(rd.get("description", "no description")),
            "redmine_link": self.format_redmine_issue_link(rd.get("id")),
            "redmine_issue_num": rd.get("id"),
            "start_date": rd.get("start_date", None),
            "author_name": author_name,
            "author_github_username": author_github_username,
            "redmine_assignee": self.get_redmine_assignee_name(rd),
        }

        description_info = template.render(desc_dict)

        #
        # (2) Create the dictionary for the GitHub issue--for the github API
        #
        # self.label_helper.clear_labels(151)
        github_issue_dict = {
            "title": rd.get("subject"),
            "body": description_info,
            "labels": self.label_helper.get_label_names_from_issue(rd),
        }

        milestone_number = self.milestone_manager.get_create_milestone(rd)
        if milestone_number:
            github_issue_dict["milestone"] = milestone_number

        if include_assignee:
            assignee = self.get_assignee(rd)
            if assignee:
                github_issue_dict["assignee"] = assignee

        msg(github_issue_dict)

        #
        # (3) Create the issue on github
        #

        issue_obj = self.get_github_conn().issues.create(github_issue_dict)
        # issue_obj = self.get_github_conn().issues.update(151, github_issue_dict)

        msgt("Github issue created: %s" % issue_obj.number)
        msg("issue id: %s" % issue_obj.id)
        msg("issue url: %s" % issue_obj.html_url)

        # Map the new github Issue number to the redmine issue number
        #
        # redmine2github_id_map.update({ rd.get('id', 'unknown') : issue_obj.number })

        # print( redmine2github_id_map)

        #
        # (4) Add the redmine comments (journals) as github comments
        #
        if include_comments:
            journals = rd.get("journals", None)
            if journals:
                self.add_comments_for_issue(issue_obj.number, journals)

        #
        #   (5) Should this issue be closed?
        #
        if self.is_redmine_issue_closed(rd):
            self.close_github_issue(issue_obj.number)

        return issue_obj.number
Exemplo n.º 6
0
    def make_github_issue(self, redmine_json_fname, **kwargs):
        """
        Create a GitHub issue from JSON for a Redmine issue.

        - Format the GitHub description to include original redmine info: author, link back to redmine ticket, etc
        - Add/Create Labels
        - Add/Create Milestones
        """
        if not os.path.isfile(redmine_json_fname):
            msgx('ERROR.  make_github_issue. file not found: %s' % redmine_json_fname)

        include_comments = kwargs.get('include_comments', True)
        include_assignee = kwargs.get('include_assignee', True)

        json_str = open(redmine_json_fname, 'rU').read()
        rd = json.loads(json_str)       # The redmine issue as a python dict

        #msg(json.dumps(rd, indent=4))
        msg('Attempt to create issue: [#%s][%s]' % (rd.get('id'), rd.get('subject') ))

        # (1) Format the github issue description
        #
        #
        template = self.jinja_env.get_template('description.md')

        author_name = rd.get('author', {}).get('name', None)
        author_github_username = self.format_name_for_github(author_name)

        desc_dict = {'description' : translate_for_github(rd.get('description', 'no description'))\
                    , 'redmine_link' : self.format_redmine_issue_link(rd.get('id'))\
                    , 'redmine_issue_num' : rd.get('id')\
                    , 'start_date' : rd.get('start_date', None)\
                    , 'author_name' : author_name\
                    , 'author_github_username' : author_github_username\
                    , 'redmine_assignee' : self.get_redmine_assignee_name(rd)
        }

        description_info = template.render(desc_dict)

        #
        # (2) Create the dictionary for the GitHub issue--for the github API
        #
        #self.label_helper.clear_labels(151)
        github_issue_dict = { 'title': rd.get('subject')\
                    , 'body' : description_info\
                    , 'labels' : self.label_helper.get_label_names_from_issue(rd)
                    }

        milestone_number = self.milestone_manager.get_create_milestone(rd)
        if milestone_number:
            github_issue_dict['milestone'] = milestone_number

        if include_assignee:
            assignee = self.get_assignee(rd)
            if assignee:
                github_issue_dict['assignee'] = assignee

        msg( github_issue_dict)

        #
        # (3) Create the issue on github
        #

        issue_obj = None
        try:
            issue_obj = self.get_github_conn().issues.create(github_issue_dict)
        except requests.exceptions.HTTPError as e:
            msgt('Error creating issue: %s' % e.message)
        
        #issue_obj = self.get_github_conn().issues.update(151, github_issue_dict)

        msgt('Github issue created: %s' % issue_obj.number)
        msg('issue id: %s' % issue_obj.id)
        msg('issue url: %s' % issue_obj.html_url)


        # Map the new github Issue number to the redmine issue number
        #
        #redmine2github_id_map.update({ rd.get('id', 'unknown') : issue_obj.number })

        #print( redmine2github_id_map)

        #
        # (4) Add the redmine comments (journals) as github comments
        #
        if include_comments:
            journals = rd.get('journals', None)
            if journals:
                self.add_comments_for_issue(issue_obj.number, journals)


        #
        #   (5) Should this issue be closed?
        #
        if self.is_redmine_issue_closed(rd):
            self.close_github_issue(issue_obj.number)

        return issue_obj.number
Exemplo n.º 7
0
    def make_github_issue(self, redmine_json_fname, **kwargs):
        """
        Create a GitHub issue from JSON for a Redmine issue.
        
        - Format the GitHub description to include original redmine info: author, link back to redmine ticket, etc
        - Add/Create Labels
        - Add/Create Milestones
        """
        if not os.path.isfile(redmine_json_fname):
            msgx('ERROR.  make_github_issue. file not found: %s' %
                 redmine_json_fname)

        include_comments = kwargs.get('include_comments', True)
        include_assignee = kwargs.get('include_assignee', True)

        json_str = open(redmine_json_fname, 'rU').read()
        rd = json.loads(json_str)  # The redmine issue as a python dict

        #msg(json.dumps(rd, indent=4))
        msg('Attempt to create issue: [#%s][%s]' %
            (rd.get('id'), rd.get('subject')))

        # (1) Format the github issue description
        #
        #
        template = self.jinja_env.get_template('description.md')

        author_name = rd.get('author', {}).get('name', None)
        author_github_username = self.format_name_for_github(author_name)

        desc_dict = {'description' : translate_for_github(rd.get('description', 'no description'))\
                    , 'redmine_link' : self.format_redmine_issue_link(rd.get('id'))\
                    , 'redmine_issue_num' : rd.get('id')\
                    , 'start_date' : rd.get('start_date', None)\
                    , 'author_name' : author_name\
                    , 'author_github_username' : author_github_username\
                    , 'redmine_assignee' : self.get_redmine_assignee_name(rd)
        }

        description_info = template.render(desc_dict)

        #
        # (2) Create the dictionary for the GitHub issue--for the github API
        #
        #self.label_helper.clear_labels(151)
        github_issue_dict = { 'title': rd.get('subject')\
                    , 'body' : description_info\
                    , 'labels' : self.label_helper.get_label_names_from_issue(rd)
                    }

        milestone_number = self.milestone_manager.get_create_milestone(rd)
        if milestone_number:
            github_issue_dict['milestone'] = milestone_number

        if include_assignee:
            assignee = self.get_assignee(rd)
            if assignee:
                github_issue_dict['assignee'] = assignee

        msg(github_issue_dict)

        #
        # (3) Create the issue on github
        #

        issue_obj = self.get_github_conn().issues.create(github_issue_dict)
        #issue_obj = self.get_github_conn().issues.update(151, github_issue_dict)

        msgt('Github issue created: %s' % issue_obj.number)
        msg('issue id: %s' % issue_obj.id)
        msg('issue url: %s' % issue_obj.html_url)

        # Map the new github Issue number to the redmine issue number
        #
        #redmine2github_id_map.update({ rd.get('id', 'unknown') : issue_obj.number })

        #print( redmine2github_id_map)

        #
        # (4) Add the redmine comments (journals) as github comments
        #
        if include_comments:
            journals = rd.get('journals', None)
            if journals:
                self.add_comments_for_issue(issue_obj.number, journals)

        #
        #   (5) Should this issue be closed?
        #
        if self.is_redmine_issue_closed(rd):
            self.close_github_issue(issue_obj.number)

        return issue_obj.number