<commit_before>'''
Created on May 17, 2014

@author: ignacio
'''
from trackers.base import IssueTracker


class Bitbucket(IssueTracker):

    def _get_issue_title(self, contents):
        div = contents.find(id='issue-view')
        issue_id = div.find('span', "issue-id").text
        title = div.find(id='issue-title').text
        return "{} {}".format(issue_id, title)

    @classmethod
    def from_remotes(cls, remotes):
        return cls._from_remotes(remotes, domain_has='bitbucket.org')

    def _get_issue_url(self, issue):
        return "{}/issue/{}".format(self._base_url, issue)<commit_msg>Implement issue list for bitbucket<commit_after>'''
Created on May 17, 2014

@author: ignacio
'''
from trackers.base import IssueTracker
import requests


class Bitbucket(IssueTracker):

    def _get_issue_title(self, contents):
        div = contents.find(id='issue-view')
        issue_id = div.find('span', "issue-id").text
        title = div.find(id='issue-title').text
        return "{} {}".format(issue_id, title)

    @classmethod
    def from_remotes(cls, remotes):
        return cls._from_remotes(remotes, domain_has='bitbucket.org')

    def _get_issue_url(self, issue):
        return "{}/issue/{}".format(self._base_url, issue)

    def get_issues(self):
        if not (self._repo_user and self._repo_name):
            raise ValueError("Could not parse repo and user from url '{}'"
                             .format(self._base_url))
        issues = _api_get("repositories/{}/{}/issues".format(self._repo_user,
                                                      self._repo_name))
        return {issue['local_id']: issue['title'] for issue in issues['issues']}


def _api_url(path):
    return "https://bitbucket.org/api/1.0/{}".format(path)

def _api_get(path):
    url = _api_url(path)
    response = requests.get(url)
    if not response.status_code == 200:
        raise ValueError("bitbucket api returned code {} != 200 for '{}'"
                         .format(response.status_code, url))
    return response.json()


{'fraction_non_alphanumeric': 0.13693957115009747, 'fraction_numerical': 0.009746588693957114, 'mean_word_length': 2.8590225563909772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2542455', 'n_tokens_mistral': 649, 'n_tokens_neox': 619, 'n_words': 137}