Exemplo n.º 1
0
def add_log():
    # Bork if something is terribly wrong
    if not request.json or not 'log' in request.json:
        abort(400)

    # Iterate over the log
    cip = CommitInsertionPipeline()
    for logitem in request.json['log']:
        try:
            commit = Commit()
            commit.author = "%s <%s>" % (logitem['author_name'], 
                                         logitem['author_email'])
            date_time = parse(logitem['date'])
            commit.c_date = datetime(
                date_time.year,
                date_time.month,
                date_time.day,
                date_time.hour,
                date_time.minute,
                date_time.second
                )
            commit.cuid = logitem['id']
            commit.files = "foo.py"
            commit.message = logitem['message']
            commit.project = "Project"
            cip.add_commit(commit, True)
        except KeyError:
            print("Something is terribly wrong")
            continue
    cip.stash_commits()

    # Return something nice and positive
    return jsonify({'result': 'success'}), 201
Exemplo n.º 2
0
 def get_commits(self, repo):
     last_commit = repo.commits.order_by(Commit.date.desc()).first()
     commit_pages = self.gh.repos.commits.list(user=repo.organization.username,
                                         repo=repo.name,
                                         sha="master")
     for commit in commit_pages.iterator():
         if last_commit and commit.sha == last_commit.sha:
             print 'Next'
             break
         c = Commit.query.filter_by(sha=commit.sha).first()
         if c is None:
             c = Commit()
             c.sha = commit.sha
             c.message = commit.commit.message
             c.repository = repo
             c.date = commit.commit.author.date
             if commit.author:
                 c.user = self.get_or_create_user(commit.author)
             print 'New commit: ' + c.sha
             db.session.add(c)
             db.session.commit()