def create_handle(): form = ProjectCreateForm() if form.validate_on_submit(): if ProjectLogic.exists_for_user(g.user, form.title.data): abort(400) # todo: replace with exception raise else: project = Project( user=g.user, title=form.title.data, source_mode=form.source_mode.data, ) project.local_text = "FROM fedora:latest \n" project.patched_dockerfile = "" event = create_project_event(project, "Created") db.session.add_all([project, event]) db.session.commit() schedule_task_async(create_project_repos_task, project.id) return redirect( url_for("project.details", username=project.user.username, title=project.title)) else: return create_view(form=form)
def run_build_async(project: Project): # todo: should we do some checks here? # project.build_requested_on = datetime.datetime.utcnow() db.session.add(project) db.session.commit() schedule_task_async(run_build_async_task, project.id)
def init_repos(username, title): user = get_user_by_name(username) project = ProjectLogic.get_project_by_title(user, title) project.check_editable_by(g.user) schedule_task_async(create_project_repos_task, project.id) flash("Repo creation scheduled", "success") return redirect(url_for("project.details", username=project.user.username, title=project.title))
def init_repos(username, title): user = get_user_by_name(username) project = ProjectLogic.get_project_by_title(user, title) project.check_editable_by(g.user) schedule_task_async(create_project_repos_task, project.id) flash("Repo creation scheduled", "success") return redirect( url_for("project.details", username=project.user.username, title=project.title))
def delete(username, title): user = get_user_by_name(username) project = ProjectLogic.get_project_by_title(user, title) form = delete_form_factory(project) if request.method == "POST" and form.validate_on_submit(): project.delete_requested_on = datetime.datetime.utcnow() ev = create_project_event(project, "Delete requested", event_type=EventType.DELETE_REQUESTED) db.session.add_all([project, ev]) db.session.commit() schedule_task_async(delete_projects_task, project.id) return render_template("project/delete.html", project=project, form=form, project_delete_page=True)
def create_project_repos(project_id: int): p = ProjectLogic.get_project_by_id_safe(project_id) if not p: return repo_name = p.repo_name if not p.github_repo_exists: log.info("Creating github repo: {}".format(repo_name)) client = GhClient() client.create_repo(repo_name) # todo: check if gh repo was created GhLogic.set_github_repo_created(p) db.session.commit() else: log.info("Github repo {} already exists".format(repo_name)) if not p.dockerhub_repo_exists: log.info("Creating dockerhub repo: {}".format(repo_name)) if dh_connector.create_project(repo_name): DhLogic.set_dh_created(p) db.session.commit() log.info("Dockerhub repo created: {}".format(repo_name)) else: return else: log.info("Dockerhub repo {} already exists".format(repo_name)) if p.dh_build_trigger_url is None: log.info("Fetching dockerhub build trigger url: {}".format(repo_name)) mb_trigger = dh_connector.get_build_trigger_url(repo_name) if mb_trigger: DhLogic.set_build_trigger(p, mb_trigger) db.session.commit() log.info("Obtained dh build trigger for: {}" .format(repo_name)) else: log.info("Build trigger for repo {} is already fetched".format(repo_name)) if p.build_requested_on is not None: schedule_task_async(run_build_async_task, project_id)
def create_handle(): form = ProjectCreateForm() if form.validate_on_submit(): if ProjectLogic.exists_for_user(g.user, form.title.data): abort(400) # todo: replace with exception raise else: project = Project( user=g.user, title=form.title.data, source_mode=form.source_mode.data, ) project.local_text = "FROM fedora:latest \n" project.patched_dockerfile = "" event = create_project_event(project, "Created") db.session.add_all([project, event]) db.session.commit() schedule_task_async(create_project_repos_task, project.id) return redirect(url_for("project.details", username=project.user.username, title=project.title)) else: return create_view(form=form)
def create_project_repos(project_id: int): p = ProjectLogic.get_project_by_id_safe(project_id) if not p: return repo_name = p.repo_name if not p.github_repo_exists: log.info("Creating github repo: {}".format(repo_name)) client = GhClient() client.create_repo(repo_name) # todo: check if gh repo was created GhLogic.set_github_repo_created(p) db.session.commit() else: log.info("Github repo {} already exists".format(repo_name)) if not p.dockerhub_repo_exists: log.info("Creating dockerhub repo: {}".format(repo_name)) if dh_connector.create_project(repo_name): DhLogic.set_dh_created(p) db.session.commit() log.info("Dockerhub repo created: {}".format(repo_name)) else: return else: log.info("Dockerhub repo {} already exists".format(repo_name)) if p.dh_build_trigger_url is None: log.info("Fetching dockerhub build trigger url: {}".format(repo_name)) mb_trigger = dh_connector.get_build_trigger_url(repo_name) if mb_trigger: DhLogic.set_build_trigger(p, mb_trigger) db.session.commit() log.info("Obtained dh build trigger for: {}".format(repo_name)) else: log.info( "Build trigger for repo {} is already fetched".format(repo_name)) if p.build_requested_on is not None: schedule_task_async(run_build_async_task, project_id)