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'
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'
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']) default_user = yt.getUser(app.config['DEFAULT_USER']) user_login = default_user['login'] users = yt.getUsers({ 'q': commit['author']['email'] }) if not users: app.logger.warn('''Couldn't find user with email address %s. Using default user.''', commit['author']['email']) elif len(users) > 1: app.logger.warn('''Found more than one user with email address %s. Using default user.''', commit['author']['email']) else: user_login = users[0]['login'] for issue_id in issues: app.logger.debug('Processing reference to issue %s', issue_id) try: issue = 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''', ref) return Response('Push event processed. Thanks!', mimetype='text/plain')
def receive_hook(): payload = request.json user_name = payload['user_name'] repo_url = payload['repository']['url'] app.logger.debug('Received payload for a push by %s on repository %s', user_name, repo_url) for commit in payload['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']) refs = re.findall(app.config['REGEX'], commit['message'], re.MULTILINE) if not refs: app.logger.info('''Didn't find any referenced issues in commit %s''', commit['id']) else: app.logger.info('Found %d referenced issues in commit %s', len(refs), commit['id']) yt = Connection(app.config['YOUTRACK_URL'], app.config['YOUTRACK_USERNAME'], app.config['YOUTRACK_PASSWORD']) user = app.config['DEFAULT_USER'] users = yt.getUsers({ 'q': commit['author']['email'] }) if not users: app.logger.warn('''Couldn't find user with email address %s. Using default user.''', commit['author']['email']) elif len(users) > 1: app.logger.warn('''Found more than one user with email address %s. Using default user.''', commit['author']['email']) else: user = users[0]['login'] for ref in refs: app.logger.info('Processing reference to issue %s', ref) try: issue = yt.getIssue(ref) comment_string = 'Commit [%(url)s %(id)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']} app.logger.debug(comment_string) yt.executeCommand(issueId=ref, command='comment', comment=comment_string, run_as=user) except YouTrackException: app.logger.warn('''Couldn't find issue %s''', ref) return Response('Payload processed. Thanks!', mimetype='text/plain')
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"
from youtrack.connection import Connection connection = Connection('some url', 'root', 'root') for user in connection.getUsers(): print("yet another") if (user.login != 'root') and (user.login != 'guest'): connection._reqXml('DELETE', '/admin/user/' + user.login, '')
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"