def update_changelog(version: str, github_repository: Repository) -> None: """ Add a version title to the changelog. """ changelog_path = Path('CHANGELOG.rst') branch = 'master' changelog_content_file = github_repository.get_contents( path=str(changelog_path), ref=branch, ) # ``get_contents`` can return a ``ContentFile`` or a list of # ``ContentFile``s. assert isinstance(changelog_content_file, ContentFile) changelog_bytes = changelog_content_file.decoded_content changelog_contents = changelog_bytes.decode('utf-8') new_changelog_contents = changelog_contents.replace( 'Next\n----', f'Next\n----\n\n{version}\n------------', ) github_repository.update_file( path=str(changelog_path), message=f'Update for release {version}', content=new_changelog_contents, sha=changelog_content_file.sha, )
def create_pr( repo: Repository, pr_branch_name: str, head: str, file: ContentFile, updated_content: str, pr_title: str, pr_body: str, ): try: repo.get_branch(pr_branch_name) print(f"Branch '{pr_branch_name}' already exist. Skipping update.") return except GithubException as ex: if ex.status != 404: raise pr_branch = repo.create_git_ref(pr_branch_name, head) repo.update_file( file.path, f"{pr_title}\n\n{pr_body}", updated_content, file.sha, branch=pr_branch_name, ) repo.create_pull(title=pr_title, body=pr_body, head=pr_branch.ref, base=BASE_BRANCH)
def update_homebrew( homebrew_filename: str, version_str: str, github_repository: Repository, homebrew_tap_github_repository: Repository, ) -> None: """ Update a Homebrew file in a given Homebrew tap with an archive from a given repository. """ archive_url = github_repository.get_archive_link( archive_format='tarball', ref=version_str, ) new_recipe_contents = get_homebrew_formula( archive_url=archive_url, head_url=github_repository.clone_url, homebrew_recipe_filename=homebrew_filename, ) message = f'Homebrew recipe for version {version_str}' try: content_file = homebrew_tap_github_repository.get_contents( path=homebrew_filename, ref='master', ) except UnknownObjectException: homebrew_tap_github_repository.create_file( path=homebrew_filename, message=message, content=new_recipe_contents, ) else: # ``get_contents`` can return a ``ContentFile`` or a list of # ``ContentFile``s. assert isinstance(content_file, ContentFile) homebrew_tap_github_repository.update_file( path=homebrew_filename, message=message, content=new_recipe_contents, sha=content_file.sha, )
def update_version(repo: Repository, version: str) -> None: """Update manifest.json with the new version""" print("Updating manifest.json...") manifest = repo.get_contents("custom_components/google_home/manifest.json") assert isinstance(manifest, ContentFile) manifest_json = json.loads(manifest.decoded_content) manifest_json["version"] = version updated_manifest = json.dumps(manifest_json, indent=2) + "\n" branch = repo.get_branch("master") # Disable branch protection before commit branch.remove_admin_enforcement() repo.update_file( path=manifest.path, message=f"Release v{version}", content=updated_manifest, sha=manifest.sha, ) # Re-enable branch protection branch.set_admin_enforcement()