<commit_before># -*- coding: utf-8 -*-
"""This module contains all the classes relating to Checks."""
from __future__ import unicode_literals

from json import dumps

from . import models
from . import pulls
from .decorators import requires_auth


class CheckSuite(models.GitHubCore):
    """The :class:`CheckSuite <CheckSuite>` object.

    .. versionadded:: 1.2.0

    Please see GitHub's `CheckSuite Documentation`_ for more information.

    .. attribute:: status

        The status of the Check Suite

    .. attribute:: conclusion

        The highest priority check run conclusion. If it has not completed this
        will be None

    .. attribute:: head_sha

        The sha of the commit at the head of the branch checked

    .. attribute:: head_branch

        The branch checked

    .. attribute:: before

        The sha of the target branch before the change

    .. attribute:: after

        The sha of the target branch after the change is applied

    .. attribute:: repository

        A representation of the repository the suite belongs to as
        :class:`~github3.repos.repo.ShortRepository`.

    .. attribute:: pull_requests

        A list of representations of the pull requests the suite belongs to as
        :class:`~github3.pulls.ShortPullRequest`. This may be empty.

    .. attribute:: id

        The unique GitHub assigned numerical id of this check suite.

    .. CheckSuite Documentation:
        http://developer.github.com/v3/checks/suites/
    """

    class_name = 'CheckSuite'
    CUSTOM_HEADERS = {
        'Accept': 'application/vnd.github.antiope-preview+json'
    }

    def _update_attributes(self, suite):
        # Import here, because a toplevel import causes an import loop
        from .repos import ShortRepository
        self._api = suite['url']
        #self.base = Base(pull['base'], self)
        self.status = suite['status']
        self.conclusion = suite['conclusion']
        self.head_branch = suite['head_branch']
        self.head_sha = suite['head_sha']
        self.before = suite['before']
        self.after = suite['after']
        pull_requests = suite.get('pull_requests', [])
        self.pull_requests = [
            pulls.ShortPullRequest(p, self) for p in pull_requests
        ]
        self.repository = ShortRepository(suite['repository'], self)
        self.id = suite['id']

    def _repr(self):
        return '<{0} [{1}]>'.format(self.class_name, self.id)
        # FIXME(omgjlk): This could be more descriptive perhaps

    @requires_auth
    def rerequest(self):
        """Rerequest the check suite.

        :returns:
            True if successful, False otherwise
        :rtype:
            bool
        """

        url = self._build_url('rerequest', base_url=self._api)
        return self._boolean(self._post(
            url, headers=CheckSuite.CUSTOM_HEADERS), 201, 404)

    @requires_auth
    def check_runs(self):
        """Retrieve the check runs for this suite.

        :returns:
            the check runs for this commit
        :rtype:
            :class:`~github3.checks.CheckRun`
        """
        url = self._build_url('check-runs', base_url=self._api)
        return self._iter(-1, url, CheckRun)


class CheckRun(models.GitHubCore):
    """The :class:`CheckRun <CheckRun>` object.

    .. versionadded:: 1.2.0

    Please see GitHub's `CheckRun Documentation`_ for more information.

    .. attribute:: status

        The current status of the check.

    .. attribute:: conclusion

        The final conclusion of the check. If the run has not concluded
        this will be None.

    .. attribute:: head_sha

        The sha of the commit at the head of the branch checked.

    .. attribute:: name

        The name of the check.

    .. attribute:: started_at

        A :class:`~datetime.datetime` object representing the date and time
        when this check run started.

    .. attribute:: completed_at

        A :class:`~datetime.datetime` object representing the date and time
        when this check run completed. If this run is not completed it will
        be ``None``.

    .. attribute:: pull_requests

        A list of representations of the pull requests the check run belongs to as
        :class:`~github3.pulls.ShortPullRequest` (this may be empty).

    .. attribute:: id

        The unique GitHub assigned numerical id of this check run.

    .. attribute:: external_id

        A reference for the run on the integrator's system. This may be None.

    .. attribute:: html_url

        The URL one would use to view this check run in the browser.

    .. attribute:: check_suite

        The ID of the check suite this run belongs to.

    .. attribute:: output

        A :class:`~github3.checks.CheckRunOutput` representing the output
        of this check run. (TODO: Implement this object)

    .. attribute:: app

        A :class:`~github3.apps.App` representing the App
        this run belongs to. (TODO: Implement this)

    .. CheckRun Documentation:
        http://developer.github.com/v3/checks/runs/
    """

    class_name = 'CheckRun'
    CUSTOM_HEADERS = {
        'Accept': 'application/vnd.github.antiope-preview+json'
    }

    def _update_attributes(self, run):
        self._api = run['url']
        self.html_url = run['html_url']
        self.status = run['status']
        self.conclusion = run['conclusion']
        self.started_at = self._strptime(run['created_at'])
        self.completed_at = self._strptime(run['completed_at'])
        self.head_sha = run['head_sha']
        self.name = run['name']
        pull_requests = run.get('pull_requests', [])
        self.pull_requests = [
            pulls.ShortPullRequest(p, self) for p in pull_requests<commit_msg>Move another import to avoid circular issues<commit_after># -*- coding: utf-8 -*-
"""This module contains all the classes relating to Checks."""
from __future__ import unicode_literals

from json import dumps

from . import models
from .decorators import requires_auth


class CheckSuite(models.GitHubCore):
    """The :class:`CheckSuite <CheckSuite>` object.

    .. versionadded:: 1.2.0

    Please see GitHub's `CheckSuite Documentation`_ for more information.

    .. attribute:: status

        The status of the Check Suite

    .. attribute:: conclusion

        The highest priority check run conclusion. If it has not completed this
        will be None

    .. attribute:: head_sha

        The sha of the commit at the head of the branch checked

    .. attribute:: head_branch

        The branch checked

    .. attribute:: before

        The sha of the target branch before the change

    .. attribute:: after

        The sha of the target branch after the change is applied

    .. attribute:: repository

        A representation of the repository the suite belongs to as
        :class:`~github3.repos.repo.ShortRepository`.

    .. attribute:: pull_requests

        A list of representations of the pull requests the suite belongs to as
        :class:`~github3.pulls.ShortPullRequest`. This may be empty.

    .. attribute:: id

        The unique GitHub assigned numerical id of this check suite.

    .. CheckSuite Documentation:
        http://developer.github.com/v3/checks/suites/
    """

    class_name = 'CheckSuite'
    CUSTOM_HEADERS = {
        'Accept': 'application/vnd.github.antiope-preview+json'
    }

    def _update_attributes(self, suite):
        # Import here, because a toplevel import causes an import loop
        from . import pulls
        from .repos import ShortRepository
        self._api = suite['url']
        #self.base = Base(pull['base'], self)
        self.status = suite['status']
        self.conclusion = suite['conclusion']
        self.head_branch = suite['head_branch']
        self.head_sha = suite['head_sha']
        self.before = suite['before']
        self.after = suite['after']
        pull_requests = suite.get('pull_requests', [])
        self.pull_requests = [
            pulls.ShortPullRequest(p, self) for p in pull_requests
        ]
        self.repository = ShortRepository(suite['repository'], self)
        self.id = suite['id']

    def _repr(self):
        return '<{0} [{1}]>'.format(self.class_name, self.id)
        # FIXME(omgjlk): This could be more descriptive perhaps

    @requires_auth
    def rerequest(self):
        """Rerequest the check suite.

        :returns:
            True if successful, False otherwise
        :rtype:
            bool
        """

        url = self._build_url('rerequest', base_url=self._api)
        return self._boolean(self._post(
            url, headers=CheckSuite.CUSTOM_HEADERS), 201, 404)

    @requires_auth
    def check_runs(self):
        """Retrieve the check runs for this suite.

        :returns:
            the check runs for this commit
        :rtype:
            :class:`~github3.checks.CheckRun`
        """
        url = self._build_url('check-runs', base_url=self._api)
        return self._iter(-1, url, CheckRun)


class CheckRun(models.GitHubCore):
    """The :class:`CheckRun <CheckRun>` object.

    .. versionadded:: 1.2.0

    Please see GitHub's `CheckRun Documentation`_ for more information.

    .. attribute:: status

        The current status of the check.

    .. attribute:: conclusion

        The final conclusion of the check. If the run has not concluded
        this will be None.

    .. attribute:: head_sha

        The sha of the commit at the head of the branch checked.

    .. attribute:: name

        The name of the check.

    .. attribute:: started_at

        A :class:`~datetime.datetime` object representing the date and time
        when this check run started.

    .. attribute:: completed_at

        A :class:`~datetime.datetime` object representing the date and time
        when this check run completed. If this run is not completed it will
        be ``None``.

    .. attribute:: pull_requests

        A list of representations of the pull requests the check run belongs to as
        :class:`~github3.pulls.ShortPullRequest` (this may be empty).

    .. attribute:: id

        The unique GitHub assigned numerical id of this check run.

    .. attribute:: external_id

        A reference for the run on the integrator's system. This may be None.

    .. attribute:: html_url

        The URL one would use to view this check run in the browser.

    .. attribute:: check_suite

        The ID of the check suite this run belongs to.

    .. attribute:: output

        A :class:`~github3.checks.CheckRunOutput` representing the output
        of this check run. (TODO: Implement this object)

    .. attribute:: app

        A :class:`~github3.apps.App` representing the App
        this run belongs to. (TODO: Implement this)

    .. CheckRun Documentation:
        http://developer.github.com/v3/checks/runs/
    """

    class_name = 'CheckRun'
    CUSTOM_HEADERS = {
        'Accept': 'application/vnd.github.antiope-preview+json'
    }

    def _update_attributes(self, run):
        # Import here, because a toplevel import causes an import loop
        from . import pulls
        self._api = run['url']
        self.html_url = run['html_url']
        self.status = run['status']
        self.conclusion = run['conclusion']
        self.started_at = self._strptime(run['created_at'])
        self.completed_at = self._strptime(run['completed_at'])
        self.head_sha = run['head_sha']
        self.name = run['name']
        pull_requests = run.get('pull_requests', [])
        self.pull_requests = [
            pulls.ShortPullRequest(p, self) for p in pull_requests
{'fraction_non_alphanumeric': 0.09733218588640276, 'fraction_numerical': 0.004130808950086058, 'mean_word_length': 2.379179994184356, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '6235655', 'n_tokens_mistral': 3284, 'n_tokens_neox': 3079, 'n_words': 1060}