def getView(): v = Obj() v.title = "Home" v.loggedin = loggedIn() v.projects = [i for i in Project.select().where(Project.active == True)] v.stat_total_builds = len([i for i in Build.select().where(Build.built==True)]) v.stat_total_projects = len(v.projects) v.stat_total_downloads = 0 v.stat_total_success = len([i for i in Build.select().where((Build.built==True) & (Build.success==True))]) v.stat_total_failure = len([i for i in Build.select().where((Build.built==True) & (Build.success==False))]) return v
def buildView(id=None): v = getView() if not id: redirect('/') q = [i for i in Build.select().where(Build.id==id)] q.reverse() if not len(q): return flashy('/', 'No build with ID #%s' % id, 'error') v.build = q[0] return render_template('build.html', v=v)
def test_build_stringifying(self): build = Build(job_name='Test', build_id=1234, build_url='test', finished_at_secs=5678, status='SUCCESS', duration_millis=4321) self.assertEqual(str(build), '<Build(id=None, name=Test, build_id=1234)>')
def test_stage_stringifying(self): build = Build(job_name='Test', build_id=1234, build_url='test', finished_at_secs=5678, status='SUCCESS', duration_millis=4321) stage = Stage(name='TestStage', status='SUCCESS', duration_millis=1010) build.stages.append(stage) self.assertEqual(str(stage), '<Stage(id=None, build_id=1234, name=TestStage)>')
def get_job_from_resp(job_name, build_url, resp): timestamp = int(resp['endTimeMillis'] / 1000) build = Build(job_name=job_name, build_id=resp['id'], build_url=build_url, finished_at_secs=timestamp, status=resp['status'], duration_millis=resp['durationMillis']) if 'stages' in resp.keys(): for resp_stage in resp['stages']: stage = Stage(name=resp_stage['name'], status=resp_stage['status'], duration_millis=resp_stage['durationMillis']) build.stages.append(stage) return build
def apiRoute(action=None): if action == 'put_build': p = Project.get(Project.id==int(request.form.get('pid'))) q = [i for i in Build.select().where((Build.build_id == request.form.get('id')) & (Build.built==False) & (Build.project==p))] if not len(q): return 'Error!' b = q[0] b.built = True b.success = bool(int(request.form.get('success'))) b.result = request.form.get('result').replace('\n', '<br />') b.finish_time = datetime.now() f = request.files.get('build') if not f or not f.filename.endswith('.tar.gz'): print "Invalid file!" else: b.build_url = 'http://'+saveBuild(b, f) b.save() if action == "github": d = request.form q = [i for i in Project.select().where((Project.repo_name==d['repository']['name'].lower()) &(Project.active==True))] if len(q): commits = [] for i in d['commits']: com = [i for i in Commit.select().where((Commit.sha==i['id'][:6]))] if len(com): commits.append(com[0]) else: c = Commit( project=q[0], info=i['message'], author=i['author']['name'], url=i['url'], sha=i['id'][:6]) c.save() commits.append(c) if not len(commits): print "No commits! %s" % d return 'Hi :3' b = Build( project=q[0], commit=commits[-1], build_id=q[0].getBuildId(), built=False, time=datetime.now()) b.save() addBuild(b) else: print 'Invalid build info! %s' % d if action == 'gitlab': d = request.json q = [i for i in Project.select().where((Project.repo_name==request.json['repository']['name'].lower()) &(Project.active==True))] if len(q): commits = [] for i in request.json['commits']: com = [i for i in Commit.select().where((Commit.sha==i['id'][:6]))] if len(com): commits.append(com[0]) continue c = Commit( project=q[0], info=i['message'], author=i['author']['name'], url='http://git.'+i['url'], sha=i['id'][:6]) c.save() commits.append(c) if not len(commits): print 'No commits?', d return ':3' b = Build( project=q[0], commit=commits[-1], build_id=q[0].getBuildId(), built=False, time=datetime.now()) b.save() addBuild(b) else: print 'Invalid build info!', d, q return ':3'