Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
40 changes: 15 additions & 25 deletions git-manager-config.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 19 additions & 18 deletions git-manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]


Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions playbook/add-file-static/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXAMPLE
13 changes: 13 additions & 0 deletions playbook/add-file-static/run.yml
Original file line number Diff line number Diff line change
@@ -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 }}

23 changes: 23 additions & 0 deletions playbook/add-file-static/sample-add-file-config.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions playbook/update-license/sample-update-license-config.yml
Original file line number Diff line number Diff line change
@@ -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