示例#1
0
    def __attach(self) -> bool:

        topic_number: int
        if self.__would_attach_topics():

            for topic_number in self.__topics_number():

                request_topic: FlexioTopic = FlexioTopic().with_number(
                    topic_number)

                try:
                    Log.info('waiting... from Flexio... Topic : ' +
                             str(topic_number))
                    topic: FlexioTopic = self.__get_topic_with_number(
                        request_topic)
                    CommonTopic.print_resume_topic(topic)
                    self.__topics.append(topic)
                except FileNotFoundError:
                    Log.error(Fg.FAIL.value + 'Topic not found : retry' +
                              Fg.RESET.value)
                    self.__topics = []
                    return self.process()
            return True
        else:
            return False
示例#2
0
    def comment_issue_with_topic(self, topic: Topic) -> IssueBuilder:
        if self.__issue is not None:
            Log.info('Waiting... Comment issue with topics : ' +
                     str(topic.number))
            self.__issuer.comment(self.__issue, 'Topic : ' + topic.url())

        return self
 def clean_remote_repo(cls, version: Version = Version(0, 0, 0)):
     git: GitCmd = GitCmd(
         state_handler=StateHandler(TestGitFlowHelper.DIR_PATH_TEST))
     git.checkout(Branches.MASTER).reset_to_tag(cls.TAG_INIT) \
         .push_force() \
         .delete_remote_branch_from_name(Branches.DEVELOP.value) \
         .delete_tag(str(version), remote=True) \
         .delete_tag('-'.join([str(version.next_minor()), Level.DEV.value]), remote=True)
     Log.info('clean remote repo : ' + str(version))
 def init_repo(cls, version: str) -> StateHandler:
     cls.clean_workdir()
     cls.mount_workdir_and_clone()
     state_handler: StateHandler = StateHandler(cls.DIR_PATH_TEST)
     state_handler.state = cls.fake_state(version)
     Git(state_handler).build_branch(Branches.DEVELOP).with_action(
         Actions.INIT).process()
     Log.info('init repo : ' + str(version))
     return state_handler
示例#5
0
 def ensure_develop_branch(self) -> GitFlowCmd:
     Log.info('Ensure have Develop branch : ' +
              self.__config_handler.develop())
     if not self.__git.branch_exists(self.__config_handler.develop()):
         self.__git.checkout(
             self.__config_handler.master()).create_branch_from(
                 self.__config_handler.develop(),
                 self.__config_handler.master()).try_to_set_upstream(
                 ).try_to_push()
     return self
示例#6
0
    def process(self):
        Log.info('Start unstable version precheck')

        scheme: Schemes
        for scheme in self.state_handler.state.schemes:
            Log.info('Precheck for : ' + scheme.value)
            sc: Scheme = SchemeBuilder.create(scheme, self.state_handler)
            dev_dependencies: Dependencies = sc.release_precheck()
            print(dev_dependencies.__dict__())
            if len(dev_dependencies):
                raise HaveDevDependencyException(dev_dependencies)
示例#7
0
    def __ensure_stash_start(self):
        if not self.options.auto_stash and not self.options.default:
            if self.options.no_cli is not True:
                auto_stash: str = input(' Stash your working tree Y/N : ' +
                                        Fg.SUCCESS.value + 'N' +
                                        Fg.RESET.value + ' ')
                auto_stash_b = True if auto_stash.capitalize(
                ) == 'Y' else False
                self.options.auto_stash = auto_stash_b

        if self.options.auto_stash:
            self.version_control.stash_start()
            Log.info('Working tree stashed')
示例#8
0
 def has_repo(self) -> bool:
     has_repo: bool = False
     try:
         repo: Repo = GitCmd(self.state_handler,
                             self.options.debug).with_config_handler(
                                 self.config_handler).get_repo()
         has_repo = True
     except ValueError as e:
         if self.options.debug:
             print(e)
         Log.info('GithubIssuer have not repo')
     finally:
         return has_repo
示例#9
0
 def __list_topics(self, count: int):
     Log.info('waiting... Flexio... last 100 Topics')
     records: List[dict] = self.__get_last_100_records()
     for t_d in records:
         t: FlexioTopic
         t = FlexioTopic.build_from_api(t_d)
         print(
             '{fg_cyan}{topic_number!s} : {topic_title!s}{reset_fg}'.format(
                 fg_cyan=Fg.INFO.value,
                 reset_fg=Fg.RESET.value,
                 topic_number=t.number,
                 topic_title=t.title))
     return self.__topics_number()
示例#10
0
    def find_issue_from_branch_name(self) -> IssueBuilder:
        if self.__issuer is not None:
            issue_number: Optional[
                int] = self.__version_control.get_issue_number()

            if issue_number is not None:
                self.__issue = self.__issuer.issue_builder().with_number(
                    issue_number)
                if self.__issue is not None:
                    Log.info('Issue number ' + str(self.__issue.number) +
                             ' found')
            else:
                Log.info('No Issue found')
        return self
示例#11
0
    def find_topic_from_branch_name(self) -> TopicBuilder:
        if self.__topicer is not None:
            topics_number: Optional[List[int]] = self.__version_control.get_topics_number()
            if topics_number is not None and len(topics_number) > 0:
                self.__topics = []
                for number in topics_number:
                    self.__topics.append(self.__topicer.topic_builder().with_number(number))

            if self.__topics is not None and len(self.__topics) > 0:
                for topic in self.__topics:
                    Log.info('Topic number ' + str(topic.number) + ' found')
            else:
                Log.info('No Topic found')

        return self
示例#12
0
class UserController:
    def __init__(self):
        self.logger = Log("AdminController")
        self.STATES = dict()
        self.NEXT_STATES = dict()

    def update_create_user(self, chat):
        try:
            user = User.objects.filter(chat_id=chat.id).first()
            if user:
                user.last_checked_bot = timezone.now()
                user.state = self.NEXT_STATES[user.state]
                user.save(force_update=True)
                return user
            else:
                self.logger.info("New User start subX : \n{}".format(chat))
                username = chat.username
                last_name = chat.last_name
                first_name = chat.first_name
                new_user = User(chat_id=chat.id,
                                username=username,
                                first_name=first_name,
                                last_name=last_name,
                                chat_type=chat.type)
                new_user.save(force_insert=True)
                return user
        except Exception as e:
            self.logger.error("update_create_user : {}".format(e))

    def update_user_state(self, chat_id, user=None):
        if user is None:
            user = User.objects.filter(chat_id=chat_id).first()
            if not user:
                raise NotImplementedError(
                    "user {} not implemented".format(chat_id))
        user.state = self.NEXT_STATES[user.state]
        user.save(force_update=True)
        return user.state

    @staticmethod
    def get_user_state(chat_id):
        return User.filter.objects(chat_id=chat_id).first().state

    def set_states(self, states):
        self.STATES = states

    def set_next_states_dict(self, next_states):
        self.NEXT_STATES = next_states
示例#13
0
    def __input_topics(self) -> Init:

        if self.config_handler.has_topicer():
            self.__topicer: Optional[Topicer] = TopicerHandler(
                self.state_handler, self.config_handler).topicer()

            self.__topics: List[Topic] = self.__topicer.attach_or_create()
            self.state_handler.state.topics = []
            for topic in self.__topics:
                self.state_handler.state.topics.append(
                    DefaultTopic().with_number(topic.number))
        else:
            Log.info('No topicer found')
            self.state_handler.state.topics = None

        return self
示例#14
0
    def __init_develop(self) -> Init:
        version: str = '-'.join(
            [str(self.__state_handler.state.version), Level.DEV.value])

        self.__git.checkout_without_refresh_state(
            self.__config_handler.develop())

        self.__state_handler.write_file()
        UpdateSchemeVersion.from_state_handler(self.__state_handler)

        self.__git.add_all().commit(''.join([
            "'Init develop as branch name: ",
            self.__config_handler.develop(), " at version:", version, "'"
        ])).try_to_set_upstream()

        Log.info('Init develop as branch name: ' +
                 self.__config_handler.develop() + ' at version: ' + version)
        return self
示例#15
0
    def process(self):
        if self.action is IssueActions.READ:

            issuer_builder: issuer_builder = IssueBuilder(
                self.version_control, self.state_handler, self.config_handler,
                None, self.options)

            issue: Optional[
                AbstractIssue] = issuer_builder.find_issue_from_branch_name(
                ).issue()

            if issue is not None:
                Log.info('waiting... from github...')
                read_issue: Optional[AbstractIssue] = issuer_builder.issuer(
                ).read_issue_by_number(issue.number)
                if read_issue is not None:
                    pprint(read_issue.__dict__())

        elif self.action is IssueActions.COMMENT:
            raise NotImplementedError
示例#16
0
    def __attach(self) -> bool:
        if self.__would_attach_issue():
            issue_number = self.__number_issue()
            issue: IssueGithub = IssueGithub().with_number(issue_number)

            try:
                Log.info('waiting... from Github... Issue : ' +
                         str(issue_number))

                r: Response = self.__read_issue(issue)
                self.__issue: IssueGithub = IssueGithub.from_api_dict(r.json())
                CommonIssue.print_resume_issue(self.__issue)
            except FileNotFoundError:
                Log.error(Fg.FAIL.value + 'Issue not found : retry' +
                          Fg.RESET.value)
                return self.process()

            return True
        else:
            return False
示例#17
0
    def try_ensure_topic(self) -> TopicBuilder:

        if self.__config_handler.has_topicer() and self.__topicer is not None:
            if self.__state_handler.has_default_topic():

                Log.info('waiting for... default Topics...')
                self.__build_default()
                Log.info(str(len(self.__topics)) + ' Topics found')

                if self.__topics is not None:
                    for topic in self.__topics:
                        CommonTopic.print_resume_topic(topic)

                    if not self.__options.default:

                        use_default_topic: str = input(
                            'Use these topics ' + Fg.SUCCESS.value + 'y' + Fg.RESET.value + '/n : ')
                        if use_default_topic.lower() == 'n':
                            self.__topics = None
            else:
                Log.info('No default Topic found')

            if self.__topics is None and not self.__options.default:
                self.__topics: List[Topic] = self.__topicer.attach_or_create()

        return self
示例#18
0
    def __ensure_is_major(self, branch: Branch) -> Branch:
        if self.branch is Branches.RELEASE:
            if not self.version_control.is_current_branch_develop():
                raise NoBranchSelected('Checkout to develop branch before')
            is_major_b: bool = False

            if self.options.major is None and not self.options.default:
                if self.options.no_cli is not True:
                    is_major: str = input(' Is major Release Y/N : ' +
                                          Fg.SUCCESS.value + 'N' +
                                          Fg.RESET.value + ' ')
                    is_major_b = True if is_major.capitalize(
                    ) == 'Y' else False
                    self.options.major = is_major_b

            else:
                is_major_b = self.options.major is True
                if is_major_b:
                    Log.info('Release option Major set from options')

            branch.with_major(is_major=is_major_b)
        return branch
示例#19
0
    def process(self):

        if self.action is TopicActions.READ:
            topic_builder: TopicBuilder = TopicBuilder(self.version_control,
                                                       self.state_handler,
                                                       self.config_handler,
                                                       None, self.options)

            topics: Optional[List[
                AbstractTopic]] = topic_builder.find_topic_from_branch_name(
                ).topics()

            if topics is not None and len(topics) > 0:
                for topic in topics:
                    Log.info('waiting... from flexio...')

                    read_topic: Optional[
                        AbstractTopic] = topic_builder.topicer(
                        ).read_topic_by_number(int(topic.number))
                    if read_topic is not None:
                        CommonTopic.print_resume_topic(read_topic)
            else:
                Log.warning('No Topic found')
示例#20
0
 def ensure_master_branch(self) -> GitFlowCmd:
     Log.info('Ensure have Master branch : ' +
              self.__config_handler.master())
     if not self.__git.local_branch_exists(self.__config_handler.master()):
         if not self.__git.remote_branch_exists(
                 self.__config_handler.master()):
             Log.warning(self.__config_handler.master() + ' not exists')
             create: str = input('Create ' +
                                 self.__config_handler.master() +
                                 ' from current branch ?  y/' +
                                 Fg.SUCCESS.value + 'n' + Fg.RESET.value +
                                 ' : ')
             if create == 'y':
                 self.__git.create_branch_from(
                     self.__config_handler.master(),
                     self.__git.get_current_branch_name()
                 ).try_to_set_upstream().try_to_push()
                 self.ensure_master_branch()
             else:
                 raise BranchNotExist(self.__config_handler.master())
         else:
             Log.error('Remote branch : ' + self.__config_handler.master() +
                       ' already exists, pull before')
     return self
示例#21
0
 def init_head(self) -> GitCmd:
     self.__exec(['git', 'symbolic-ref', 'HEAD', '"refs/heads/' + Branches.MASTER.value + '"'])
     Log.info('init HEAD : ' + '"refs/heads/' + Branches.MASTER.value + '"')
     return self
示例#22
0
 def try_to_pull(self) -> GitCmd:
     Log.info('Try to pull from remote')
     if self.has_remote():
         return self.pull()
     return self
示例#23
0
 def set_upstream(self) -> GitCmd:
     self.__exec(["git", "push", "--set-upstream", GitConfig.REMOTE.value, self.get_current_branch_name()])
     Log.info('Set upstream for ' + self.get_current_branch_name())
     return self
示例#24
0
 def __post_issue(self, issue: IssueGithub) -> Response:
     Log.info('waiting... Github create issue')
     return self.__github.create_issue(issue)
示例#25
0
 def try_to_push_force(self) -> GitCmd:
     Log.info('Try to push forced to remote')
     if self.has_remote():
         return self.push_force()
     return self
示例#26
0
    def try_to_push_tag(self, tag: str) -> GitCmd:
        Log.info('Try to push tag to remote : ' + tag)

        if self.has_remote():
            return self.push_tag(tag)
        return self
示例#27
0
 def clean_workdir(cls):
     shutil.rmtree(cls.DIR_PATH_TEST, True)
     Log.info('clean workdir : ' + cls.DIR_PATH_TEST.as_posix())
示例#28
0
 def try_to_set_upstream(self) -> GitCmd:
     Log.info('Try to set upstream')
     if self.has_remote():
         return self.set_upstream()
     return self
示例#29
0
 def __ensure_stash_end(self):
     if self.options.auto_stash:
         self.version_control.stash_end()
         Log.info('Stashed work restored ')
示例#30
0
 def reset_to_tag(self, tag: str) -> GitCmd:
     self.__exec(['git', 'reset', '--hard', tag])
     Log.info('Reset to tag ' + tag)
     return self