예제 #1
0
def close_old_issue(repo_username, repo_id, number, issue):
    context = {
        'issue': issue,
        'user': issue.get('user')
    }
    comment = util.get_template('CLOSING_TEMPLATE', context)

    github_api.close_issue(repo_username, repo_id, number, issue)
    github_api.create_issue_comment(repo_username, repo_id, number, comment)

    return {
        'closed_old_issue': True
    }
예제 #2
0
def close(msg, chat_id):
    comando = ''
    for s in 'close':
        comando += '({}|{})'.format(s, s.upper())
    pattern = '^/{} \d+$'.format(comando)

    if bool(re.match(pattern, msg)):
        issue_id = msg.split(' ')[1]

        items = get_issue(issue_id)
        if items is None:
            text = 'No existe la issue {}.'.format(issue_id)
        elif items[0] == 'closed':
            text = 'La issue {} ya estaba cerrada.'.format(issue_id)
        else:
            text = close_issue(issue_id)
            text += ' Para ver el issue correspondiente, ingrese a ' \
                    'https://github.com/Genaron/T07/issues/{}' \
                    ''.format(issue_id)
        send_msg(text, chat_id)
    else:
        cmd_error(chat_id)
예제 #3
0
def index():
    if request.method == 'POST':
        update = request.get_json(force=True)
        chat_id = update['message']['chat']['id']
        message = update['message']['text']

        if message == '/send_test':
            send_message(chat_id, 'test, your id: {}'.format(chat_id))
        elif message == '/send_hi':
            send_message(chat_id, 'hi')
        elif message.startswith('/get'):
            message_split = message.split(' ')
            if len(message_split) != 2:
                send_message(chat_id, 'Not enough arguments')
                return 'Hi there'
            num_issue = message_split[1]
            if num_issue.startswith('#'):
                num_issue = int(num_issue.replace('#', ''))
                issue_req = get_issue(num_issue)
                if issue_req.status_code == 200:
                    issue = issue_req.json()
                    send_message(chat_id, format_issue(issue))
                else:
                    send_message(chat_id, 'It was not possible to get issue')
            else:
                send_message(chat_id, 'Num issue must start with #')
        elif message.startswith('/post'):
            message_split = message.split(' ', maxsplit=2)
            if len(message_split) != 3:
                send_message(chat_id, 'Not enough arguments')
                return 'Hi there'
            num_issue = message_split[1]
            respuesta = message_split[2]
            if not num_issue.startswith('#') or not respuesta.startswith('*'):
                send_message(chat_id, 'Check # and *')
            else:
                num_issue = int(num_issue.replace('#', ''))
                respuesta = respuesta.replace('*', '')
                req = post_comment(num_issue, respuesta)
                if req.status_code == 201:
                    send_message(chat_id, 'Comment posted')
                else:
                    send_message(chat_id,
                                 'It was not possible to post comment')
        elif message.startswith('/label'):
            message_split = message.split(' ')
            if len(message_split) != 3:
                send_message(chat_id, 'Not enough arguments')
                return 'Hi there'
            num_issue = message_split[1]
            label = message_split[2]
            if num_issue.startswith('#'):
                num_issue = int(num_issue.replace('#', ''))
                if label in get_labels(num_issue, only_names=True):
                    send_message(chat_id, 'Issue already has this label')
                else:
                    req = add_label(num_issue, label)
                    if req.status_code == 200:
                        send_message(chat_id, 'Label added')
                    else:
                        send_message(chat_id,
                                     'It was not possible to add label')
            else:
                send_message(chat_id, 'Num issue must start with #')
        elif message.startswith('/close'):
            message_split = message.split(' ')
            if len(message_split) != 2:
                send_message(chat_id, 'Not enough arguments')
                return 'Hi there'
            num_issue = message_split[1]
            if num_issue.startswith('#'):
                num_issue = int(num_issue.replace('#', ''))
                issue = get_issue(num_issue).json()
                if issue['state'] == 'closed':
                    send_message(chat_id, 'Issue already closed')
                else:
                    req = close_issue(num_issue)
                    if req.status_code == 200:
                        send_message(chat_id, 'Issue closed')
                    else:
                        send_message(chat_id,
                                     'It was not possible to close the issue')
            else:
                send_message(chat_id, 'Num issue must start with #')
        elif message == '/add':
            if chat_id in CHAT_ID_SET:
                send_message(chat_id, 'You are already in contacts')
            else:
                CHAT_ID_SET.add(chat_id)
                send_message(chat_id, 'You were added to contacts')
        elif message == '/remove':
            if chat_id in CHAT_ID_SET:
                CHAT_ID_SET.remove(chat_id)
                send_message(chat_id, 'You were removed from contacts')
            else:
                send_message(chat_id, 'You are not in the contacts')
        elif message == '/air':
            send_message(chat_id, get_air_status())
        else:
            send_message(chat_id, 'Default')

        return 'Received : {}'.format(message)
    else:
        return 'Hi there'
예제 #4
0
def submit_issue_response(repo_username, repo_id, number, action_type, message_type, custom_message):
    data = {
        'repo_username': repo_username,
        'repo_id': repo_id,
        'number': number,
        'action_type': action_type,
        'message_type': message_type,
        'custom_message': custom_message
    }

    try:
        issue = github_api.fetch_issue(repo_username, repo_id, number)
        if not issue or issue.get('error'):
            data['error'] = 'could not find issue %s' % number
            return data

        context = {
            'issue': issue,
            'user': issue.get('user')
        }
        msg = None

        if message_type == 'expire':
            msg = util.get_template('EXPIRE_TEMPLATE', context)

        elif message_type == 'forum':
            msg = util.get_template('FORUM_TEMPLATE', context)

        elif message_type == 'inapplicable':
            msg = util.get_template('INAPPLICABLE_TEMPLATE', context)

        elif message_type == 'more':
            msg = util.get_template('MORE_TEMPLATE', context)

        elif message_type == 'feature':
            github_api.add_issue_labels(repo_username, repo_id, number, [cvar['FEATURE_REQUEST_LABEL']], issue=issue)
            msg = util.get_template('FEATURE_REQUEST_TEMPLATE', context)

        elif message_type == 'no_reply':
            msg = util.get_template('CLOSING_NOREPLY_TEMPLATE', context)

        elif message_type == 'pr_close':
            msg = util.get_template('CLOSE_PULL_REQUEST_TEMPLATE', context)

        elif message_type == 'custom':
            msg = custom_message

        elif message_type == 'close':
            msg = None

        else:
            data['error'] = 'invalid message_type: %s' % message_type
            return data

        if msg and len(msg.strip()):
            data['created_comment'] = github_api.create_issue_comment(repo_username, repo_id, number, msg)

        if action_type == 'close':
            data['issue_closed'] = github_api.close_issue(repo_username, repo_id, number, issue)

        elif action_type == 'reply':
            github_api.add_issue_labels(repo_username, repo_id, number, [cvar['NEEDS_REPLY_LABEL']], issue=issue)

    except Exception as ex:
        print 'submit_issue_response error, %s: %s' % (number, ex)
        data['error'] = '%s' % ex

    return data