class TestToRally(object):
    """Tests documentation verifier"""

    def __init__(self, rally, config_file, regex_json):
        self.config_file = config_file
        handler = logging.FileHandler(self.config_file['RALLY_LOGGER'])
        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
        handler.setFormatter(formatter)
        log.addHandler(handler)
        self.rally = rally
        self.errors = {}
        self.authors_to_inform = {}

        with open(regex_json) as regex_file:
            regex_expressions = json.load(regex_file)

        self.file_types = {}
        for file_type, regex in regex_expressions['file_types'].items():
            if file_type not in self.file_types:
                self.file_types[file_type] = {}
            self.file_types[file_type]['test_case'] = re.compile(
                r'{0}'.format(regex['test_case']), re.IGNORECASE | re.MULTILINE | re.DOTALL
            )
            self.file_types[file_type]['test_type'] = re.compile(
                r'{0}'.format(regex['test_type']), re.IGNORECASE | re.DOTALL
            )

        self.ignored_tags = regex_expressions['ignored_tags']

        self.re_story_module = re.compile(
            r'{0}'.format(regex_expressions['user_story_module']), re.IGNORECASE | re.DOTALL
        )
        self.re_story_name = re.compile(
            r'{0}'.format(regex_expressions['user_story_name']), re.IGNORECASE | re.DOTALL
        )
        self.re_test_case_name = re.compile(
            r'{0}'.format(regex_expressions['test_case_name']), re.IGNORECASE | re.DOTALL
        )
        self.re_test_folder = re.compile(
            r'{0}'.format(regex_expressions['test_folder']), re.IGNORECASE | re.DOTALL
        )
        self.re_test_contract = re.compile(
            r'{0}'.format(regex_expressions['test_contract']), re.IGNORECASE | re.DOTALL
        )
        self.re_author_id = re.compile(r'.*?([0-9]+)\.js', re.DOTALL)

        #Hipchat integration
        try:
            self.hipster = HypChat(self.config_file['HIPCHAT_TOKEN'])
            self.qe_room = self.hipster.get_user(self.config_file['QE_CHAT']) \
                if 'QE_CHAT_IS_USER' in self.config_file and self.config_file['QE_CHAT_IS_USER'] \
                else self.hipster.get_room(self.config_file['QE_CHAT'])

        except Exception, details:
            log.info('Connection to HipChat was disabled.')
            log.info('REASON: {0}'.format(details))
Esempio n. 2
0
def send_notify(data):

    hp = HypChat(__token__)
    for user in __users__:
        try:
            t_user = hp.get_user(user)
            message=wrap(data)
            t_user.message(message)
        except Exception as e:
            print e
    return True
Esempio n. 3
0
def send_notify(data):

    hp = HypChat(__token__)
    for user in __users__:
        try:
            t_user = hp.get_user(user)
            message = wrap(data)
            t_user.message(message)
        except Exception as e:
            print e
    return True
class JiraService:
    def __init__(self):
        self.jira = JIRA(server=os.environ['JIRA_INSTANCE'], basic_auth=(os.environ['JIRA_USER'], os.environ['JIRA_PASSWORD']))
        self.hipchat = HypChat(os.environ['HIPCHAT_TOKEN'], endpoint = "https://puppet.hipchat.com")

        # map of <field-id> -> <field-name>, used to make querying custom fields more readable.
        self.name_map = {field['id'] : field['name'] for field in self.jira.fields()}

    # applies the passed-in JQL filter and returns an array of tickets that match it
    def get_tickets(self, search_filter):
        def process_ticket(ticket):
            ticket_fields = self.get_fields(ticket)
            return {
                "ticket" : ticket.key,
                "status" : ticket_fields["Status"]["name"]
            }

        return [process_ticket(ticket) for ticket in self.jira.search_issues(search_filter)]

    # returns a dictionary with the following keys:
    #   (1) involved_devs
    #         Nested structure with the following keys:
    #            -Everything that dev_info returns
    #            -category (Either "Assignee", "Watcher", or "Reporter", in that order)
    #   (2) team
    #         Lists the team associated with the ticket
    #
    # NOTE: Some puppet employees might have their e-mails end in @puppetlabs.com instead of
    # @puppet.com -- if this happens, then the code should be modified to try both e-mails when
    # acquiring the dev info.
    #
    # TODO: What if ticket does not have a field? E.g. No team, no assignee, etc. Handle this
    # case!
    def ticket_info(self, ticket):
        def involved_dev_info(involved_dev, category):
            dev_info = self.dev_info("*****@*****.**" % involved_dev['key'])
            dev_info['category'] = category
            return dev_info

        ticket_info = self.get_fields(self.jira.issue(ticket))
        ticket_watchers = self.jira.watchers(ticket)

        # calculate the involved devs
        (assignee, reporter) = tuple(
            [[involved_dev_info(ticket_info[dev_type], dev_type)] if ticket_info[dev_type] else [] for dev_type in ("Assignee", "Reporter")]
        )
        watchers = [involved_dev_info(watcher.raw, "Watcher") for watcher in ticket_watchers.watchers]
        return {
            "involved_devs" : assignee + watchers + reporter,
            "team" : ticket_info["Team"]["value"] if ticket_info["Team"] else None
        }

    # returns a dictionary with the following keys:
    #   (1) name
    #   (2) email
    #   (3) hipchat_alias
    def dev_info(self, dev_email):
        hipchat_info = self.hipchat.get_user(dev_email)
        return {
            'name' : hipchat_info['name'],
            'email' : dev_email,
            'hipchat_alias' : hipchat_info['mention_name']
        }

    # TODO: Make this private after everything's tested
    def get_fields(self, jira_issue):
        return {self.name_map[field_id] : field_value for field_id, field_value in jira_issue.raw['fields'].items()}