Sets a commit status indicator on github.

        If not running from a pull request (i.e. repository is None), then this
        just prints to stderr.

        Args:
            state: The state of the status indicator.
                Must be 'error', 'failure', 'pending', or 'success'.
            description: A summary of why the state is what it is,
                e.g. '5 lint errors' or 'tests passed!'.
            context: The name of the status indicator, e.g. 'pytest' or 'lint'.
            target_url: Optional location where additional details about the
                status can be found, e.g. an online test results page.

        Raises:
            ValueError: Not one of the allowed states.
            IOError: The HTTP post request failed, or the response didn't have
                a 201 code indicating success in the expected way.

def report_status_to_github(self,
                                state: str,
                                description: str,
                                context: str,
                                target_url: Optional[str] = None):
        """Sets a commit status indicator on github.

        If not running from a pull request (i.e. repository is None), then this
        just prints to stderr.

        Args:
            state: The state of the status indicator.
                Must be 'error', 'failure', 'pending', or 'success'.
            description: A summary of why the state is what it is,
                e.g. '5 lint errors' or 'tests passed!'.
            context: The name of the status indicator, e.g. 'pytest' or 'lint'.
            target_url: Optional location where additional details about the
                status can be found, e.g. an online test results page.

        Raises:
            ValueError: Not one of the allowed states.
            IOError: The HTTP post request failed, or the response didn't have
                a 201 code indicating success in the expected way.
        """
        if state not in ['error', 'failure', 'pending', 'success']:
            raise ValueError('Unrecognized state: {!r}'.format(state))

        if self.repository is None or self.repository.access_token is None:
            return

        print(repr(('report_status',
                    context,
                    state,
                    description,
                    target_url)), file=sys.stderr)

        payload = {
            'state': state,
            'description': description,
            'context': context,
        }
        if target_url is not None:
            payload['target_url'] = target_url

        url = (
            "https://api.github.com/repos/{}/{}/statuses/{}?access_token={}"
            .format(self.repository.organization,
                    self.repository.name,
                    self.actual_commit_id,
                    self.repository.access_token))

        response = requests.post(url, json=payload)

        if response.status_code != 201:
            raise IOError('Request failed. Code: {}. Content: {}.'.format(
                response.status_code, response.content))