File indexing completed on 2024-12-08 08:08:26
0001 """ 0002 functions for setting the workflow of a repository 0003 """ 0004 0005 # SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im> 0006 # 0007 # SPDX-License-Identifier: GPL-2.0-or-later 0008 0009 import argparse 0010 0011 from lab.config import RepositoryConfig, Workflow 0012 0013 0014 def parser( 0015 subparsers: argparse._SubParsersAction, # pylint: disable=protected-access 0016 ) -> argparse.ArgumentParser: 0017 """ 0018 Subparser for workflow command 0019 :param subparsers: subparsers object from global parser 0020 :return: merge request creation subparser 0021 """ 0022 workflow_parser: argparse.ArgumentParser = subparsers.add_parser( 0023 "workflow", help="Set the workflow to use for a project" 0024 ) 0025 0026 group = workflow_parser.add_mutually_exclusive_group(required=True) 0027 group.add_argument( 0028 "--fork", 0029 help="Set the fork workflow (branch in a fork of the upstream repository)", 0030 action="store_true", 0031 ) 0032 group.add_argument( 0033 "--workbranch", 0034 help="Set the work branch workflow (branch in the upstream repository)", 0035 action="store_true", 0036 ) 0037 return workflow_parser 0038 0039 0040 def run(args: argparse.Namespace) -> None: 0041 """ 0042 run workflow command 0043 :param args: parsed arguments 0044 """ 0045 repository_config = RepositoryConfig() 0046 if args.fork: 0047 repository_config.set_workflow(Workflow.FORK) 0048 elif args.workbranch: 0049 repository_config.set_workflow(Workflow.WORKBRANCH) 0050 repository_config.save()