Skip to content
Merged
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 taskboot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from taskboot.build import build_hook
from taskboot.build import build_image
from taskboot.cargo import cargo_publish
from taskboot.git import git_push
from taskboot.github import github_release
from taskboot.push import heroku_release
from taskboot.push import push_artifacts
Expand Down Expand Up @@ -269,6 +270,26 @@ def main():
)
deploy_pypi.set_defaults(func=publish_pypi)

# Push on a repository
git_push_cmd = commands.add_parser(
"git-push", help="Push the commits of a branch on a repository",
)
git_push_cmd.add_argument(
"--force-push", action="store_true", help="Force push the branch",
)
git_push_cmd.add_argument(
"repository",
type=str,
help="Repository name to use (example: github.com/mozilla/task-boot)",
)
git_push_cmd.add_argument(
"user", type=str, help="User login to use",
)
git_push_cmd.add_argument(
"branch", type=str, help="The name of the branch to use",
)
git_push_cmd.set_defaults(func=git_push)

# Deploy as a github release
github_release_cmd = commands.add_parser(
"github-release", help="Create a GitHub release and publish assets"
Expand Down
35 changes: 35 additions & 0 deletions taskboot/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import logging
import subprocess

from taskboot.config import Configuration

logger = logging.getLogger(__name__)


def git_push(target, args):
"""
Push commits on a repository
"""

# Load config from file/secret
config = Configuration(args)
assert config.has_github_auth(), "Missing GitHub authentication"

# Set remote repository
repo_link = "https://{}:{}@{}.git".format(
args.user, config.github["token"], args.repository
)
subprocess.run(["git", "remote", "set-url", "origin", repo_link])

# Push on repository
if args.force_push:
command = ["git", "push", "-f", "origin", args.branch]
else:
command = ["git", "push", "origin", args.branch]

subprocess.run(command, check=True)