Ejemplo n.º 1
0
 def read_issue_by_number(self, number: int) -> Issue:
     repo: Repo = GitCmd(self.state_handler, self.options.debug).get_repo()
     # repo: Repo = Repo(owner='flexiooss', repo='flexio-flow-punching-ball')
     resp: Response = Github(
         self.config_handler).with_repo(repo).read_issue(
             IssueGithub().with_number(number))
     return IssueGithub.from_api_dict(resp.json())
Ejemplo n.º 2
0
    def test_read_issue(self):
        issue: IssueGithub = IssueGithub().with_number(5)

        r: Response = self.github_repo.read_issue(issue)
        print(r.status_code)
        print(r.content)
        print(r.json())
        self.assertIs(r.status_code, 200)

        issue_read: IssueGithub = IssueGithub.from_api_dict(r.json())
        print(issue_read.__dict__())
Ejemplo n.º 3
0
    def test_should_start_hotfix_with_issue(self):
        issue_created: IssueGithub = IssueGithub().with_number(ISSUE_NUMBER)

        self.assertIs(
            self.git.remote_branch_exists('hotfix/0.0.1-dev' +
                                          issue_created.get_ref()), False)
        self.assertIs(
            self.git.local_branch_exists('hotfix/0.0.1-dev' +
                                         issue_created.get_ref()), False)

        self.__hotfix_start(issue_created)

        self.assertIs(
            self.git.remote_branch_exists('hotfix/0.0.1-dev' +
                                          issue_created.get_ref()), True)
        self.assertIs(
            self.git.local_branch_exists('hotfix/0.0.1-dev' +
                                         issue_created.get_ref()), True)

        state_master: State = self.__get_master_state()
        self.assertEqual('0.0.0', str(state_master.version))
        self.assertEqual(Level.STABLE, state_master.level)

        state_dev: State = self.__get_dev_state()
        self.assertEqual('0.1.0', str(state_dev.version))
        self.assertEqual(Level.DEV, state_dev.level)

        state_hotfix: State = self.__get_hotfix_state()
        self.assertEqual('0.0.1', str(state_hotfix.version))
        self.assertEqual(Level.DEV, state_hotfix.level)
        with self.assertRaises(BranchAlreadyExist):
            self.__hotfix_start()
Ejemplo n.º 4
0
    def __post_issue(self, issue: IssueGithub) -> IssueGithub:
        r: Response = self.github.create_issue(issue)

        if r.status_code == 201:
            issue_created: Dict[str, str] = r.json()
            return issue.with_number(int(issue_created.get('number')))
        else:
            raise GithubRequestApiError(r)
Ejemplo n.º 5
0
 def comment(self, issue: IssueGithub, text: str) -> Issue:
     repo: Repo = GitCmd(self.state_handler,
                         self.options.debug).with_config_handler(
                             self.config_handler).get_repo()
     resp: Response = Github(
         self.config_handler).with_repo(repo).create_comment(issue=issue,
                                                             body=text)
     return IssueGithub.from_api_dict(resp.json())
Ejemplo n.º 6
0
    def test_create_issue_comment(self):
        issue: IssueGithub = IssueGithub()
        issue.title = 'issue test ' + str(int(time.time()))
        issue.body = 'test description'
        issue.assign(USER)
        issue.label('bug')

        r: Response = self.github_repo.create_issue(issue)

        issue_created: IssueGithub = IssueGithub()
        issue_created.number = r.json().get('number')

        r: Response = self.github_repo.create_comment(issue_created,
                                                      body='super commentaire')
        print(r.status_code)
        print(r.content)
        print(r.json())
        self.assertIs(r.status_code, 201)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def tearDown(self):
        TestGitFlowHelper.clean_workdir()
        TestGitFlowHelper.init_repo(INIT_VERSION)
        self.git.delete_branch_from_name(
            'hotfix/0.0.1-dev', remote=True).delete_tag(
                '0.0.1', remote=True).delete_branch_from_name(
                    'hotfix/0.0.1-dev' +
                    IssueGithub().with_number(ISSUE_NUMBER).get_ref(),
                    remote=True)

        TestGitFlowHelper.clean_remote_repo()
        TestGitFlowHelper.clean_workdir()
Ejemplo n.º 9
0
    def test_create_issue(self):
        issue: IssueGithub = IssueGithub()
        issue.title = 'issue test ' + str(int(time.time()))
        issue.body = 'test description'
        issue.assign(USER)
        issue.label('bug')

        r: Response = self.github_repo.create_issue(issue)
        print(r.status_code)
        print(r.content)
        print(r.json())
        self.assertIs(r.status_code, 201)
Ejemplo n.º 10
0
    def test_should_finish_release_with_issue(self):
        issue_created: IssueGithub = IssueGithub().with_number(ISSUE_NUMBER)
        with self.assertRaises(BranchNotExist):
            self.__release_finish()

        self.__release_start(issue_created)
        self.__release_finish(issue_created)

        state_master: State = self.__get_master_state()
        self.assertEqual('0.1.0', str(state_master.version))
        self.assertEqual(Level.STABLE, state_master.level)
        self.assertIs(
            self.git.remote_branch_exists(
                'release/0.1.0' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()), False)

        self.assertIs(self.git.tag_exists('0.1.0'), True,
                      'Tag should be 0.1.0')

        state_dev: State = self.__get_dev_state()
        self.assertEqual('0.2.0', str(state_dev.version))
        self.assertEqual(Level.DEV, state_dev.level)
Ejemplo n.º 11
0
    def tearDown(self):
        print('tearDown')
        TestGitFlowHelper.clean_workdir()
        TestGitFlowHelper.init_repo(INIT_VERSION)

        self.git.delete_remote_branch_from_name(
            'release/' + INIT_VERSION).delete_remote_branch_from_name(
                'release/' + INIT_VERSION +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()).delete_tag(
                    INIT_VERSION, remote=True)

        TestGitFlowHelper.clean_remote_repo(Version.from_str(INIT_VERSION))
        TestGitFlowHelper.clean_workdir()
Ejemplo n.º 12
0
    def tearDown(self):
        TestGitFlowHelper.clean_workdir()
        TestGitFlowHelper.init_repo(INIT_VERSION)

        self.git.delete_branch_from_name(
            'feature/' + slugify(FEATURE_NAME) + '-0.1.0-dev',
            True).delete_branch_from_name(
                'feature/' + slugify(FEATURE_NAME) + '-0.1.0-dev' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref(),
                True).delete_branch_from_name(
                    'release/ma-super-nouvelle-feature-accentue-0.1.0-dev',
                    True)

        TestGitFlowHelper.clean_remote_repo()
        TestGitFlowHelper.clean_workdir()
Ejemplo n.º 13
0
    def test_should_finish_release_with_issue(self):
        issue_created: IssueGithub = IssueGithub().with_number(ISSUE_NUMBER)

        with self.assertRaises(BranchNotExist):
            self.__feature_finish()

        self.__feature_start(issue_created)
        self.__feature_finish(issue_created)

        self.__feature_start()
        self.__feature_finish()

        state_master: State = self.__get_master_state()
        self.assertEqual('0.0.0', str(state_master.version))
        self.assertEqual(Level.STABLE, state_master.level)
        self.assertFalse(
            self.git.remote_branch_exists(
                'feature/' + slugify(FEATURE_NAME) + '-0.1.0-dev' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()))

        state_dev: State = self.__get_dev_state()

        self.assertEqual('0.1.0', str(state_dev.version))
        self.assertEqual(Level.DEV, state_dev.level)
Ejemplo n.º 14
0
    def test_should_start_release_with_issue(self):
        issue_created: IssueGithub = IssueGithub().with_number(ISSUE_NUMBER)

        self.assertIs(
            self.git.remote_branch_exists(
                'release/0.1.0' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()), False)
        self.assertIs(
            self.git.local_branch_exists(
                'release/0.1.0' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()), False)

        self.__release_start(issue_created)

        self.assertIs(
            self.git.local_branch_exists(
                'release/0.1.0' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()), True)
        self.assertIs(
            self.git.remote_branch_exists(
                'release/0.1.0' +
                IssueGithub().with_number(ISSUE_NUMBER).get_ref()), True)

        state_master: State = self.__get_master_state()
        self.assertEqual('0.0.0', INIT_VERSION)
        self.assertEqual(Level.STABLE, state_master.level)

        state_dev: State = self.__get_dev_state()
        self.assertEqual('0.1.0', str(state_dev.version))
        self.assertEqual(Level.DEV, state_dev.level)

        state_release: State = self.__get_release_state()
        self.assertEqual('0.1.0', str(state_release.version))
        self.assertEqual(Level.STABLE, state_release.level)
        with self.assertRaises(BranchAlreadyExist):
            self.__release_start()
Ejemplo n.º 15
0
    def process(self) -> Issue:
        # self.__start_message()

        self.__start_message_issue()

        issue: IssueGithub = self.__input_issue()

        r: Response = self.__post_issue(issue)

        if r.status_code == 201:
            issue_created: IssueGithub = IssueGithub.from_api_dict(r.json())

            self.__resume_issue_created(issue_created)
        else:
            raise GithubRequestApiError(r)

        return issue_created
Ejemplo n.º 16
0
    def __input_milestone(self, issue: IssueGithub) -> Create:

        milestone: str = input("""Milestone number : 
{bg_help}`-l` to list the existing 
`-c` to create milestone{reset_bg}""".format(reset_bg=Fg.RESET.value,
                                             bg_help=Fg.NOTICE.value))

        if milestone == '-c':
            r1: Response = self.__github.get_open_milestones()
            milestones_repo: List[str] = []
            if r1.status_code == 200:
                milestones_response: List[Dict[str, str]] = r1.json()
                l: Dict[str, str]
                for l in milestones_response:
                    milestones_repo.append('{number!s} : {title!s}'.format(
                        number=l.get('number'), title=l.get('title')))

            if len(milestones_repo):
                message: str = """{fg_cyan}{milestones!s}{fg_reset}

Choose number : 
""".format(fg_cyan=Fg.NOTICE.value,
                milestones=' | '.join(milestones_repo),
                fg_reset=Fg.RESET.value)
            else:
                message: str = Fg.FAIL.value + 'No milestone, type `-c` to create milestone or `-a` for abort' + Fg.RESET.value

            milestone: str = input(message)

        if milestone == '-c':
            milestone_inst: Milestone = self.__create_milestone()
            r2: Response = self.__github.create_milestone(milestone_inst)
            if r2.status_code == 201:
                milestone_created: Dict[str, str] = r2.json()
                milestone = milestone_created.get('number')
                self.__resume_milestone(milestone_created)

        milestone = milestone if not milestone == '-a' else ''

        if milestone:
            issue.milestone = int(milestone)
        return self
Ejemplo n.º 17
0
    def __input_assignees(self, issue: IssueGithub) -> Create:
        if self.__options.default:
            assignees: List[str] = self.__default_issue.assignees
        else:
            message: str = """ Assignees {default}
{bg_help}separator `;`{reset_bg}
{bg_help}`-l` to list users{reset_bg}
""".format(default=Fg.SUCCESS.value +
            ';'.join(self.__default_issue.assignees) + Fg.RESET.value +
            ' :' if len(self.__default_issue.assignees) else '',
            reset_bg=Fg.RESET.value,
            bg_help=Fg.NOTICE.value)

            assignees: str = input(message)
            assignees = assignees if assignees else self.__config_handler.config.github.user
            if assignees == '-l':
                r: Response = self.__github.get_users()
                members: List[str] = []
                if r.status_code == 200:
                    members_response: List[Dict[str, str]] = r.json()
                    l: Dict[str, str]
                    for l in members_response:
                        members.append(
                            '{login!s}'.format(login=l.get('login')))
                if len(members):
                    message: str = """{fg_cyan}{members!s} {reset_fg}
    
Choose pseudo :
""".format(fg_cyan=Fg.NOTICE.value,
                    members=' | '.join(members),
                    reset_fg=Fg.RESET.value)
                else:
                    message: str = Fg.FAIL.value + 'No member, type `abort`' + Fg.RESET.value
                assignees: str = input(message)

            assignees: List[str] = assignees.split(';')
            assignees = self.__sanitize_list_input(assignees)

        if len(assignees):
            issue.assignees = assignees
        return self
Ejemplo n.º 18
0
    def __input_labels(self, issue: IssueGithub) -> Create:
        labels_lst: List[str]

        if self.__options.default:
            labels_lst = self.__default_issue.labels
        else:
            message: str = 'Labels '
            r: Response = self.__github.get_labels()

            labels_repo: List[str] = []
            if r.status_code == 200:
                labels_response: List[Dict[str, str]] = r.json()
                l: Dict[str, str]
                for l in labels_response:
                    labels_repo.append(l.get('name'))

            default: str = ';'.join(self.__default_issue.labels) if len(
                self.__default_issue.assignees) else ''

            if len(labels_repo):
                message += """
{fg_cyan}{labels!s}{fg_reset}

Choose label : {fg_green}{default}{fg_reset}
{fg_cyan}separator `;` {fg_reset}
""".format(fg_cyan=Fg.NOTICE.value,
                labels=' | '.join(labels_repo),
                fg_reset=Fg.RESET.value,
                fg_green=Fg.SUCCESS.value,
                default=default)

            labels: str = input(message)
            labels = labels if len(labels) > 0 else default
            labels_lst = labels.split(';')
            labels_lst = self.__sanitize_list_input(labels_lst)

        if len(labels_lst):
            issue.labels = labels_lst
        return self
Ejemplo n.º 19
0
    def __input_issue(self):
        issue: IssueGithub = IssueGithub()
        title: str = ''

        title_default: str = Fg.SUCCESS.value + self.__default_issue.title + Fg.RESET.value if self.__default_issue.title is not None else ''
        if self.__options.default and self.__default_issue.title is not None:
            title = self.__default_issue.title
        else:
            while not len(title) > 0:

                title = input(Fg.FAIL.value + '[required]' + Fg.RESET.value +
                              ' Issue Title : ' + title_default)
                title = title if title else self.__default_issue.title

        issue.title = title

        if not self.__options.default:
            body: str = input('Description : ')
            if body:
                issue.body = body

        self.__input_assignees(issue).__input_labels(issue)

        return issue
Ejemplo n.º 20
0
 def create_issue(self, issue: IssueGithub) -> Response:
     url: str = '/'.join([self.__repo_base_url(), 'issues'])
     return requests.post(url,
                          json=issue.__dict__(),
                          headers=self.__auth({}))
Ejemplo n.º 21
0
 def issue_builder(self) -> Issue:
     return IssueGithub()