diff --git a/README.md b/README.md index b4e72ee..b839612 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # git-manager Manage a large amount of github repos at once + +## Setup +- Install Requirments: + - Ansible + - Python + +## How To Use +- Fill out the sample config +- Fill in `extra_vars` in your config that are necessary for what you need to do +- Copy and paste your config into `git-manager-config.yml` +- Create an ansible playbook called `run.yml` in it's own dir that orchestrates your changes + - This is the `playbook_dir` +- Run with `python3 git-manager.py` + +**You will still need to go manually create the PRs** + +### Update LICENSE Dates +Replaces an old year with a new year in a LICENSE file + +### Add File(Static) +Adds a file that doesn't need to change per repo to all repos \ No newline at end of file diff --git a/git-manager-config.yml b/git-manager-config.yml index a1818df..2d48e3c 100644 --- a/git-manager-config.yml +++ b/git-manager-config.yml @@ -1,33 +1,23 @@ # python3 # repersent your orgs and repos here # config['orgs']['cyberark']['repos'] -# config['general']['branch-name'] +# config['general']['branch_name'] + orgs: cyberark: - repos: - - summon - - conjur - - summon-conjur + repos: [conjur, secretless-broker, summon] # repersent your general configs here general: - branch-name: updating-LICENSE - commit-message: updating LICENSE file - pr-name: updating LICENSE - git-add: - - LICENSE - remove-tmp-dir: no - playbook-dir: ./playbook/update-license - create-branch: yes - extra-vars: - from_year: 2020 - to_year: 2021 - - - - - - - - - + branch_name: add-CODEOWNERS + pr_name: add CODEOWNERS file + git_add: + - .github/CODEOWNERS + commit_message: Adding CODEOWNERS file + remove_tmp_dir: no + playbook_dir: ./playbook/add-file-static + create_branch: yes + extra_vars: + destination_dir: .github + file_name: CODEOWNERS + static_file_path: ./CODEOWNERS diff --git a/git-manager.py b/git-manager.py index e702a63..09b9f37 100644 --- a/git-manager.py +++ b/git-manager.py @@ -13,11 +13,11 @@ global LOGGER MANDATORY_GENERAL_PARAMETERS = [ - 'pr-name', - 'branch-name', - 'commit-message', - 'git-add', - 'playbook-dir' + 'pr_name', + 'branch_name', + 'commit_message', + 'git_add', + 'playbook_dir' ] @@ -133,14 +133,14 @@ def clone_and_setup_repos(config, working_dir): for repo in repos: LOGGER.info("Cloning repo '{}/{}' and copying over files located in playbook directory".format(org, repo)) git_clone(working_dir, org, repo) - branch_name = config['general']['branch-name'] + branch_name = config['general']['branch_name'] # if we are creating branch then lets do it - if config['general'].get('create-branch') is True: + if config['general'].get('create_branch') is True: git_branch(working_dir, org, repo, branch_name) # now checkout branch git_checkout(working_dir, org, repo, branch_name) - playbook_dir = config['general']['playbook-dir'] + playbook_dir = config['general']['playbook_dir'] # now copy over the playbook playbook_files = [f for f in listdir(playbook_dir) if isfile(join(playbook_dir, f))] for playbook_file in playbook_files: @@ -150,34 +150,35 @@ def clone_and_setup_repos(config, working_dir): def update_repos(config, working_dir): extra_vars = {} - if 'extra-vars' in config['general']: - extra_vars = config['general']['extra-vars'] + if 'extra_vars' in config['general']: + extra_vars = config['general']['extra_vars'] + LOGGER.debug("Extra Variables:", extra_vars) - for org, value in config['orgs'].items(): + for organization, value in config['orgs'].items(): repos = value['repos'] for repo in repos: - LOGGER.info("Running 'run.yml' in '{}/{}'".format(org, repo)) - extra_vars['org'] = org + LOGGER.info("Running 'run.yml' in '{}/{}'".format(organization, repo)) + extra_vars['org'] = organization extra_vars['repo'] = repo - run_playbook(working_dir, org, repo, extra_vars) - LOGGER.info("Finished running 'run.yml' in '{}/{}'".format(org, repo)) + run_playbook(working_dir, organization, repo, extra_vars) + LOGGER.info("Finished running 'run.yml' in '{}/{}'".format(organization, repo)) def git_add(config, working_dir, org, repo): # this should be a list - add_files = config['general']['git-add'] + add_files = config['general']['git_add'] command = ['git', 'add'] command.extend(add_files) repo_dir = get_repo_dir(working_dir, org, repo) subprocess_command(command, repo_dir) def git_commit(config, working_dir, org, repo): - commit_message = config['general']['commit-message'] + commit_message = config['general']['commit_message'] command = ['git', 'commit', '-m', commit_message] repo_dir = get_repo_dir(working_dir, org, repo) subprocess_command(command, repo_dir) def git_push(config, working_dir, org, repo): - command = ['git', 'push'] + command = ['git', 'push', '--set-upstream', 'origin', config['general']['branch_name']] repo_dir = get_repo_dir(working_dir, org, repo) subprocess_command(command, repo_dir) diff --git a/playbook/add-file-static/CODEOWNERS b/playbook/add-file-static/CODEOWNERS new file mode 100644 index 0000000..45ca171 --- /dev/null +++ b/playbook/add-file-static/CODEOWNERS @@ -0,0 +1 @@ +EXAMPLE diff --git a/playbook/add-file-static/run.yml b/playbook/add-file-static/run.yml new file mode 100644 index 0000000..af9deff --- /dev/null +++ b/playbook/add-file-static/run.yml @@ -0,0 +1,13 @@ +--- +- name: Running this playbook in '{{ org }}/{{ repo }}' + hosts: localhost + tasks: + - name: make directory '{{ destination_dir }}' if it does not exist + shell: mkdir -p "{{ destination_dir }}" + + - name: copy '{{ static_file_path }}' into '{{ destination_dir }}/{{ file_name }}' + shell: cp "{{ static_file_path }}" "{{ destination_dir }}/{{ file_name }}" + + - name: open browser + shell: open https://www.github.com/{{ org }}/{{ repo }} + \ No newline at end of file diff --git a/playbook/add-file-static/sample-add-file-config.yml b/playbook/add-file-static/sample-add-file-config.yml new file mode 100644 index 0000000..2d48e3c --- /dev/null +++ b/playbook/add-file-static/sample-add-file-config.yml @@ -0,0 +1,23 @@ +# python3 +# repersent your orgs and repos here +# config['orgs']['cyberark']['repos'] +# config['general']['branch_name'] + +orgs: + cyberark: + repos: [conjur, secretless-broker, summon] + +# repersent your general configs here +general: + branch_name: add-CODEOWNERS + pr_name: add CODEOWNERS file + git_add: + - .github/CODEOWNERS + commit_message: Adding CODEOWNERS file + remove_tmp_dir: no + playbook_dir: ./playbook/add-file-static + create_branch: yes + extra_vars: + destination_dir: .github + file_name: CODEOWNERS + static_file_path: ./CODEOWNERS diff --git a/playbook/update-license/sample-update-license-config.yml b/playbook/update-license/sample-update-license-config.yml new file mode 100644 index 0000000..b58190a --- /dev/null +++ b/playbook/update-license/sample-update-license-config.yml @@ -0,0 +1,26 @@ +# python3 +# repersent your orgs and repos here +# config['orgs']['cyberark']['repos'] +# config['general']['branch-name'] +orgs: + cyberark: + repos: + - summon + - conjur + - summon-conjur + + # repersent your general configs here + general: + branch_name: updating-LICENSE + commit_message: updating LICENSE file + pr_name: updating LICENSE + git_add: + - LICENSE + remove_tmp_dir: no + playbook_dir: ./playbook/update-license + create_branch: yes + extra_vars: + from_year: 2020 + to_year: 2021 + + \ No newline at end of file