Exemple #1
0
        # get all json files in assets/features
        self.accounts_features_data = file_to_json(
            get_all_assets("features", "accounts.json")[0])
        # create questions
        self.add_question(
            CheckboxQuestion(
                "functions",
                "Select all the functionality you want for accounts",
                list(
                    map(lambda x: x["name"],
                        self.accounts_features_data["functions"])),
            ))

    def post_process(self, responses):
        for account_function in responses["functions"]:
            github_user: github.AuthenticatedUser = get_authenticated_user()
            project_name: str = Node.get_full_response()["metadata"]["name"]
            github_repo: github.Repository = github_user.get_repo(project_name)
            user_story = list(
                filter(
                    lambda x: x["name"] == account_function,
                    self.accounts_features_data["functions"],
                ))[0]["user_story"]
            github_repo.create_issue(
                f"add support for account {account_function}",
                f"{user_story}",
            )


Node.register(AccountsNode())
Exemple #2
0
from preapp import Node, ConfirmQuestion
from preapp.utils.fileio import get_all_assets


class FeaturesNode(Node):
    """Allows users to select features for their apps"""

    def __init__(self):
        super(FeaturesNode, self).__init__("features", [], parents=["platform"])

    def pre_process(self):
        # get all json files in assets/features
        features: List[str] = get_all_assets("features", "json", False, False)
        # create questions
        for feature in features:
            self.add_question(ConfirmQuestion(feature, f"Do you want to include {feature}?", False))

    def post_process(self, responses):
        # add included features sub nodes
        for key, value in responses.items():
            if value and key != "serializable":
                self.add_child(key)


Node.register(FeaturesNode())
Exemple #3
0
from preapp import Node, ConfirmQuestion


class GithubNode(Node):
    """Checks if the user wants to connect their github"""

    def __init__(self):
        super(GithubNode, self).__init__(
            "github", [ConfirmQuestion("use", "Do you want to connect your github?", True)],
        )

    def post_process(self, responses):
        if responses["use"] == True:
            self.add_child("github_credentials")
            self.add_child("github_repository")


Node.register(GithubNode())
Exemple #4
0
from preapp.question import ConfirmQuestion
import subprocess
from preapp import Node
from preapp.utils.miscellaneous import bash


class GithubCloneNode(Node):
    """Clones a github repository"""
    def __init__(self):
        super(GithubCloneNode, self).__init__(
            "github_clone",
            [],
            parents=[
                "metadata",
                "github",
                "github_repository",
                "github_credentials",
            ],
            serializable=False,
        )

    def pre_process(self):
        project_name: str = self.get_full_response()["metadata"]["name"]
        github_username: str = self.get_full_response(
        )["github_credentials"]["username"]
        repo_download_url: str = f"https://github.com/{github_username}/{project_name}.git"
        bash(f"git clone {repo_download_url}")


Node.register(GithubCloneNode())
Exemple #5
0
            frameworks: Dict[str, Any] = self.get_full_response()["framework"]
            project_name: str = self.get_full_response()["metadata"]["name"]
            bash(
                f"cd {project_name} && mkdir .github && cd .github && mkdir workflows"
            )

            for key, value in frameworks.items():
                call_hook("github_actions", key, value)

            # if "web_frontend" in frameworks:
            #     call_hook("github_actions", "web_frontend", frameworks["web_frontend"])
            # if "web_backend" in frameworks:
            #     call_hook("github_actions", "web_backend", frameworks["web_backend"])


Node.register(GithubActionsNode())


def commit_actions_file(actions_filepath: str, project_name: str,
                        github_username: str, github_password: str) -> None:
    copy_file(actions_filepath,
              f"{os.getcwd()}/{project_name}/.github/workflows/nodejs.yml")

    commit_and_push(
        "Setup Github Actions",
        project_name,
        github_username,
        github_password,
        directory=project_name,
    )
Exemple #6
0
                    "Select the label organization for your repository?",
                    ["default", "PST"],
                )
            ],
            parents=["metadata", "github_credentials", "github_repository"],
        )

    def post_process(self, responses):
        if responses["organization"] == "PST":
            repo_name: str = self.get_full_response()["metadata"]["name"]

            remove_all_labels(repo_name)

            github_user: AuthenticatedUser = get_authenticated_user()
            repo_object = github_user.get_repo(repo_name)

            for item in file_to_json(
                    f"{__assets_directory__}/github/labels/pst.json"):
                repo_object.create_label(item["name"], item["color"],
                                         item["description"])


Node.register(GithubLabelsNode())


def remove_all_labels(repository_name: str) -> None:
    github_user: AuthenticatedUser = get_authenticated_user()

    for label in github_user.get_repo(repository_name).get_labels():
        label.delete()
Exemple #7
0
from __future__ import print_function, unicode_literals
from PyInquirer import prompt, print_json
from preapp.nodes.root_node import RootNode
import argparse
from preapp import Node

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="tool for setting up software projects")
    parser.add_argument("-p", "--preset", action="store", type=str)
    parser.add_argument("-c", "--credentials", action="store", type=str)

    args = parser.parse_args()
    root_node: RootNode = RootNode(args.preset, args.credentials)
    Node.register(root_node)
    root_node.process()