# Buggy code
def issues(self):
    user = self.config.get("username")
    response = self.get_collection("/repositories/" + user + "/")
    repo_tags = list(
        filter(
            self.filter_repos,
            [repo["full_name"] for repo in response if repo.get("has_issues")],
        )
    )

    issues = sum([self.fetch_issues(repo) for repo in repo_tags], [])
    log.debug(" Found %i total.", len(issues))

    closed = ["resolved", "duplicate", "wontfix", "invalid", "closed"]
    try:
        issues = [tup for tup in issues if tup[1]["status"] not in closed]
    except KeyError:  # Undocumented API change.
        issues = [tup for tup in issues if tup[1]["state"] not in closed]
    issues = list(filter(self.include, issues))
    log.debug(" Pruned down to %i", len(issues))

    for tag, issue in issues:
        issue_obj = self.get_issue_for_record(issue)
        tagParts = tag.split("/")
        projectName = tagParts[1]
        if self.project_owner_prefix:
            projectName = tagParts[0] + "." + projectName
        url = issue["links"]["html"]["href"]
        extras = {
            "project": projectName,
            "url": url,
            "annotations": self.get_annotations(tag, issue, issue_obj, url),
        }
        issue_obj.update_extra(extras)
        yield issue_obj

    if not self.filter_merge_requests:
        pull_requests = sum([self.fetch_pull_requests(repo) for repo in repo_tags], [])
        log.debug(" Found %i total.", len(pull_requests))

        closed = ["rejected", "fulfilled"]
        not_resolved = lambda tup: tup[1]["state"] not in closed
        pull_requests = list(filter(not_resolved, pull_requests))
        pull_requests = list(filter(self.include, pull_requests))
        log.debug(" Pruned down to %i", len(pull_requests))

        for tag, issue in pull_requests:
            issue_obj = self.get_issue_for_record(issue)
            tagParts = tag.split("/")
            projectName = tagParts[1]
            if self.project_owner_prefix:
                projectName = tagParts[0] + "." + projectName
            url = self.BASE_URL + "/".join(
                issue["links"]["html"]["href"].split("/")[3:]
            ).replace("pullrequests", "pullrequest")
            extras = {
                "project": projectName,
                "url": url,
                "annotations": self.get_annotations2(tag, issue, issue_obj, url),
            }
            issue_obj.update_extra(extras)
            yield issue_obj


# Traceback (IOError)
ERROR:bugwarrior.services:Worker for [ELIDED] failed: Non-200 status code 410; u'https://api.bitbucket.org/1.0/repositories/[ELIDED]'; u'{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\\n\\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}'
Traceback (most recent call last):
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 499, in _aggregate_issues
for issue in service.issues():
File "/home/ELIDEDi/.local/lib/python2.7/site-packages/bugwarrior/services/bitbucket.py", line 233, in issues
'annotations': self.get_annotations(tag, issue, issue_obj, url)
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/bitbucket.py", line 177, in get_annotations
'/repositories/%s/issues/%i/comments' % (tag, issue['id']))
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/bitbucket.py", line 144, in get_data
return self.json_response(requests.get(url, **self.requests_kwargs))
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 478, in json_response
response.status_code, response.url, response.text,
IOError: Non-200 status code 410; u'https://api.bitbucket.org/1.0/repositories/ELIDED'; u'{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\\n\\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}'

# Fixed code
def issues(self):
    user = self.config.get("username")
    response = self.get_collection("/repositories/" + user + "/")
    repo_tags = list(
        filter(
            self.filter_repos,
            [repo["full_name"] for repo in response if repo.get("has_issues")],
        )
    )

    issues = sum([self.fetch_issues(repo) for repo in repo_tags], [])
    log.debug(" Found %i total.", len(issues))

    closed = ["resolved", "duplicate", "wontfix", "invalid", "closed"]
    try:
        issues = [tup for tup in issues if tup[1]["status"] not in closed]
    except KeyError:  # Undocumented API change.
        issues = [tup for tup in issues if tup[1]["state"] not in closed]
    issues = list(filter(self.include, issues))
    log.debug(" Pruned down to %i", len(issues))

    for tag, issue in issues:
        issue_obj = self.get_issue_for_record(issue)
        tagParts = tag.split("/")
        projectName = tagParts[1]
        if self.project_owner_prefix:
            projectName = tagParts[0] + "." + projectName
        url = issue["links"]["html"]["href"]
        extras = {
            "project": projectName,
            "url": url,
            "annotations": self.get_annotations(tag, issue, issue_obj, url),
        }
        issue_obj.update_extra(extras)
        yield issue_obj

    if not self.filter_merge_requests:
        pull_requests = sum([self.fetch_pull_requests(repo) for repo in repo_tags], [])
        log.debug(" Found %i total.", len(pull_requests))

        closed = ["rejected", "fulfilled"]
        not_resolved = lambda tup: tup[1]["state"] not in closed
        pull_requests = list(filter(not_resolved, pull_requests))
        pull_requests = list(filter(self.include, pull_requests))
        log.debug(" Pruned down to %i", len(pull_requests))

        for tag, issue in pull_requests:
            issue_obj = self.get_issue_for_record(issue)
            tagParts = tag.split("/")
            projectName = tagParts[1]
            if self.project_owner_prefix:
                projectName = tagParts[0] + "." + projectName
            url = self.BASE_URL + "/".join(
                issue["links"]["html"]["href"].split("/")[3:]
            ).replace("pullrequests", "pullrequest")
            extras = {
                "project": projectName,
                "url": url,
                "annotations": self.get_annotations(tag, issue, issue_obj, url),
            }
            issue_obj.update_extra(extras)
            yield issue_obj