<commit_before># -*- coding: utf-8 -*- 
from django.db import models
from django.utils.functional import lazy
from django.core.cache import cache
from django.conf import settings
from yats.models import tickets, organisation
from yats.models import base

import base64
import httplib2
try:
    import json
except ImportError:
    from django.utils import simplejson as json

class ticket_component(base):
    name = models.CharField(max_length=255)

    def __unicode__(self):
        return self.name

def getGibthubTags():
    owner = settings.GITHUB_OWNER
    repo = settings.GITHUB_REPO
    user = settings.GITHUB_USER
    password = settings.GITHUB_PASS
    
    if not owner or not repo:
        return []

    cache_name = 'yats.%s.%s.tags.github' % (owner, repo)
    tags = cache.get(cache_name)
    if tags:
        return tags
    
    # https://developer.github.com/v3/repos/#list-tags
    result = []
    headers = {
               'Accept': 'application/vnd.github.v3+json',
               'User-Agent': 'yats'
               }
    if user:
        headers['Authorization'] = 'Basic %s' % base64.b64encode('%s:%s' % (user, password))
    
    h = httplib2.Http()
    header, content = h.request('https://api.github.com/repos/%s/%s/tags' % (owner, repo), 'GET', headers=headers)
    if header['status'] != '200':
        raise Exception(content)
    
    tags = json.loads(content)
    
    for tag in tags:
        result.append((tag['name'], tag['name'],))
    
    cache.set(cache_name, result, 60 * 10)
    return reversed(sorted(result))

class test(tickets):
    component = models.ForeignKey(ticket_component)
    version = models.CharField(max_length=255, choices=lazy(getGibthubTags, list)())
    keywords = models.CharField(max_length=255, blank=True)
    reproduction = models.TextField(null=True)
    billing_needed = models.NullBooleanField(default=None)
    billing_reason = models.TextField(null=True, blank=True)
    billing_done = models.NullBooleanField(default=None)
    solution = models.TextField(null=True, blank=True)
    fixed_in_version = models.CharField(max_length=255, choices=lazy(getGibthubTags, list)(), blank=True)
    deadline = models.DateField(null=True, blank=True)<commit_msg>= try/except and always return an array...<commit_after># -*- coding: utf-8 -*- 
from django.db import models
from django.utils.functional import lazy
from django.core.cache import cache
from django.conf import settings
from yats.models import tickets, organisation
from yats.models import base

import base64
import httplib2
try:
    import json
except ImportError:
    from django.utils import simplejson as json

class ticket_component(base):
    name = models.CharField(max_length=255)

    def __unicode__(self):
        return self.name

def getGibthubTags():
    owner = settings.GITHUB_OWNER
    repo = settings.GITHUB_REPO
    user = settings.GITHUB_USER
    password = <PASSWORD>
    
    if not owner or not repo:
        return []

    cache_name = 'yats.%s.%s.tags.github' % (owner, repo)
    tags = cache.get(cache_name)
    if tags:
        return tags
    
    # https://developer.github.com/v3/repos/#list-tags
    result = []
    headers = {
               'Accept': 'application/vnd.github.v3+json',
               'User-Agent': 'yats'
               }
    if user:
        headers['Authorization'] = 'Basic %s' % base64.b64encode('%s:%s' % (user, password))
    
    try:
        h = httplib2.Http()
        header, content = h.request('https://api.github.com/repos/%s/%s/tags' % (owner, repo), 'GET', headers=headers)
        if header['status'] != '200':
            print 'ERROR fetching data from GitHub: %s' % content
            return []
    
    except:
        print 'ERROR fetching data from GitHub'
        return [] 
    
    tags = json.loads(content)
    
    for tag in tags:
        result.append((tag['name'], tag['name'],))
    
    cache.set(cache_name, result, 60 * 10)
    return reversed(sorted(result))

class test(tickets):
    component = models.ForeignKey(ticket_component)
    version = models.CharField(max_length=255, choices=lazy(getGibthubTags, list)())
    keywords = models.CharField(max_length=255, blank=True)
    reproduction = models.TextField(null=True)
    billing_needed = models.NullBooleanField(default=None)
    billing_reason = models.TextField(null=True, blank=True)
    billing_done = models.NullBooleanField(default=None)
    solution = models.TextField(null=True, blank=True)
    fixed_in_version = models.CharField(max_length=255, choices=lazy(getGibthubTags, list)(), blank=True)
    deadline = models.DateField(null=True, blank=True)
{'fraction_non_alphanumeric': 0.12076042341758479, 'fraction_numerical': 0.012961762799740765, 'mean_word_length': 3.182475158084914, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, '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': '1272199', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1430, 'n_words': 325}