Exemple #1
0
Fichier : ji.py Projet : pnw/jiggl
def add_worklog(tce):
    def log():
        started = toggl_strptime(tce.entry['start'])
        return jira.add_worklog(
            tce.ticket,
            timeSpentSeconds=tce.entry['duration'],
            comment=tce.comment,
            started=started,
        )

    try:
        worklog = log()
    except JIRAError as e:
        ticket = jira.issue(tce.ticket)

        status_id = ticket.fields.status.id
        if status_id != COMPLETE:
            print bcolors.fail('Invalid status %s' % status_id)
            raise

        reclose_transition = get_transition_id(status_id)

        jira.transition_issue(ticket, reopen_transition(ticket))
        worklog = log()
        jira.transition_issue(ticket, reclose_transition(ticket))
    return worklog
Exemple #2
0
def add_worklog(tce):
    def log():
        started = toggl_strptime(tce.entry['start'])
        return jira.add_worklog(
            tce.ticket,
            timeSpentSeconds=tce.entry['duration'],
            comment=tce.comment,
            started=started,
        )

    try:
        worklog = log()
    except JIRAError as e:
        ticket = jira.issue(tce.ticket)

        status_id = ticket.fields.status.id
        if status_id != COMPLETE:
            print bcolors.fail('Invalid status %s' % status_id)
            raise

        reclose_transition = get_transition_id(status_id)

        jira.transition_issue(ticket, reopen_transition(ticket))
        worklog = log()
        jira.transition_issue(ticket, reclose_transition(ticket))
    return worklog
Exemple #3
0
 def take_action(self, parsed_args):
     print bcolors.warning('Deleting %s' % settings_filepath)
     if raw_input('Are you sure? (y/N) ').upper() == 'Y':
         try:
             os.remove(settings_filepath)
         except OSError:
             pass
         print 'Done'
     else:
         print bcolors.fail('Cancel logout')
Exemple #4
0
 def take_action(self, parsed_args):
     print bcolors.warning('Deleting %s' % settings_filepath)
     if raw_input('Are you sure? (y/N) ').upper() == 'Y':
         try:
             os.remove(settings_filepath)
         except OSError:
             pass
         print 'Done'
     else:
         print bcolors.fail('Cancel logout')
Exemple #5
0
 def check_jira(self):
     """
     Make sure the user has entered correct jira credentials
     """
     print '\nChecking your Jira credentials...'
     try:
         # Jira automatically does a credentials check when you instantiate the class
         JIRA(self.jira_url, basic_auth=(self.jira_username, self.jira_password))
     except JIRAError:
         raise RuntimeError(bcolors.fail('Invalid Jira credentials.'))
     print bcolors.okblue('Success!')
Exemple #6
0
 def check_toggl(self):
     """
     Make sure the user has entered a correct toggl token
     """
     print '\nChecking your Toggl credentials...'
     toggl = PyToggl(self.toggl_api_token)
     try:
         toggl.query('/me')
     except HTTPError:
         raise RuntimeError(bcolors.fail('Invalid Toggl API token.'))
     print bcolors.okblue('Success!')
Exemple #7
0
 def check_toggl(self):
     """
     Make sure the user has entered a correct toggl token
     """
     print '\nChecking your Toggl credentials...'
     toggl = PyToggl(self.toggl_api_token)
     try:
         toggl.query('/me')
     except HTTPError:
         raise RuntimeError(bcolors.fail('Invalid Toggl API token.'))
     print bcolors.okblue('Success!')
Exemple #8
0
 def check_jira(self):
     """
     Make sure the user has entered correct jira credentials
     """
     print '\nChecking your Jira credentials...'
     try:
         # Jira automatically does a credentials check when you instantiate the class
         JIRA(self.jira_url,
              basic_auth=(self.jira_username, self.jira_password))
     except JIRAError:
         raise RuntimeError(bcolors.fail('Invalid Jira credentials.'))
     print bcolors.okblue('Success!')
Exemple #9
0
def for_day(dt):
    print_welcome_for_date(dt)
    entries = toggl.query('/time_entries', params={'start_date': get_start_for_date(dt),
                                                   'end_date': get_end_for_date(dt)})

    entries = z.map(replace_cologne, entries)

    valid_entries, invalid_entries = split_entries(entries)

    print_invalid_entries(invalid_entries)
    valid_entries = list(z.map(get_val, valid_entries))
    if len(valid_entries) == 0:
        print bcolors.okblue('No time entries to log for today')
        # if not raw_input('\nContinue? (Y/n)') in ('Y', 'y', ''):
        #     exit()
        return

    print_valid_entries(valid_entries)
    print_total_for_day(valid_entries)

    if raw_input('\nLog time? (Y/n) ') not in ('Y', 'y', ''):
        print bcolors.fail('Will not log time. Exiting')
        exit()

    print

    logged_entries = []  # the tickets on Toggl that need to be marked as jiggld

    tces = z.groupby(lambda tce: tce.ticket, z.map(to_tce, valid_entries))
    try:
        for ticked_id, tces in tces.iteritems():
            for tce in tces:
                print_jira_preflight(tce)
                with ensure_open_ticket(ticked_id):
                    # continue
                    try:
                        worklog = add_worklog(tce)
                    except JIRAError as e:
                        if 'non-editable workflow state' in str(e):
                            print bcolors.fail('CANNOT EDIT!')
                            exit()
                        print bcolors.fail(str(e))
                        continue
                    # print tce.entry['id']
                    logged_entries.append(tce.entry)
                    print 'WORKLOG ID', worklog.id
                    record_worklog(tce, worklog.id)
                    print_jira_postflight(tce, None)

                    # if raw_input('Good?') != '':
                    #     print bcolors.fail('Exiting')
                    #     exit()
    except Exception as e:
        print bcolors.fail(str(e))
        raise
    finally:
        if logged_entries:
            print 'Marking %s Toggl entries as tagged' % (len(logged_entries))
            resp = toggl.update_tags(list(z.pluck('id', logged_entries)), [JIGGLD_TAG])
        else:
            print 'No Toggl entries to tag as jiggld'