<commit_before>import requests
import json

from gitcd.Git.Command import Command
from gitcd.Exceptions import GitcdGithubApiException

from pprint import pprint
import sys


class Status(Command):

    def execute(self, branch: str):
        featureBranch = self.getFeatureBranch(branch)
        self.interface.header("see status for branch %s" % featureBranch)

        origin = self.getOrigin()
        master = self.config.getMaster()
        repo = self.getRepository(origin)
        username = self.getUsername(origin)
        token = self.getTokenOrAskFor()
        ref = "%s:refs/heads/%s" % (username, featureBranch)
        # claudio-walser:refs/heads/implement-status
        if isinstance(token, str):
            url = "https://api.github.com/repos/%s/%s/pulls" % (username, repo)

            data = {
                "state": 'open',
                "head": ref,
                "base": master
            }

            self.interface.warning("Fetch pull-request infos on %s" % (url))

            headers = {'Authorization': 'token %s' % token}
            response = requests.get(
                url,
                headers=headers,
                params=data
            )

            if response.status_code != 200:
                raise GitcdGithubApiException(
                    "Could not fetch open pull requests," +
                    " please have a look manually."
                )

            result = response.json()

            if len(result) == 1:
                reviewedBy = self.isReviewedBy(
                    result[0]['comments_url']
                )
                self.interface.ok("Pull Request Info")
                self.interface.info("Branches: %s...%s" % (
                    featureBranch,
                    master)
                )
                self.interface.info("Number:   %s" % (result[0]['number']))
                self.interface.info("Reviewd by: %s" % (reviewedBy))
                self.interface.info("URL: %s" % (result[0]['html_url']))

                # if not reviewed yet
                if reviewedBy is '':
                    reviewPullRequest = self.interface.askFor(
                        "Do you want to review this pull \
                        request in your Browser?", [
                            "yes",
                            "no"
                        ], "yes"
                    )

                    if reviewPullRequest == "yes":
                        # delete feature branch remote and locally
                        defaultBrowser = self.getDefaultBrowserCommand()
                        self.cli.execute("%s %s" % (
                            defaultBrowser,
                            "%s/files" % (result[0]['html_url'])
                        ))
            else:
                self.interface.info(
                    "No pull request exists for %s...%s" % (
                        featureBranch,
                        master<commit_msg>just output it without color<commit_after>import requests
import json

from gitcd.Git.Command import Command
from gitcd.Exceptions import GitcdGithubApiException

from pprint import pprint
import sys


class Status(Command):

    def execute(self, branch: str):
        featureBranch = self.getFeatureBranch(branch)
        self.interface.header("see status for branch %s" % featureBranch)

        origin = self.getOrigin()
        master = self.config.getMaster()
        repo = self.getRepository(origin)
        username = self.getUsername(origin)
        token = self.getTokenOrAskFor()
        ref = "%s:refs/heads/%s" % (username, featureBranch)
        # claudio-walser:refs/heads/implement-status
        if isinstance(token, str):
            url = "https://api.github.com/repos/%s/%s/pulls" % (username, repo)

            data = {
                "state": 'open',
                "head": ref,
                "base": master
            }

            self.interface.warning("Fetch pull-request infos on %s" % (url))

            headers = {'Authorization': 'token %s' % token}
            response = requests.get(
                url,
                headers=headers,
                params=data
            )

            if response.status_code != 200:
                raise GitcdGithubApiException(
                    "Could not fetch open pull requests," +
                    " please have a look manually."
                )

            result = response.json()

            if len(result) == 1:
                reviewedBy = self.isReviewedBy(
                    result[0]['comments_url']
                )
                self.interface.ok("Pull Request Info")
                self.interface.writeOut("Branches: %s...%s" % (
                    featureBranch,
                    master)
                )
                self.interface.writeOut("Number:   %s" % (result[0]['number']))
                self.interface.writeOut("Reviewd by: %s" % (reviewedBy))
                self.interface.writeOut("URL: %s" % (result[0]['html_url']))

                # if not reviewed yet
                if reviewedBy is '':
                    reviewPullRequest = self.interface.askFor(
                        "Do you want to review this pull \
                        request in your Browser?", [
                            "yes",
                            "no"
                        ], "yes"
                    )

                    if reviewPullRequest == "yes":
                        # delete feature branch remote and locally
                        defaultBrowser = self.getDefaultBrowserCommand()
                        self.cli.execute("%s %s" % (
                            defaultBrowser,
                            "%s/files" % (result[0]['html_url'])
                        ))
            else:
                self.interface.writeOut(
                    "No pull request exists for %s...%s" % (
                        featureBranch,
                        master
{'fraction_non_alphanumeric': 0.1018596079745351, 'fraction_numerical': 0.002680515999329871, 'mean_word_length': 1.2587968217934167, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7529910', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1407, 'n_words': 337}