def csv2youtrack(params):
    source = dict()
    for s in ('issues', 'comments', 'attachments'):
        if params.get(s + '_file'):
            source[s] = Client(params[s + '_file'])
    if source:
        token = params.get('token')
        if not token and 'token_file' in params:
            try:
                with open(params['token_file'], 'r') as f:
                    token = f.read().strip()
            except (OSError, IOError) as e:
                print("Cannot load token from file: " + str(e))
                sys.exit(1)
        if token:
            target = Connection(params['target_url'], token=token)
        elif 'login' in params:
            target = Connection(params['target_url'],
                                params.get('login', ''),
                                params.get('password', ''))
        else:
            print("You have to provide token or login/password to import data")
            sys.exit(1)

        config = CsvYouTrackImportConfig(csvClient.FIELD_NAMES,
                                         csvClient.FIELD_TYPES)
        importer = CsvYouTrackImporter(source, target, config)
        importer.import_csv()
    else:
        print("Nothing to import.")
def youtrack2youtrack(source_url,
                      source_login,
                      source_password,
                      target_url,
                      target_login,
                      target_password,
                      project_ids,
                      query='',
                      params=None):
    if not len(project_ids):
        print "You should sign at least one project to import"
        return
    if params is None:
        params = {}

    source = Connection(source_url, source_login, source_password)
    target = Connection(target_url, target_login, target_password)
    #, proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, 'localhost', 8888)

    print "Import issue link types"
    for ilt in source.getIssueLinkTypes():
        try:
            print target.createIssueLinkType(ilt)
        except youtrack.YouTrackException, e:
            print e.message
Exemplo n.º 3
0
def sync(master_url, master_root_login, master_root_password, slave_url,
         slave_root_login, slave_root_password, project_id, query,
         fields_to_sync, slave_to_master_map, last_run, debug_mode):

    issue_binder = IssueBinder(slave_to_master_map)

    master = Connection(master_url, master_root_login, master_root_password)
    slave = Connection(slave_url, slave_root_login, slave_root_password)
    logger = Logger(master, slave, master_root_login, slave_root_login)

    current_run = datetime.now()
    synchronizer = YouTrackSynchronizer(master, slave, logger, issue_binder,
                                        project_id, fields_to_sync, query,
                                        last_run, current_run)
    synchronizer.setDebugMode(debug_mode)

    try:
        if get_project(slave, project_id):
            synchronizer.sync()
        else:
            youtrack2youtrack(master_url, master_root_login,
                              master_root_password, slave_url,
                              slave_root_login, slave_root_password,
                              [project_id], query)
            synchronizer.syncAfterImport()
    finally:
        logger.finalize()
        #write dictionary of synchronized issues
        write_sync_map(issue_binder.s_to_m)
Exemplo n.º 4
0
def import_users(source_url, source_login, source_password, target_url,
                 target_login, target_password):

    source = Connection(source_url, source_login, source_password)
    target = Connection(target_url, target_login, target_password)

    _import_all_users(source, target)
Exemplo n.º 5
0
    def __init__(self, params):
        self._params = params
        self._projects = None
        self._max_issue_ids = {}
        self._issue_ids = {}
        self._relations = {}
        self._users = {}
        self._groups = {}
        self._subsystems = {}
        self._versions = {}

        # Connecting to Redmine
        if 'rm_api_key' in params:
            self._source = youtrackutils.redmine.RedmineClient(
                params['rm_api_key'],
                params['rm_url']
            )
        elif 'rm_login' in params:
            self._source = youtrackutils.redmine.RedmineClient(
                None,
                params['rm_url'],
                params.get('rm_login'),
                params.get('rm_password')
            )
        else:
            print("You have to provide Redmine API key or login/password")
            sys.exit(1)

        # Connecting to YouTrack
        token = params.get('token')
        if not token and 'token_file' in params:
            try:
                with open(params['token_file'], 'r') as f:
                    token = f.read().strip()
            except (OSError, IOError) as e:
                print("Cannot load token from file: " + str(e))
                sys.exit(1)
        if token:
            self._target = Connection(params['yt_url'], token=token)
        elif 'yt_login' in params:
            self._target = Connection(params['yt_url'],
                                      params.get('yt_login'),
                                      params.get('yt_password'))
        else:
            print("You have to provide YouTrack token or login/password")
            sys.exit(1)

        if not params.get('project_lead_login'):
            project_lead = params.get('yt_login')
            if not project_lead:
                for login in ('root', 'admin', 'administrator', 'guest'):
                    try:
                        project_lead = self._target.getUser(login).login
                        break
                    except youtrack.YouTrackException:
                        continue
            self._params['project_lead_login'] = project_lead
def googlecode2youtrack(project_name, source_login, source_password, target_url, target_login, target_password,
                        project_id):
    target = Connection(target_url, target_login, target_password)

    try:
        target.getProject(project_id)
    except YouTrackException:
        target.createProjectDetailed(project_id, project_name, "", target_login)

    for field_name, field_type in googleCode.FIELD_TYPES.items():
        create_and_attach_custom_field(target, project_id, field_name, field_type)

    start = 1
    max = 30

    while True:
        source = gdata.projecthosting.client.ProjectHostingClient()
        source.client_login(source_login, source_password, source="youtrack", service="code")
        print "Get issues from " + str(start) + " to " + str(start + max)
        query = gdata.projecthosting.client.Query(start_index=start, max_results=max)
        issues = source.get_issues(project_name, query=query).entry
        start += max

        if len(issues) <= 0:
            break

        target.importIssues(project_id, project_name + " assignees",
            [to_yt_issue(target, project_id, issue, source.get_comments(project_name, issue_id(issue)).entry) for issue
             in issues])
        for issue in issues:
            import_tags(target, project_id, issue)
            import_attachments(target, project_id, project_name, issue, target_login)
    def te_st_live(self):
        yt = Connection('https://tickets.i.gini.net', username, password)
        print 'connected to [%s]' % yt.baseUrl
        all_backend_issues = yt.getIssues('Backend', 'state:complete', 0, 1)
        print 'found %d issues' % len(all_backend_issues)
        changes = yt.get_changes_for_issue(all_backend_issues[0].id)

        state_changes = filter(has_state_changes, changes)
        self.assertEqual(4, len(state_changes))

        open_state_changes = filter(partial(has_new_value, 'In Progress'),
                                    state_changes)
        self.assertEqual(1, len(open_state_changes))

        open_state_time = open_state_changes[0].updated

        open_state_datetime = datetime.datetime.fromtimestamp(open_state_time /
                                                              1000.0)
        self.assertEqual(2016, open_state_datetime.year)
        self.assertEqual(7, open_state_datetime.month)
        self.assertEqual(6, open_state_datetime.day)

        resolved_state_changes = filter(has_resolved_value, state_changes)
        self.assertEqual(1, len(resolved_state_changes))

        complete_state_time = resolved_state_changes[0].updated
        complete_state_datetime = datetime.datetime.fromtimestamp(
            complete_state_time / 1000.0)
        self.assertEqual(2016, complete_state_datetime.year)
        self.assertEqual(7, complete_state_datetime.month)
        self.assertEqual(13, complete_state_datetime.day)

        self.assertEqual(datetime.timedelta(7, 3875, 903000),
                         complete_state_datetime - open_state_datetime)
Exemplo n.º 8
0
def main(argv):
    project_name = ''
    project_id = ''
    project_desc = ''
    project_usr = '******'
    project_pwd = 'Sarasa12'
    svn_cli = pysvn.Client()
    svn_working_path = '/tmp'
    youtrack_url = 'http://localhost:80'
    try:
        opts, args = getopt.getopt(
            argv, "hp:i:d:", ["project_name=", "project_id=", "project_desc="])
    except getopt.GetoptError:
        print 'test.py -p <project_name> -i <project_id> -d <project_desc>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'test.py -p <project_name> -i <project_id> -d <project_desc>'
            sys.exit()
        elif opt in ("-p", "--project_name"):
            project_name = arg
        elif opt in ("-i", "--project_id"):
            project_id = arg
        elif opt in ("-d", "--project_desc"):
            project_desc = arg

    #yt = Connection('http://v-rot-mne-nogi.myjetbrains.com/youtrack', 'root', 'root')
    #, proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, 'localhost', 8888))
    yt = Connection(youtrack_url, project_usr, project_pwd)

    #def createProjectDetailed(self, projectId, name, description, projectLeadLogin, startingNumber=1)
    print yt.createProjectDetailed(project_id, project_name, project_desc,
                                   project_usr, 1)
Exemplo n.º 9
0
def push_event_hook():
    push_event = request.json
    app.logger.debug(push_event)
    user_name = push_event['user_name']
    repo_name = push_event['repository']['name']
    repo_url = push_event['repository']['url']
    repo_homepage = push_event['repository']['homepage']
    refspec = push_event['ref']
    app.logger.debug('Received push event by %s in branch %s on repository %s',
                     user_name, refspec, repo_url)

    for commit in push_event['commits']:
        app.logger.debug('Processing commit %s by %s (%s) in %s', commit['id'],
                         commit['author']['name'], commit['author']['email'],
                         commit['url'])
        commit_time = dateutil.parser.parse(commit['timestamp'])
        issues = re.findall(app.config['REGEX'], commit['message'],
                            re.MULTILINE)
        if not issues:
            app.logger.debug(
                '''Didn't find any referenced issues in commit %s''',
                commit['id'])
        else:
            app.logger.debug('Found %d referenced issues in commit %s',
                             len(issues), commit['id'])
            yt = Connection(app.config['YOUTRACK_URL'],
                            app.config['YOUTRACK_USERNAME'],
                            app.config['YOUTRACK_PASSWORD'])

            user_login = get_user_login(yt, commit['author']['email'])
            if user_login is None:
                app.logger.warn(
                    "Couldn't find user with email address %s. Using default user.",
                    commit['author']['email'])
                default_user = yt.getUser(app.config['DEFAULT_USER'])
                user_login = default_user['login']

            for issue_id in issues:
                app.logger.debug('Processing reference to issue %s', issue_id)
                try:
                    yt.getIssue(issue_id)
                    comment_string = 'Commit [%(url)s %(id)s] on branch %(refspec)s in [%(repo_homepage)s %(repo_name)s] made by %(author)s on %(date)s\n{quote}%(message)s{quote}' % {
                        'url': commit['url'],
                        'id': commit['id'],
                        'author': commit['author']['name'],
                        'date': str(commit_time),
                        'message': commit['message'],
                        'repo_homepage': repo_homepage,
                        'repo_name': repo_name,
                        'refspec': refspec
                    }
                    app.logger.debug(comment_string)
                    yt.executeCommand(issueId=issue_id,
                                      command='comment',
                                      comment=comment_string.encode('utf-8'),
                                      run_as=user_login.encode('utf-8'))
                except YouTrackException:
                    app.logger.warn("Couldn't find issue %s", issue_id)
    return Response('Push event processed. Thanks!', mimetype='text/plain')
Exemplo n.º 10
0
def jira2youtrack(source_url, source_login, source_password,
                  target_url, target_login, target_password,
                  projects, flags, field_mappings, value_mappings):
    print 'source_url   : ' + source_url
    print 'source_login : '******'target_url   : ' + target_url
    print 'target_login : '******'', target_login)
        except YouTrackException:
            pass

        while True:
            _end = start + chunk_size - 1
            if end and _end > end:
                _end = end
            if start > _end:
                break
            print 'Processing issues: %s [%d .. %d]' % (project_id, start, _end)
            try:
                jira_issues = source.get_issues(project_id, start, _end)
                start += chunk_size
                if not (jira_issues or end):
                    break
                # Filter out moved issues
                jira_issues = [issue for issue in jira_issues
                               if issue['key'].startswith('%s-' % project_id)]
                if flags & FI_ISSUES:
                    issues2import = []
                    for issue in jira_issues:
                        issues2import.append(
                            to_yt_issue(target, issue, project_id,
                                        field_mappings, value_mappings))
                    if not issues2import:
                        continue
                    target.importIssues(
                        project_id, '%s assignees' % project_id, issues2import)
            except YouTrackException, e:
                print e
                continue
            for issue in jira_issues:
                if flags & FI_LINKS:
                    process_links(target, issue, issue_links)
                if flags & FI_LABELS:
                    process_labels(target, issue)
                if flags & FI_ATTACHMENTS:
                    process_attachments(source, target, issue,
                                        flags & FI_REPLACE_ATTACHMENTS > 0)
                if flags & FI_WORK_LOG:
                    process_worklog(source, target, issue)
def csv2youtrack(source_file, target_url, target_login, target_password):
    target = Connection(target_url, target_login, target_password)
    source = Client(source_file)

    config = CsvYouTrackImportConfig(csvClient.FIELD_NAMES,
                                     csvClient.FIELD_TYPES)
    importer = CsvYouTrackImporter(source, target, config)
    importer.import_csv()
 def te_st_live_get_cycle_time(self):
     yt = Connection('https://tickets.i.gini.net', username, password)
     print 'connected to [%s]' % yt.baseUrl
     issue = Issue()
     issue.id = 'BACKEND-671'
     issue.created = '123'
     issue = CycleTimeAwareIssue(issue, YoutrackProvider(yt))
     self.assertEqual(7, issue.cycle_time.days)
Exemplo n.º 13
0
def zendesk2youtrack(source_url, source_login, source_password, target_url,
                     target_login, target_password, project_id):
    target = Connection(target_url, target_login, target_password)
    source = ZendeskClient(source_url, source_login, source_password)

    importer = ZendeskYouTrackImporter(
        source, target, ZendeskYouTrackImportConfig(zendesk.NAMES, {}, {}))
    importer.do_import({project_id: project_id})
 def process_commits(secret=None):
     if context_secret and secret != context_secret:
         abort(403)
     yt = Connection(yt_url, yt_login, yt_password)
     try:
         cmd_pattern = re.compile(
             r'#((?:%s)-\d+)(?:\s+(.+))?' %
             '|'.join(yt.getProjects().keys()),
             re.IGNORECASE | re.MULTILINE)
     except YouTrackException:
         app.logger.warning('Cannot get projects from YT')
         cmd_pattern = re.compile(r'#([A-z]+-\d+)(?:\s+(.+))?',
                                  re.MULTILINE)
     payload = json.loads(request.form.get('payload'))
     commits_url_template = get_commits_url_template(payload)
     for commit in payload['commits']:
         message = commit['message'].encode('utf-8')
         issue_refs = cmd_pattern.findall(message)
         if not issue_refs:
             continue
         commit_node = commit['node']
         commit_url = commits_url_template % commit['raw_node']
         timestamp = commit['utctimestamp']
         author = commit['author'].encode('utf-8')
         match = re.search(r'<(.+?)>', commit['raw_author'])
         if not match:
             app.logger.error("Cannot get author's email address.")
             abort(400)
         users = yt.getUsers(params={'q': match.group(1)})
         if not users:
             app.logger.error('Cannot find user with email ' +
                              match.group(1))
             abort(400)
         if len(users) != 1:
             app.logger.error('Not unique email address ' + match.group(1))
             abort(400)
         comment = "Commit [%s %s] made by '''%s''' on ''%s''\n{quote}%s{quote}" \
                   % (commit_url, commit_node, author, timestamp, message)
         cmd_exec_result = True
         for issue_id, command in issue_refs:
             if command is None:
                 command = ''
             try:
                 app.logger.info(
                     "Adding commit %s to issue %s (command: %s)" %
                     (commit_node, issue_id, command))
                 yt.executeCommand(issue_id,
                                   command,
                                   comment,
                                   run_as=users[0].login)
             except YouTrackException as e:
                 cmd_exec_result = False
                 app.logger.error(
                     'Failed to add commit %s to issue %s: %s' %
                     (commit_node, issue_id, e.message))
         if not cmd_exec_result:
             abort(500)
     return 'success'
Exemplo n.º 15
0
def proyecto_elegido(bot, update, user_data):
    bot.sendChatAction(chat_id=update.callback_query.from_user.id,
                       action=ChatAction.TYPING)

    # Es la primera vez que entra o cambia tipo de tareas?
    user_data['tipo_tarea'] = '#Unresolved'
    if not user_data.get('proyecto'):
        user_data['proyecto'] = update.callback_query.data
        logger.info('Elegir Proyecto Opción {}'.format(user_data['proyecto']))
    else:
        user_data['tipo_tarea'] = update.callback_query.data
        logger.info('Elegir Proyecto Opción {} {}'.format(
            user_data['proyecto'], user_data['tipo_tarea']))

    connection = Connection(user_data['host']['host'],
                            user_data['host']['username'],
                            user_data['host']['pass'])
    username, email = splitEmail(user_data['host']['username'])

    query = 'Type: Task and {} and ( Assignee: {} or #Unassigned )'.format(
        user_data['tipo_tarea'], username)
    issues = connection.getIssues(user_data['proyecto'], query, 0, 20)

    keyboard = []
    texto = '*Tareas:* \n '
    for issue in issues:
        texto += '\n *[{}]* _{}, {}_\n *Prioridad:* _{}_\n *Resumen:* {} \n'.format(
            issue['id'], issue['Type'], issue['State'], issue['Priority'],
            escapeMarkdown(utf8(issue['summary'])))
        keyboard.append(
            InlineKeyboardButton(issue['id'], callback_data=issue['id']))
    # Agrego posibilidad de ver otras tareas
    if user_data['tipo_tarea'] == '#Unresolved':
        keyboard.append(
            InlineKeyboardButton('Ver solucionadas',
                                 callback_data='#Resolved'))
    else:
        keyboard.append(
            InlineKeyboardButton('Ver no solucionadas',
                                 callback_data='#Unresolved'))
    # Acomodo el teclado
    keyboard = [keyboard[i:i + 3] for i in range(0, len(keyboard), 3)]
    reply_markup = InlineKeyboardMarkup(keyboard,
                                        resize_keyboard=True,
                                        one_time_keyboard=True)

    texto += '\n *Elegí la tarea:*'

    if len(keyboard) > 0:
        update.callback_query.edit_message_text(text=texto,
                                                reply_markup=reply_markup,
                                                parse_mode='Markdown')
        return ISSUE
    else:
        update.callback_query.edit_message_text(
            text="No hay tareas asignadas a vos! Chau")
        return ConversationHandler.END
Exemplo n.º 16
0
 def handle(self, *args, **kwargs):
     #configfile = static("acessorio.json")
     configfile = os.path.join(settings.BASE_DIR, "static/acessorio.json")
     with open(configfile) as config_file:
         config = json.load(config_file)
     yt = Connection(url='https://youtrack.ugent.be',
                     token=config['YTTOKR'])
     # get CMB issues
     PRCissues = yt.get_all_issues("PRC-", 0, 500)
     # open PRC issue IDs
     PRCissuesIDs = []
     Currentissuesindexes = list()
     counter = 0
     for issue in PRCissues:
         #print(issue['id'])
         if datetime.datetime.now() - datetime.datetime.fromtimestamp(
                 int(issue["created"]) / 1000) < datetime.timedelta(
                     hours=40):
             #timesincecreation = datetime.datetime.now() - datetime.datetime.fromtimestamp(int(issue["created"])/1000)
             #if timesincecreation < datetime.timedelta(hours=60) and timesincecreation > datetime.timedelta(hours=1):
             PRCissuesIDs.append(issue["id"])
             Currentissuesindexes.append(counter)
         counter = counter + 1
     # update PRCissues (filter State Closed)
     print(PRCissuesIDs)
     PRCissues = [PRCissues[index] for index in Currentissuesindexes]
     filename = os.path.join(settings.BASE_DIR,
                             "static/PRC_issues_creation_hourly.csv")
     with open(filename, 'w', encoding='utf-8') as csvfile:
         #csvfile.write('Running start date\tLab PI\tType\tUser Name\tYouTrack\tProject Name (YouTrack)\t# samples\tMS_Injections_Per_Sample\trun length (hours)\ttotal running time (hours)\tMass_Spectrometer\tCreated_DateH\tArrival_DateH\tMS_RunStateH\tMS_RunStatesH\tMS_RunStatesnrH\tre-runs/problems\tMS_RunStartH\tMS_RunStartsH\tMS_RunStartsnrH\tresolvedH\tResolvedDateH\tCleatedDate\n')
         #csvfile.write('YouTrack_id,Contact_Email,Analysis_Type\n')
         i = 0
         for issue in PRCissues:
             # name of fields in issue
             indices = list()
             for attr_name, attr_type in issue._attribute_types.items():
                 indices.append(attr_name)
                 # YouTrack_id
             issueid = issue['id']
             # Project_name
             issuecontactemail = issue['Contact_Email']
             # sendRegistrationEmail
             if 'sendRegistrationEmail' in indices:
                 issuesendregistrationemail = issue['sendRegistrationEmail']
             else:
                 issuesendregistrationemail = 'Yes'
             # No_Samples
             if 'Analysis_Type' in indices:
                 issueAnalysisType = str(issue['Analysis_Type'])
             else:
                 issueAnalysisType = 'None'
             row = issueid + ',' + issuecontactemail + ',' + issueAnalysisType + ',' + issuesendregistrationemail
             row = row + '\n'
             csvfile.write(row, )
             i = i + 1
Exemplo n.º 17
0
def recibir_horas(bot, update, user_data):
    try:
        duracion = int(update.message.text)
        logger.info(duracion)
    except ValueError:
        logger.error("No entiendo el número!")
        update.message.reply_text("No entiendo el número!")
        return RECIBIR

    work_item = {
        'duration': duracion,
        'date': str(datetime.now()),
        'worktype': user_data['tipo_nom'],
        'description': 'bot :)'
    }
    work_item = dotdict(work_item)
    logger.info(work_item)

    try:
        connection = Connection(user_data['host']['host'],
                                user_data['host']['username'],
                                user_data['host']['pass'])
        connection.createWorkItem(user_data['issue'], work_item)
        logger.info('Guardar tiempo {} {}'.format(user_data['issue'],
                                                  duracion))

        issue = connection.getIssue(user_data['issue'])

        keyboard = []
        if user_data['tipo_tarea'] == '#Unresolved':
            keyboard.append([
                InlineKeyboardButton('Marcar como cerrada',
                                     callback_data='issue_estado_cerrar')
            ])
        else:
            keyboard.append([
                InlineKeyboardButton('Marcar como en progreso',
                                     callback_data='issue_estado_en_progreso')
            ])
        keyboard.append([
            InlineKeyboardButton('Dejar como {}'.format(issue['State']),
                                 callback_data='terminar')
        ])
        reply_markup = InlineKeyboardMarkup(keyboard,
                                            resize_keyboard=True,
                                            one_time_keyboard=True)
        update.message.reply_text("Gracias amego! Y ahora?",
                                  reply_markup=reply_markup)
        return CONFIRMAR

    except Exception as e:
        logger.error(e)
        update.message.reply_text("No eh!")

    return ConversationHandler.END
Exemplo n.º 18
0
    def __init__(self, host, user, password, api_key):
        connection = Connection(url=host, api_key=api_key)

        # get one issue
        issue = connection.getIssue('PI-1000')

        # get first 10 issues in project JT for query 'for: me #unresolved'
        issues = connection.getIssues(
            'pi', '#Resolved Fixed in build: {Next Build}', 0, 10)
        for issue in issues:
            print(issue)
Exemplo n.º 19
0
def agilezen2youtrack(source_url, source_token, target_url, target_login,
                      target_password, project_names_to_import):
    source = Client(source_url, source_token)
    target = Connection(target_url, target_login, target_password)
    last_page = False
    current_page = 1
    try:
        target.createCustomFieldDetailed("State", "state[1]", False, True,
                                         True, {"attachBundlePolicy": "2"})
    except YouTrackException, e:
        print str(e)
Exemplo n.º 20
0
def push_event_hook(room=None):
    push_event = request.json
    app.logger.debug(push_event)
    app.logger.debug("slack_room:%s" % room)

    # process mergerequest
    if 'object_kind' in push_event and push_event['object_kind'] == 'merge_request':
        obj = push_event['object_attributes']
        user = push_event['user']
        slack = Slacker(app.config['SLACK_TOKEN'])
        url = "%s/%s/%s/merge_requests/%d" % (app.config['GITLAB_HOME'], obj['target']['namespace'], obj['target']['name'], obj['iid'])
        print url
        event = "Pull Request(%s): %s - %s\n%s" % (obj['state'], url, obj['title'], obj['description'])
        slack.chat.post_message('#%s' % room, event, username=user['username'], icon_url=user['avatar_url'])
        return Response('Push event processed. Thanks!', mimetype='text/plain')

    user_name = push_event['user_name']
    repo_name = push_event['repository']['name']
    repo_url = push_event['repository']['url']
    repo_homepage = push_event['repository']['homepage']
    refspec = push_event['ref']
    app.logger.debug('Received push event by %s in branch %s on repository %s', user_name, refspec, repo_url)

    for commit in push_event['commits']:
        app.logger.debug('Processing commit %s by %s (%s) in %s', commit['id'], commit['author']['name'], commit['author']['email'], commit['url'])
        commit_time = dateutil.parser.parse(commit['timestamp'])
        issues = re.findall(app.config['REGEX'], commit['message'], re.MULTILINE)
        if not issues:
            app.logger.debug('''Didn't find any referenced issues in commit %s''', commit['id'])
        else:
            app.logger.debug('Found %d referenced issues in commit %s', len(issues), commit['id'])
            yt = Connection(app.config['YOUTRACK_URL'], app.config['YOUTRACK_USERNAME'], app.config['YOUTRACK_PASSWORD'])

            user_login = get_user_login(yt, commit['author']['email'])
            if user_login is None:
                app.logger.warn("Couldn't find user with email address %s. Using default user.", commit['author']['email'])
                default_user = yt.getUser(app.config['DEFAULT_USER'])
                user_login = default_user['login']

            for issue_id in issues:
                app.logger.debug('Processing reference to issue %s', issue_id)
                try:
                    yt.getIssue(issue_id)
                    comment_string = 'Commit [%(url)s %(id)s] on branch %(refspec)s in [%(repo_homepage)s %(repo_name)s] made by %(author)s on %(date)s\n{quote}%(message)s{quote}' % {'url': commit['url'], 'id': commit['id'], 'author': commit['author']['name'], 'date': str(commit_time), 'message': commit['message'], 'repo_homepage': repo_homepage, 'repo_name': repo_name, 'refspec': refspec}
                    app.logger.debug(comment_string)
                    yt.executeCommand(issueId=issue_id, command='comment', comment=comment_string.encode('utf-8'),
                                      run_as=user_login.encode('utf-8'))
                except YouTrackException:
                    app.logger.warn("Couldn't find issue %s", issue_id)
    return Response('Push event processed. Thanks!', mimetype='text/plain')
Exemplo n.º 21
0
def csv2youtrack(source_file, target_url, target_login, target_password, comments_file=None, attachments_file=None):
    target = Connection(target_url, target_login, target_password)
    source = Client(source_file)
    source_comments = None
    if comments_file:
        source_comments = Client(comments_file)

    source_attachments = None
    if attachments_file:
        source_attachments = Client(attachments_file)

    config = CsvYouTrackImportConfig(csvClient.FIELD_NAMES, csvClient.FIELD_TYPES)
    importer = CsvYouTrackImporter(source, target, config, source_comments, source_attachments)
    importer.import_csv()
Exemplo n.º 22
0
 def submit(self):
     try:
         connection = Connection(settings.YOUTRACK_URL,
                                 settings.YOUTRACK_LOGIN,
                                 settings.YOUTRACK_PASSWORD)
         response, content = connection.createIssue(
             self.project,
             assignee=None,
             summary=u'Issue from feedback form',
             description=self.cleaned_data['description'])
         print response
         issue_id = response['location'].split('/')[-1]
         connection.executeCommand(
             issue_id, 'Customer email ' + self.cleaned_data['email'])
         return True
     except YouTrackException:
         return False
Exemplo n.º 23
0
def jira2youtrack(source_url, source_login, source_password, target_url, target_login, target_password, project_id,
                  issues_count, skip_count):
    print("source_url      : " + source_url)
    print("source_login    : "******"target_url      : " + target_url)
    print("target_login    : "******"project_id      : " + project_id)
    print("issues_count    : ", issues_count)
    print("skip_count      : ", skip_count)

    first_chunk = skip_count / 10
    last_chunk = issues_count / 10
    if issues_count % 10:
        last_chunk += 1

    source = JiraClient(source_url, source_login, source_password)
    target = Connection(target_url, target_login, target_password)

    try:
        target.createProjectDetailed(project_id, project_id, "", target_login)
    except YouTrackException:
        pass

    for i in range(first_chunk, last_chunk):
        start = i * 10 + 1
        end = (i + 1) * 10 + 1
        if start <= skip_count: start = skip_count + 1
        if end > issues_count + 1: end = issues_count + 1
        try:
            jira_issues = source.get_issues(project_id, start, end)
            target.importIssues(project_id, project_id + " assignees",
                [create_yt_issue_from_jira_issue(target, issue, project_id) for issue in
                 jira_issues])
            for issue in jira_issues:
                try:
                    process_labels(target, issue)
                except YouTrackException, e:
                    print e
                try:
                    process_attachments(source, target, issue)
                except YouTrackException, e:
                    print e
                try:
                    process_worklog(source, target, issue)
                except YouTrackException, e:
                    print e
def doMove(source_url, source_login, source_password, target_url, target_login, target_password, source_issue_id, target_project_id) :
    print "source_url       : " + source_url
    print "source_login     : "******"source_password  : "******"target_url       : " + target_url
    print "target_login     : "******"target_password  : "******"source_id        : " + source_issue_id
    print "target_project   : " + target_project_id

    # connecting
    try :
        target = Connection(target_url, target_login, target_password)
        print "Connected to target url [%s]" % target_url
    except Exception, ex:
        print "Failed to connect to target url [%s] with login/password [%s/%s]" % (target_url, target_login, target_password)
        raise ex
Exemplo n.º 25
0
def host_elegido(bot, update, user_data):
    bot.sendChatAction(chat_id=update.callback_query.from_user.id,
                       action=ChatAction.TYPING)

    usuario = usuarios.getCollection().find_one(
        {'chat_id': update.callback_query.from_user.id})
    logger.info('Elegir host Opción {}'.format(update.callback_query.data))

    host = next(x for x in usuario['hosts']
                if x['host'] == update.callback_query.data)
    user_data['host'] = host

    try:
        connection = Connection(user_data['host']['host'],
                                user_data['host']['username'],
                                user_data['host']['pass'])
        connections[usuario['chat_id']] = connection
        proyectos = connection.getProjects()

    except YouTrackException as e:
        logger.error(e)
        del user_data['host']['pass']
        usuarios.getCollection().update(
            {'chat_id': update.callback_query.from_user.id},
            {'$pull': {
                'hosts': user_data['host']
            }})

        return CONFIRMAR

    keyboard = []
    for proyecto in proyectos.keys():
        keyboard.append(
            InlineKeyboardButton(proyectos[proyecto], callback_data=proyecto))

    # Acomodo el teclado
    keyboard = [keyboard[i:i + 3] for i in range(0, len(keyboard), 3)]
    reply_markup = InlineKeyboardMarkup(keyboard,
                                        resize_keyboard=True,
                                        one_time_keyboard=True)
    update.callback_query.edit_message_text(text="Bien! Elegí un proyecto",
                                            reply_markup=reply_markup)
    return PROYECTO
Exemplo n.º 26
0
def issue_elegido(bot, update, user_data):
    bot.sendChatAction(chat_id=update.callback_query.from_user.id,
                       action=ChatAction.TYPING)

    user_data['issue'] = update.callback_query.data
    logger.info('Elegir Issue {} Opción {}'.format(user_data['proyecto'],
                                                   user_data['issue']))

    connection = Connection(user_data['host']['host'],
                            user_data['host']['username'],
                            user_data['host']['pass'])
    try:
        the_types = connection.getProjectTimeTrackingWorkTypes(
            user_data['proyecto'])
    except YouTrackException as e:
        logger.error('Error de Youtrack {}'.format(e))
        reply_markup = InlineKeyboardMarkup([[
            InlineKeyboardButton("Elegir otro proyecto",
                                 callback_data=user_data['host']['host'])
        ]],
                                            resize_keyboard=True,
                                            one_time_keyboard=True)
        del user_data['proyecto']
        update.callback_query.edit_message_text(
            text="El proyecto no admite registro de horas, hablá con tu PM",
            reply_markup=reply_markup)
        return HOST

    user_data['types'] = the_types['types']
    keyboard = []
    for one_type in the_types['types']:
        keyboard.append([
            InlineKeyboardButton(one_type['name'],
                                 callback_data=one_type['id'])
        ])

    reply_markup = InlineKeyboardMarkup(keyboard,
                                        resize_keyboard=True,
                                        one_time_keyboard=True)

    update.callback_query.edit_message_text(text="Elegí el tipo",
                                            reply_markup=reply_markup)
    return RECIBIR
Exemplo n.º 27
0
def issue_actualizar_estado(bot, update, user_data):
    bot.sendChatAction(chat_id=update.callback_query.from_user.id,
                       action=ChatAction.TYPING)
    if update.callback_query.data == 'issue_estado_cerrar':
        estado = 'Fixed'
    else:
        estado = 'In Progress'

    logger.info('Actualizar estado issue {} {}'.format(user_data['issue'],
                                                       estado))
    try:
        connection = Connection(user_data['host']['host'],
                                user_data['host']['username'],
                                user_data['host']['pass'])
        command = 'State ' + estado
        connection.executeCommand(user_data['issue'], command)

        update.callback_query.edit_message_text("Gracias amego!")

    except Exception as e:
        logger.error(e)
        update.callback_query.edit_message_text("No eh!")
    return ConversationHandler.END
from youtrack.connection import Connection

target = Connection("some url", "root", "root")
for user in target.getUsers():
    yt_user = target.getUser(user.login)
    try:
        if (str(yt_user.email).find("jetbrains") > 0):
            print yt_user.email
        elif (str(yt_user.email).find("intellij") > 0):
            print yt_user.email
    except:
        print "exception"
def bugzilla2youtrack(target_url, target_login, target_pass, bz_db, bz_host, bz_port, bz_login, bz_pass,
                      bz_product_names, issues_filter):
    # connecting to bz
    client = Client(bz_host, int(bz_port), bz_login, bz_pass, db_name=bz_db)

    if not len(bz_product_names):
        answer = raw_input("All projects will be imported. Are you sure? [y/n]")
        if answer.capitalize() != "Y":
            sys.exit()
        bz_product_names = client.get_product_names()

    print("bz_product_names :   " + repr(bz_product_names))

    # connecting to yt
    target = Connection(target_url, target_login, target_pass)

    print("Creating issue link types")
    link_types = client.get_issue_link_types()
    for link in link_types:
        print("Processing link type [ %s ]" % link.name)
        try:
            target.createIssueLinkType(to_yt_issue_link_type(link))
        except YouTrackException:
            print("Can't create link type [ %s ] (maybe because it already exists)" % link.name)
    print("Creating issue link types finished")

    print("Creating custom fields")
    custom_fields = client.get_custom_fields()
    for cf in custom_fields:
        create_yt_custom_field(cf, target)
    print("Creating custom fields finished")

    for key in youtrackutils.bugzilla.FIELD_TYPES:
        if key not in youtrack.EXISTING_FIELDS:
            create_custom_field(target, youtrackutils.bugzilla.FIELD_TYPES[key], key, True, bundle_policy="1")

    bz_product_ids = []

    for name in bz_product_names:
        product_id = str(client.get_product_id_by_name(name))
        bz_product_ids.append(product_id)
        print("Creating project [ %s ] with name [ %s ]" % (product_id, name))
        try:
            target.getProject(str(product_id))
        except YouTrackException:
            target.createProjectDetailed(str(product_id), name, client.get_project_description(product_id),
                target_login)

        print("Importing components for project [ %s ]" % product_id)
        process_components(client.get_components(product_id), product_id, target)
        print("Importing components finished for project [ %s ]" % product_id)

        print("Importing versions for project [ %s ]" % product_id)
        process_versions(client.get_versions(product_id), product_id, target)
        print("Importing versions finished for project [ %s ] finished" % product_id)

        print("Importing issues to project [ %s ]" % product_id)
        max_count = 100
        count = 0
        from_id = 0
        bz_issues_count = client.get_issues_count(product_id)
        while count < bz_issues_count:
            batch = client.get_issues(product_id, from_id, from_id + max_count)
            batch = [bz_issue for bz_issue in batch if (issues_filter(bz_issue))]
            count += len(batch)
            from_id += max_count
            target.importIssues(product_id, product_id + " assignees",
                [to_yt_issue(bz_issue, product_id, target) for bz_issue in batch])
            # todo convert to good tags import
            for issue in batch:
                tags = issue["keywords"] | issue["flags"]
                for t in tags:
                    print("Processing tag [ %s ]" % t.encode('utf8'))
                    target.executeCommand(str(product_id) + "-" + str(issue[get_number_in_project_field_name()]),
                        "tag " + t.encode('utf8'))
            for issue in batch:
                for attach in issue["attachments"]:
                    print("Processing attachment [ %s ]" % (attach.name.encode('utf8')))
                    content = StringIO(attach.content)
                    target.createAttachment(str(product_id) + "-" + str(issue[get_number_in_project_field_name()]),
                        attach.name, content, attach.reporter.login
                        , created=str(int(attach.created) * 1000))
        print("Importing issues to project [ %s ] finished" % product_id)

    # todo add pagination to links
    print("Importing issue links")
    cf_links = client.get_issue_links()
    duplicate_links = client.get_duplicate_links()
    if len(duplicate_links):
        try:
            target.createIssueLinkTypeDetailed("Duplicate", "duplicates", "is duplicated by", True)
        except YouTrackException:
            print("Can't create link type [ Duplicate ] (maybe because it already exists)")
    depend_links = client.get_dependencies_link()
    if len(depend_links):
        try:
            target.createIssueLinkTypeDetailed("Depend", "depends on", "is required for", True)
        except YouTrackException:
            print("Can't create link type [ Depend ] (maybe because it already exists)")
    links = cf_links | duplicate_links | depend_links

    links_to_import = list([])
    for link in links:
        print("Processing link %s for issue%s" % (link.name, link.source))
        if (str(link.target_product_id) in bz_product_ids) and (str(link.source_product_id) in bz_product_ids):
            links_to_import.append(to_yt_issue_link(link))
    print(target.importLinks(links_to_import))
    print("Importing issue links finished")
Exemplo n.º 30
0
def fb2youtrack(params):
    # Connection to FogBugz
    source = FBClient(params['fb_url'],
                      params['fb_login'],
                      params['fb_password'])

    # Connecting to YouTrack
    token = params.get('token')
    if not token and 'token_file' in params:
        try:
            with open(params['token_file'], 'r') as f:
                token = f.read().strip()
        except (OSError, IOError) as e:
            print("Cannot load token from file: " + str(e))
            sys.exit(1)
    if token:
        target = Connection(params['yt_url'], token=token)
    elif 'yt_login' in params:
        target = Connection(params['yt_url'],
                            params.get('yt_login'),
                            params.get('yt_password'))
    else:
        print("You have to provide token or login/password to import data")
        sys.exit(1)

    if not params.get('project_lead_login'):
        project_lead = params.get('yt_login')
        if not project_lead:
            for login in ('root', 'admin', 'administrator', 'guest'):
                try:
                    project_lead = target.getUser(login).login
                    break
                except youtrack.YouTrackException:
                    continue
        params['project_lead_login'] = project_lead

    max_issue_id = params['fb_max_issue_id']

    project_names = youtrackutils.fbugz.PROJECTS_TO_IMPORT
    accessible_projects = source.list_project_names()
    for p_name in project_names:
        if not (p_name in accessible_projects.keys()):
            print('Unknown project names. Exiting...')
            sys.exit()

#    for p_name in accessible_projects :
#        if (p_name.encode('utf-8') in project_names_str) :
#            project_names_str.remove(p_name.encode('utf-8'))
#            project_names.append(p_name)
#
#    if (len(project_names_str) != 0) :
#        print 'Unknown project names!'

    print('Creating custom fields')
#
#    for field_name in ['Category', 'Priority', 'Status']:
#        field_name = get_yt_name_from_fb__field_name(field_name)
#        create_custom_field(target, fbugz.CF_TYPES[field_name], field_name, False)

    fb_category_bundle_name = u'FB Categories'
    fb_priorities_bundle_name = u'FB Priorities'
    fb_statuses_bundle_name = u'FB Statuses'

    common_fields = {
        u'category'  :   fb_category_bundle_name,
        u'priority'  :   fb_priorities_bundle_name,
        u'status'    :   fb_statuses_bundle_name
    }

    field_name = u'category'
    create_bundle_with_values(
        target,
        youtrackutils.fbugz.CF_TYPES[get_yt_field_name(field_name)],
        common_fields[field_name],
        source.list_categories(),
        lambda bundle, value:
        bundle.createElement(to_yt_field_value(field_name, value)))
    field_name = u'priority'
    create_bundle_with_values(target, youtrackutils.fbugz.CF_TYPES[get_yt_field_name(field_name)],
                              common_fields[field_name],
                              [elem[0] + '-' + elem[1] for elem in source.list_priorities()],
                              lambda bundle, value : bundle.createElement(to_yt_field_value(field_name, value)))

    field_name = u'status'
    statuses = [(to_yt_field_value(field_name, value), resolved) for (value, resolved) in source.list_statuses()]
    create_bundle_with_values(target, youtrackutils.fbugz.CF_TYPES[get_yt_field_name(field_name)],
                              common_fields[field_name],
                              statuses, lambda bundle, value : to_yt_status(bundle, value))

    simple_fields = [u'original_title', u'version', u'computer', u'due', u'estimate']

    for name in simple_fields:
        name = get_yt_field_name(name)
        create_custom_field(target, youtrackutils.fbugz.CF_TYPES[name], name, False)

    print('Importing users')
    for name in ['Normal', 'Deleted', 'Community', 'Virtual'] :
        group = Group()
        group.name = name
        try :
            target.createGroup(group)
            print('Group with name [ %s ] successfully created' % name)
        except:
            print("Can't create group with name [ %s ] (maybe because it already exists)" % name)

    users_to_import = []
    max = 100
    for user in source.get_users() :
        yt_user = _to_yt_user(user)
        print('Importing user [ %s ]' % yt_user.login)
        users_to_import.append(yt_user)
        if len(users_to_import) >= max:
            _do_import_users(target, users_to_import)
            users_to_import = []
    _do_import_users(target, users_to_import)
    print('Importing users finished')

    # to handle linked issues
    try :
        target.createIssueLinkTypeDetailed('parent-child', 'child of', 'parent of', True)
    except YouTrackException:
        print("Can't create issue link type [ parent-child ] (maybe because it already exists)")
    links_to_import = []

    for project_name in project_names:
        value_sets = dict([])

        project_id = accessible_projects[project_name]
        print('Importing project [ %s ]' % project_name)
        target.createProjectDetailed(project_id,
                                     project_name.encode('utf-8'),
                                     '',
                                     params['project_lead_login'])

        print('Creating custom fields in project [ %s ]' % project_name)

        for cf_name in common_fields:
            bundle_name = common_fields[cf_name]
            cf_name = get_yt_field_name(cf_name)
            target.deleteProjectCustomField(project_id, cf_name)
            target.createProjectCustomFieldDetailed(project_id, cf_name, 'No ' + cf_name.lower(),
                    {'bundle' : bundle_name})

        for cf_name in simple_fields:
            cf_name = get_yt_field_name(cf_name)
            try:
                target.createProjectCustomFieldDetailed(project_id, cf_name, 'No ' + cf_name.lower())
            except YouTrackException:
                print("Can't create custom field with name [%s]" % cf_name)
        cf_name = get_yt_field_name('fix_for')
        milestones = source.get_milestones(project_id)
        value_sets["fix_for"] = []
        for milestone in milestones:
            value_sets["fix_for"].append(milestone.name)
            milestone.name = to_yt_field_value('fix_for', milestone.name)
        add_values_to_field(target, cf_name, project_id, milestones,
                            lambda bundle, value: _to_yt_version(bundle, value))

        cf_name = get_yt_field_name('area')
        areas = source.get_areas(project_id)
        value_sets["area"] = []
        for area in areas:
            value_sets["area"].append(area.name)
            area.name = to_yt_field_value('area', area.name)
        add_values_to_field(target, cf_name, project_id, areas,
                            lambda bundle, value: _to_yt_subsystem(bundle, value))

        print('Importing issues for project [ %s ]' % project_name)
        start = 0
        issues_to_import = []
        # create dictionary with child : parent pairs
        while start <= max_issue_id:
            fb_issues = source.get_issues(project_name, start, 30)
            for issue in fb_issues :
                add_values_to_field(target, get_yt_field_name('area'), project_id,
                                    [issue.field_values['area']], lambda bundle, value: bundle.createElement(value))
                issues_to_import.append(_to_yt_issue(issue, value_sets))
            target.importIssues(project_id, project_name.encode('utf-8') + " assignees", issues_to_import)
            for issue in fb_issues :
                full_issue_id = '%s-%s' % (project_id, issue.ix_bug)
                for attach in issue.attachments :
                    target.createAttachmentFromAttachment(full_issue_id, attach)
                for tag in issue.tags :
                    target.executeCommand(full_issue_id, 'tag ' + tag)
                if issue.bug_parent is not None:
                    parent_issue_id = '%s-%s' % (source.get_issue_project_id(issue.bug_parent), issue.bug_parent)
                    link = Link()
                    link.typeName = 'parent-child'
                    link.source = full_issue_id
                    link.target = parent_issue_id
                    links_to_import.append(link)
            issues_to_import = []
            start += 30
        print('Importing issues for project [ %s ] finished' % project_name)

    print('Importing issue links')
    print(target.importLinks(links_to_import))
    print('Importing issue links finished')