Exemplo n.º 1
0
def bytags(p, data):
    repo = data['repo']

    # Loading tags for current project
    tags_url = ghAuth('https://api.github.com/repos/' + repo + '/tags')
    tags = json.loads(urlfetch.fetch(tags_url).content)

    refresh = False

    # Looping over tags
    for tag in tags:
        # If tags are not in the database, add them
        query = "SELECT * FROM VersionCache WHERE project = :1 AND commit = :2"
        q = db.GqlQuery(query, p, tag['commit']['sha'])
        if (q.count() == 0):
            refresh = True
            commit_url = ghAuth(
                'https://api.github.com/repos/' + repo +
                '/commits/' + tag['commit']['sha']
            )
            commit = json.loads(urlfetch.fetch(commit_url).content)

            # Parse the date to python datetime
            version_date = commit['commit']['author']['date']
            version_date = iso8601date.parse_iso8601_datetime(version_date)
            # Remove leading v from version number if present
            version_version = re.sub('^v(?=\d)', '', tag['name'])

            t = VersionCache(project=p,
                             version=version_version,
                             commit=tag['commit']['sha'],
                             date=version_date)
            t.put()

    #if refresh:
        #logging.info('refreshed version data')
    #else:
        #logging.info('version data unchanged')

    # Return the most recent released version
    query = (
        "SELECT version FROM VersionCache WHERE project = :1 " +
        "ORDER BY date DESC"
    )
    q = db.GqlQuery(query, p).get()
    return q.version
Exemplo n.º 2
0
    def get(self):
        url = ghAuth('https://api.github.com/rate_limit')
        rate = urlfetch.fetch(url).content
        rate = json.loads(rate)

        self.response.status = 200
        self.response.headers['Charset'] = 'utf-8'
        self.response.headers['Content-Type'] = 'text/plain'

        self.response.write('GitHub API status:\n---------------------\n')
        self.response.write('Limit:     ' + str(rate['rate']['limit']).rjust(10) + '\n')
        self.response.write('Remaining: ' + str(rate['rate']['remaining']).rjust(10))
Exemplo n.º 3
0
def byjsonfile(project, data):
    repo = data["repo"]
    filename = data["file"]

    url = ghAuth("https://api.github.com/repos/" + repo + "/contents/" + filename)
    project_data = json.loads(urlfetch.fetch(url).content)

    sha = project_data["sha"]
    q = db.GqlQuery("SELECT * FROM VersionCache WHERE project = :1 AND commit = :2", project, sha)

    if q.count() == 0:
        # logging.info('refreshing version data')
        version_version = json.loads(base64.b64decode(project_data["content"]))["version"]

        t = VersionCache(project=project, version=version_version, commit=sha, date=datetime.datetime.now())
        t.put()
    # else:
    # logging.info('version data unchanged')

    q = db.GqlQuery("SELECT version FROM VersionCache WHERE project = :1 ORDER BY date DESC", project).get()
    return q.version
Exemplo n.º 4
0
def parsePullRequest(url):
    response = []
    # Get the list of files added in the pull request
    pullfiles = urlfetch.fetch(ghAuth(url + '/files'))
    pullfiles = json.loads(pullfiles.content)
    for pullfile in pullfiles:
        pulldata = defaultdict()
        pulldata['filename'] = pullfile['filename']
        pulldata['status'] = pullfile['status']
        pulldata['patch'] = pullfile['patch']
        pulldata['raw_url'] = pullfile['raw_url']
        pulldata['blob_url'] = pullfile['blob_url']
        pulldata['extension'] = os.path.splitext(pullfile['filename'])[1][1:]
        if pulldata['extension'] == 'yaml':
            pulldata['valid'] = True
            pulldata['data'] = parseYamlFile(pullfile['raw_url'])
        else:
            pulldata['valid'] = False
            pulldata['data'] = {}

        response.append(pulldata)

    return response
Exemplo n.º 5
0
from app.models import FileCache
from app.models import Project

from app.helpers import ghAuth

#
# Configuration
#
source_repo = 'version-is/version.is-sources'


#
# Paths
#
raw_path = 'https://raw.github.com/' + source_repo + '/master/'
contents_path = ghAuth('https://api.github.com/repos/' + source_repo + '/contents')


#
# Test if a handler is indeed callable and from our handlers module
#
def testHandler(handler):
    handler_valid = True
    try:
        handler = getattr(handlers, handler)
    except AttributeError:
        handler_valid = False

    return (handler_valid, handler)

Exemplo n.º 6
0
def pullRequestApiUrl():
    return ghAuth('https://api.github.com/repos/version-is/version.is-sources/pulls')