Пример #1
0
    def handler(self, bot, update, *args, **kwargs):
        auth_data = kwargs.get('auth_data')
        username = kwargs.get('username')
        start_date = kwargs.get('start_date')
        end_date = kwargs.get('end_date')

        # check if the user exists on Jira host
        self.app.jira.is_user_on_host(username=username, auth_data=auth_data)
        utils.validate_date_range(start_date, end_date)

        all_worklogs = self.app.jira.get_all_user_worklogs(username,
                                                           start_date,
                                                           end_date,
                                                           auth_data=auth_data)
        all_user_logs = self.app.jira.define_user_worklogs(
            all_worklogs, username, name_key='author_name')

        seconds = sum(
            worklog.get('time_spent_seconds', 0) for worklog in all_user_logs)
        spent_time = utils.calculate_tracking_time(seconds)

        is_united_states_timezone = self.app.jira.get_jira_tz(
            **kwargs) in US_TIMEZONES
        date_fmt = "%m-%d-%Y" if is_united_states_timezone else "%Y-%m-%d"
        template = f'User <b>{username}</b> from <b>{start_date.strftime(date_fmt)}</b> ' \
                   f'to <b>{end_date.strftime(date_fmt)}</b> spent: '
        text = template + str(round(spent_time, 2)) + ' h'
        return self.app.send(bot, update, text=text, **kwargs)
Пример #2
0
 def worklog_deleted(self):
     start_time = int(self.update['changelog']['items'][-1]['from'])
     end_time = int(self.update['changelog']['items'][-1]['to'])
     additional_data = {
         'action': 'deleted',
         'time': round(calculate_tracking_time(end_time - start_time), 2),
     }
     self.data.update(additional_data)
Пример #3
0
    def calculate_spent_time(issues, start_date, end_date, session_data):
        jira_conn = session_data['jira_conn']
        spent_time = 0
        for issue in issues:
            if issue.fields is None:
                continue
            if issue.fields.worklog.total > issue.fields.worklog.maxResults:
                received_worklogs = jira_conn.worklogs(issue.id)  # additional request to JIRA API
            else:
                received_worklogs = issue.fields.worklog.worklogs

            for worklog in received_worklogs:
                worklog_date = pendulum.parse(worklog.started)
                if worklog_date < start_date or worklog_date > end_date:
                    continue

                spent_time += utils.calculate_tracking_time(worklog.timeSpentSeconds)

        return spent_time
Пример #4
0
def test_calculate_tracking_time():
    seconds = 17800
    assert 4.94 == utils.calculate_tracking_time(seconds)
    assert 0.0 == utils.calculate_tracking_time(0)