This commit is contained in:
Hanzhang Zeng (Roger) 2019-05-13 16:22:56 -07:00
Родитель def8f5b9fa
Коммит 961b28554a
5 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -35,7 +35,7 @@ class ProjectManager(BaseManager):
self._config = Configuration(base_url=base_url) self._config = Configuration(base_url=base_url)
self._client = ServiceClient(creds, self._config) self._client = ServiceClient(creds, self._config)
self._credentials = creds self._credentials = creds
#need to make a secondary client for the creating project as it uses a different base url # Need to make a secondary client for the creating project as it uses a different base url
self._create_project_config = Configuration(base_url=create_project_url) self._create_project_config = Configuration(base_url=create_project_url)
self._create_project_client = ServiceClient(creds, self._create_project_config) self._create_project_client = ServiceClient(creds, self._create_project_config)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}

Просмотреть файл

@ -11,6 +11,7 @@ from ..exceptions import (
) )
from ..base.base_github_manager import BaseGithubManager from ..base.base_github_manager import BaseGithubManager
class GithubRepositoryManager(BaseGithubManager): class GithubRepositoryManager(BaseGithubManager):
def check_github_repository(self, repository_fullname): def check_github_repository(self, repository_fullname):
@ -91,6 +92,7 @@ class GithubRepositoryManager(BaseGithubManager):
def commit_file(self, repository_fullname, file_path, commit_message, file_data, sha=None, encode='utf-8'): def commit_file(self, repository_fullname, file_path, commit_message, file_data, sha=None, encode='utf-8'):
data = { data = {
"branch": "master",
"message": "{message}".format(message=commit_message), "message": "{message}".format(message=commit_message),
"content": base64.b64encode(bytes(file_data.encode(encode))).decode('ascii'), "content": base64.b64encode(bytes(file_data.encode(encode))).decode('ascii'),
} }

Просмотреть файл

@ -13,6 +13,7 @@ except ImportError:
from subprocess import STDOUT, check_call, check_output, CalledProcessError from subprocess import STDOUT, check_call, check_output, CalledProcessError
from ..exceptions import GitOperationException from ..exceptions import GitOperationException
def does_git_exist(): def does_git_exist():
try: try:
check_call("git", stdout=DEVNULL, stderr=STDOUT) check_call("git", stdout=DEVNULL, stderr=STDOUT)
@ -23,9 +24,11 @@ def does_git_exist():
return False return False
return True return True
def does_local_git_repository_exist(): def does_local_git_repository_exist():
return os.path.exists(".git") return os.path.exists(".git")
def does_git_remote_exist(remote_name): def does_git_remote_exist(remote_name):
command = ["git", "remote", "show"] command = ["git", "remote", "show"]
try: try:
@ -35,6 +38,7 @@ def does_git_remote_exist(remote_name):
return remote_name in output return remote_name in output
def does_git_has_credential_manager(): def does_git_has_credential_manager():
command = ["git", "config", "--list"] command = ["git", "config", "--list"]
try: try:
@ -44,6 +48,7 @@ def does_git_has_credential_manager():
return "credential.helper=manager" in output return "credential.helper=manager" in output
def git_init(): def git_init():
command = ["git", "init"] command = ["git", "init"]
try: try:
@ -51,6 +56,7 @@ def git_init():
except CalledProcessError: except CalledProcessError:
raise GitOperationException(message=" ".join(command)) raise GitOperationException(message=" ".join(command))
def git_add_remote(remote_name, remote_url): def git_add_remote(remote_name, remote_url):
command = ["git", "remote", "add", remote_name, remote_url] command = ["git", "remote", "add", remote_name, remote_url]
try: try:
@ -58,6 +64,7 @@ def git_add_remote(remote_name, remote_url):
except CalledProcessError: except CalledProcessError:
raise GitOperationException(message=" ".join(command)) raise GitOperationException(message=" ".join(command))
def git_remove_remote(remote_name): def git_remove_remote(remote_name):
command = ["git", "remote", "remove", remote_name] command = ["git", "remote", "remove", remote_name]
try: try:
@ -65,6 +72,7 @@ def git_remove_remote(remote_name):
except CalledProcessError: except CalledProcessError:
raise GitOperationException(message=" ".join(command)) raise GitOperationException(message=" ".join(command))
def git_stage_all(): def git_stage_all():
command = ["git", "add", "--all"] command = ["git", "add", "--all"]
try: try:
@ -72,6 +80,7 @@ def git_stage_all():
except CalledProcessError: except CalledProcessError:
raise GitOperationException(message=" ".join(command)) raise GitOperationException(message=" ".join(command))
def git_commit(message): def git_commit(message):
command = ["git", "commit", "--allow-empty", "--message", message] command = ["git", "commit", "--allow-empty", "--message", message]
try: try:
@ -79,6 +88,7 @@ def git_commit(message):
except CalledProcessError: except CalledProcessError:
raise GitOperationException(message=" ".join(command)) raise GitOperationException(message=" ".join(command))
def git_push(remote_name, force=False): def git_push(remote_name, force=False):
command = ["git", "push", remote_name, "--all"] command = ["git", "push", remote_name, "--all"]
@ -90,6 +100,7 @@ def git_push(remote_name, force=False):
except CalledProcessError: except CalledProcessError:
raise GitOperationException(message=" ".join(command)) raise GitOperationException(message=" ".join(command))
def _sanitize_git_remote_name(organization_name, project_name, repository_name): def _sanitize_git_remote_name(organization_name, project_name, repository_name):
concatenated_remote_name = "{organization_name}_{project_name}_{repository_name}".format( concatenated_remote_name = "{organization_name}_{project_name}_{repository_name}".format(
organization_name=organization_name, organization_name=organization_name,
@ -99,6 +110,7 @@ def _sanitize_git_remote_name(organization_name, project_name, repository_name):
sanitized_remote_name = re.sub(r"[^A-Za-z0-9_-]|\s", "-", concatenated_remote_name) sanitized_remote_name = re.sub(r"[^A-Za-z0-9_-]|\s", "-", concatenated_remote_name)
return sanitized_remote_name return sanitized_remote_name
def construct_git_remote_name(organization_name, project_name, repository_name, remote_prefix): def construct_git_remote_name(organization_name, project_name, repository_name, remote_prefix):
remote_name = "_{prefix}_{name}".format( remote_name = "_{prefix}_{name}".format(
prefix=remote_prefix, prefix=remote_prefix,
@ -106,6 +118,7 @@ def construct_git_remote_name(organization_name, project_name, repository_name,
) )
return remote_name return remote_name
def construct_git_remote_url(organization_name, project_name, repository_name, domain_name="dev.azure.com"): def construct_git_remote_url(organization_name, project_name, repository_name, domain_name="dev.azure.com"):
url = "https://{domain}/{org}/{proj}/_git/{repo}".format( url = "https://{domain}/{org}/{proj}/_git/{repo}".format(
domain=domain_name, domain=domain_name,

Просмотреть файл

@ -8,6 +8,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from ..constants import (WINDOWS, PYTHON, NODE, DOTNET, POWERSHELL) from ..constants import (WINDOWS, PYTHON, NODE, DOTNET, POWERSHELL)
from ..exceptions import LanguageNotSupportException from ..exceptions import LanguageNotSupportException
class YamlManager(object): class YamlManager(object):
""" Generate yaml files for devops """ Generate yaml files for devops

Просмотреть файл

@ -8,7 +8,7 @@ from os import path
from setuptools import setup, find_packages from setuptools import setup, find_packages
NAME = "azure-functions-devops-build" NAME = "azure-functions-devops-build"
VERSION = "0.0.21" VERSION = "0.0.22"
REQUIRES = ["msrest", REQUIRES = ["msrest",
"vsts", "vsts",