Commit d6457437 authored by Ivan Yelizariev's avatar Ivan Yelizariev
Browse files

Merge branch 'master' into 'master'

Master

See merge request !59
parents 2cfc8d48 1fea3124
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
{
    "git_author": "TestMergeBot <Rusllanx@yandex.ru>", 
    "sqs_queue_url": "https://us-east-2.queue.amazonaws.com/504794208121/github-bot-queue", 
    "ec2_instance_id": "i-0b42cb725341a7e9f", 
    "instance_profile_name": "github-instance-profile-name", 
    "ssm_parameters": {
        "GIT_AUTHOR": "TestMergeBot <Rusllanx@yandex.ru>", 
        "GITHUB_TOKEN_FOR_BOT": "c72357690724c71e1a5230eacc7fb5355c020e08", 
        "QUEUE_NAME": "github-bot-queue", 
        "SHUTDOWN_TIME": "60"
    }, 
    "key_name": "github-bot-key", 
    "queue_name": "github-bot-queue", 
    "role_name_lambda": "github-bot-lambda-role", 
    "role_policies_for_lambda": [
        "arn:aws:iam::aws:policy/AmazonSQSFullAccess", 
        "arn:aws:iam::aws:policy/AmazonEC2FullAccess"
    ], 
    "role_policies_for_ec2": [
        "arn:aws:iam::aws:policy/AmazonSQSFullAccess", 
        "arn:aws:iam::aws:policy/AmazonEC2FullAccess", 
        "arn:aws:iam::aws:policy/AWSLambdaExecute", 
        "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM", 
        "arn:aws:iam::aws:policy/AmazonSSMFullAccess"
    ], 
    "lambda_name": "github-bot-lambda", 
    "role_name_ec2": "github-bot-ec2-role"
}
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ def deploy_bot(github_token, deployment_info, info_filename):

    print('Starting deployment process.')
    user_data = open('/'.join(os.path.realpath(__file__).split('/')[:-1]) + '/ec2-script.sh').read()

    user_data += '\nsudo git config --global user.name {}'.format(git_author.split()[0])
    user_data += '\nsudo git config --global user.email {}'.format(git_author.split()[0])

    role_policies_for_ec2 = ['arn:aws:iam::aws:policy/AmazonSQSFullAccess',
                             'arn:aws:iam::aws:policy/AmazonEC2FullAccess',
                             'arn:aws:iam::aws:policy/AWSLambdaExecute',
@@ -32,6 +36,12 @@ def deploy_bot(github_token, deployment_info, info_filename):
                                'arn:aws:iam::aws:policy/AmazonEC2FullAccess']
    deployment_info['role_policies_for_lambda'] = role_policies_for_lambda

    if hook_exists == '':
        hook_exists = 'none'

    if hook_created == '':
        hook_created = 'none'

    ssm_parameters = {
        'QUEUE_NAME': queue_name,
        'SHUTDOWN_TIME': '60',
@@ -40,6 +50,7 @@ def deploy_bot(github_token, deployment_info, info_filename):
        'WEBHOOK_WHEN_PORTING_PR_EXISTS': hook_exists,
        'WEBHOOK_WHEN_PORTING_PR_CREATED': hook_created
    }

    deployment_info['ssm_parameters'] = ssm_parameters

    sqs_response = create_sqs(queue_name)
+24 −8
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ def write_in_log(log_message):
    with open('/home/ec2-user/logs-github-bot/{}.txt'.format(now.strftime('%Y-%m-%d')), 'a') as logfile:
        logfile.write('{} {}\n'.format(now.strftime('%Y-%m-%d %H:%M:%S'), log_message))

    print(log_message)


def write_message(message):
    """
@@ -62,8 +64,8 @@ def update_bot():
    Updates bot itself.
    """

    call(['git', '-C', 'odoo-devops', 'fetch', '--all'])
    call(['git', '-C', 'odoo-devops', 'reset', '--hard', 'origin'])
    call(['sudo', 'git', '-C', 'odoo-devops', 'fetch', '--all'])
    call(['sudo', 'git', '-C', 'odoo-devops', 'reset', '--hard', 'origin'])


def process_message(msg_body, required_fields, github_token, git_author=None,
@@ -130,14 +132,22 @@ def process_message(msg_body, required_fields, github_token, git_author=None,

                write_in_log('making pull-request in {} {} from {} {}'.format(full_repo_name, next_branch,
                                                                              fork_user, merge_branch))
                Popen(['python', '/home/ec2-user/odoo-devops/tools/porting-bot/scripts/pull-request.py',

                pr_call_params = ['python', '/home/ec2-user/odoo-devops/tools/porting-bot/scripts/pull-request.py',
                       full_repo_name, next_branch, fork_user, merge_branch,
                       '--github_token', github_token,
                       '--webhook_when_porting_pr_exists', hook_exists,
                       '--webhook_when_porting_pr_created', hook_created,
                       '--original_pr_title', msg_body['pull_request']['title']]).wait()
                       '--original_pr_title', msg_body['pull_request']['title']]

                if hook_exists is not None:
                    pr_call_params.extend(['--webhook_when_porting_pr_exists', hook_exists])
                if hook_created is not None:
                    pr_call_params.extend(['--webhook_when_porting_pr_created', hook_created])

                write_in_log(' '.join(pr_call_params))
                Popen(pr_call_params).wait()

                write_in_log('pull-request complete'.format(next_branch))
                successful = True

            else:
                write_in_log('merge in branch "{}" is not supported'.format(next_branch))
@@ -145,7 +155,6 @@ def process_message(msg_body, required_fields, github_token, git_author=None,
        else:
            write_in_log('action is {}, pull request not merged'.format(action))

        successful = True

    else:
        absent_fields = ''
@@ -174,6 +183,12 @@ def main():
    hook_exists = ssm_client.get_parameter(Name='WEBHOOK_WHEN_PORTING_PR_EXISTS', WithDecryption=True)['Parameter']['Value']
    hook_created = ssm_client.get_parameter(Name='WEBHOOK_WHEN_PORTING_PR_CREATED', WithDecryption=True)['Parameter']['Value']

    if hook_exists == 'none':
        hook_exists = None

    if hook_created == 'none':
        hook_created = None

    sqs = boto3.resource('sqs', region_name=region_name)
    queue = sqs.get_queue_by_name(QueueName=queue_name)

@@ -192,11 +207,12 @@ def main():
            msg_body = json.loads(message.body)
            required_fields = ['action', 'number', 'repository']

            write_message(message.body)
            successful = process_message(msg_body, required_fields,
                                         github_token, git_author=git_author,
                                         hook_exists=hook_exists,
                                         hook_created=hook_created)
            if successful:
                write_message(message.body)

            queue.delete_messages(Entries=[{
                'Id': message.message_id,
+0 −23
Original line number Diff line number Diff line
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAkEir3RCWDUc25rUSj0Xyd1uifP3z54pQ36l9bgD3PJwrJwnEGlMPP2M8WPUX
VTAoYd/8JMu/eCgB5X0qrSxcWRY8AjbVSgzohq4frrRNeFAKA+LanJFwD2czEXPgNQ73ybQ2yMjO
miT82sLRd+viwateBahjNQNfwxyqYyu70eotspR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m3VksCFE/SBwpJCjrLJRD2PN4nHrtNcwHnMHWyyRd1wuj
eEx9a9aUc0uFuMr8WaGZ73zyJfKltjXkE6BYG201zIkLQOoZaaeWtMpk/E4dNDLNGBrgYug53Ng4
Mj9V3+v+V0zC13lhHpiY6Kfem1TDX+IyIZK/LMWcILDdUIHrAoGAec6mI6bOP6OaQQy7vAgkvO/X
LNXic6BmtiUKmADyaTaf+xT9nYbv8FChMQnp2IrE3eqcq9jfAwo/uyO6PNvW5/tL3FCeJXq1HDra
YwkbOnlrs8RmnDGp6reT3dXsvBG3xMOr/vXxP7N1K9tsMhA+zYg/bgZb1rsxsBibNk8qqLQ=
-----END RSA PRIVATE KEY-----
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@ import os
from subprocess import Popen, PIPE, call
import argparse

VERSION_EMOJIS = {'8.0': ':eight:', '9.0': ':nine:', '10.0': ':one::zero:', '11.0': ':one::one:', '12.0': ':one::two:'}
VERSION_EMOJIS = {'8.0': ':eight:', '9.0': ':nine:', '10.0': ':one::zero:',
                  '11.0': ':one::one:', '12.0': ':one::two:', '13.0': ':one::three:'}


def main():
Loading