def update_job_step(uuid, step, status): job = get_job_by_uuid(uuid) info = job['info'] or [] step['status'] = status info.append(step) # steps & env already stringified get_cursor().execute(" UPDATE jobs set steps = ? where uuid=? ", (json.dumps(info), str(uuid))) commit_db()
def add_project(project): # https://docs.gitlab.com/ee/api/projects.html#get-single-project print("add_project") print(project) uuid = uuid4() name = project['path_with_namespace'] id = project['id'] get_cursor().execute(INSERT_PROJECT_SQL, (str(uuid), int(id), name, dumps(project))) commit_db()
def update_project_pipeline(id, branch, steps, env): # steps & env already stringified get_cursor().execute(" UPDATE projects set build_branch= ?, pipeline_steps= ?, pipeline_envs= ? where id=? ", (branch, steps, env, id)) commit_db()
def get_project_by_uuid(uuid): return get_cursor().execute("Select * from projects where uuid=? ;", uuid)
def get_project_by_id(id): return get_cursor().execute("Select * from projects where id= ? ;", (str(id),)).fetchone()
def get_projects(**kwargs): page = kwargs['page'] if 'page' in kwargs else 10 page_size = kwargs['page_size'] if 'page_size' in kwargs else 0 print(page) print(page_size) return get_cursor().execute(SELECT_PROJECTS_SQL, (page, page_size * page)).fetchall()
def init_db(): get_cursor().execute(CREATE_TABLE_JOBS_SQL) get_cursor().execute(CREATE_TABLE_PROJECTS_SQL)
def update_job_status(uuid, status): # steps & env already stringified get_cursor().execute(" UPDATE jobs set status= ? where uuid=? ", (status, uuid)) commit_db()
def get_job_by_uuid(uuid): return get_cursor().execute("Select * from jobs where uuid= ? ;", (str(uuid), )).fetchone()
def create_job(project_id): # https://docs.gitlab.com/ee/api/projects.html#get-single-project uuid = uuid4() get_cursor().execute(INSERT_JOB_SQL, (str(uuid), int(project_id))) commit_db()