Skip to main content

Library for automation updates on multiple repositories.

Project description

Multi repo automation

Config

Create a file with something like this:

- dir: /home/user/src/myrepo
  name: user/myrepo
  types: ['javascript', 'python', 'docker']
  master_branch: master
  stabilization_branches: [1.0, 1.1]
  folders_to_clean: []

Utilities

import multi_repo_automation as mra

# Test if a file exists
if mra.run(["git", "ls-files", "**/*.txt"], stdout=subprocess.PIPE).stdout.strip() != b"":
  print("Found")
# Test if a file exists and contains a text
if mra.git_grep(file, r"\<text\>"]):
  print("Found")
# Edit a file in vscode
mra.edit("file")

To do something on all repo that not depends on the branch

#!/usr/bin/env python3
import argparse
import multi_repo_automation as mra

def _main() -> None:
    with open(os.path.join(os.path.dirname(__file__), "repo.yaml"), encoding="utf-8") as f:
        repos = yaml.load(f.read(), Loader=yaml.SafeLoader)

    args_parser = argparse.ArgumentParser(description="Apply an action on all the repos.")
    args = args_parser.parse_args()

    pull_request_created_message = []
    try:
        for repo in repos:
                try:
                    print(f"=== {repo['name']} ===")
                    with mra.Cwd(repo):
                        # Do something
                finally:
                    print(f"=== {repo['name']} ===")
    finally:
        print(f"{len(pull_request_created_message)} pull request created")
        for repo in pull_request_created_message:
            print(repo)

if __name__ == '__main__':
  _main()

To update all the master branches write a script like

#!/usr/bin/env python3
import argparse
import multi_repo_automation as mra

def _main() -> None:
    with open(os.path.join(os.path.dirname(__file__), "repo.yaml"), encoding="utf-8") as f:
        repos = yaml.load(f.read(), Loader=yaml.SafeLoader)

    args_parser = argparse.ArgumentParser(description="Apply an action on all the repos.")
    args = args_parser.parse_args()

    pull_request_created_message = []
    try:
        for repo in repos:
                try:
                    print(f"=== {repo['name']} ===")
                    with mra.Cwd(repo):
                        pull_request_created_message.extend(_do(repo))
                finally:
                    print(f"=== {repo['name']} ===")
    finally:
        print(f"{len(pull_request_created_message)} pull request created")
        for repo in pull_request_created_message:
            print(repo)

if __name__ == '__main__':
  _main()

def _do(repo: mra.Repo) -> List[str]:
    create_branch = mra.CreateBranch(
        repo,
        "branch_name",
        "Commit/Pull request message",
    )
    with create_branch:
        # Do something

    if create_branch.pull_request_created:
        if create_branch.message:
            return [create_branch.message]
        else:
            return [f"https://github.com/{repo['name']}/pulls"]
  return []

To update all the stabilization branches write a script like

#!/usr/bin/env python3
import argparse
import multi_repo_automation as mra

def _main() -> None:
    with open(os.path.join(os.path.dirname(__file__), "repo.yaml"), encoding="utf-8") as f:
        repos = yaml.load(f.read(), Loader=yaml.SafeLoader)

    args_parser = argparse.ArgumentParser(description="Apply an action on all the repos.")
    args = args_parser.parse_args()

    pull_request_created_message = []
    try:
        for repo in repos:
                try:
                    print(f"=== {repo['name']} ===")
                    with mra.Cwd(repo):
                        pull_request_created_message.extend(
                          do_on_base_branches(repo:, 'branch_prefix' , _do)
                finally:
                    print(f"=== {repo['name']} ===")
    finally:
        print(f"{len(pull_request_created_message)} pull request created")
        for repo in pull_request_created_message:
            print(repo)

if __name__ == '__main__':
  _main()

def _do(repo: mra.Repo) -> List[str]:
    create_branch = mra.CreateBranch(
        repo,
        "branch_name",
        "Commit/Pull request message",
    )
    with create_branch:
        # Do something

    if create_branch.pull_request_created:
        if create_branch.message:
            return [create_branch.message]
        else:
            return [f"https://github.com/{repo['name']}/pulls"]
  return []

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multi_repo_automation-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

multi_repo_automation-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file multi_repo_automation-0.1.0.tar.gz.

File metadata

  • Download URL: multi_repo_automation-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for multi_repo_automation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbc92d8faeabdeb2dde695b6f8e41ae2469e3e07487213dc8fe5737855b33433
MD5 3d267874f6905747b71b614de3baad3a
BLAKE2b-256 c78bd76b6928c6c2908153d540582db847165b2347e9de576ec031c8d731d328

See more details on using hashes here.

Provenance

File details

Details for the file multi_repo_automation-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for multi_repo_automation-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17ccb4cb03a7a2fe124d86d34bf87f7ce96868e33bd4d2548fa9eaf8760d9028
MD5 c83598f9e6d0b79b4329f0178e6aeb5f
BLAKE2b-256 b64cda4cdccb62d7950b38d9e86c8f2d86abe1d2368176669a139672cda2e9cc

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page