Last active
July 21, 2019 01:40
-
-
Save jordan-chalupka/7541bb17b6e9af6d64ed8a10fab1c67b to your computer and use it in GitHub Desktop.
Python AWS Lambda function to delete branches which have been merged into master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
def run(command): | |
print(command) | |
process = subprocess.call(command, shell=True, cwd='/tmp/') | |
def lambda_handler(event, context): | |
GITHUB_EMAIL = os.environ['GITHUB_EMAIL'] | |
GITHUB_USERNAME = os.environ['GITHUB_USERNAME'] | |
GITHUB_REPO = os.environ['GITHUB_REPO'] | |
GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] | |
commands = ( | |
'rm -rf /tmp/*', | |
f"git clone @github.com/{GITHUB_USERNAME}/{GITHUB_REPO}.git">https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{GITHUB_REPO}.git .", | |
'git branch -r | grep -v master | cut -d/ -f2- | xargs -n 1 git push origin --delete' | |
) | |
for command in commands: | |
run(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment