def run(): git = git.Git('./test_folder', 'https://github.com/mascanio/test-priv.git', 'mascanio', env['token']) status = git.status() print(status) print(status.is_clean()) git.add_all() git.commit('master') status = git.status() print(status) print(status.is_clean()) print(git.get_current_branch()) # print(git.push(git.get_current_branch())) # print(git.pull('dev', rebase=True)) git.rebase_stash('master') status = git.status() print(status) print(status.is_clean())
def get_branch_files(repository, check_upstream=False): if check_upstream and repository.github.upstream is not None: git.fetch( 'upstream', '--no-tags', '%s:refs/remotes/upstream/%s' % \ (repository.github.branch, repository.github.branch)) diff_output = git.diff( '--name-only', 'origin/%s..upstream/%s' % \ (repository.github.branch, repository.github.branch), strip=False) git.rebase('upstream/%s' % repository.github.branch) else: diff_output = '\n'.join([ line[3:] for line in git.status('status', '-s', strip=False) if len(line) > 3 ]) new_files = get_eligible_files(repository, diff_output, 'en') lstree_output = git.ls_tree('-r', '--name-only', repository.github.branch, strip=False) all_files = get_eligible_files(repository, lstree_output, 'en') return new_files, all_files
def process_repository(repository_full_path): repo_result = {} if os.path.isdir(repository_full_path ) and not ignore.is_ignore_path(repository_full_path): repository = os.path.basename(repository_full_path) # process repository cwd_backup = os.getcwd() os.chdir(repository_full_path) msgo, msge = git.reset_hard_head() if 'CONFLICT' in msgo or msge: repo_result['reset'] = get_error_info('git reset --hard HEAD', msgo, msge, repository) msgo, msge = git.checkout('master') if 'CONFLICT' in msgo or "Already on 'master'" != msge.strip(): repo_result['checkout'] = get_error_info('git checkout master', msgo, msge, repository) msgo, msge = git.pull() if 'CONFLICT' in msgo or ('error' in msge) or ('fatal' in msge): repo_result['pull'] = get_error_info('git pull', msgo, msge, repository) msgo, msge = git.status() if 'CONFLICT' in msgo or msge: repo_result['status'] = get_error_info('git status', msgo, msge, repository) os.chdir(cwd_backup) return repo_result
def partial(self, identifier, commit_message): """Creates a commit. Args: identifier: string that uniquely identifies the task. commit_message: partial changes commit message. Returns: No data is returned. """ git.add_files(git._changed_files()) git.status("") git.commit(identifier + " : " + commit_message) self.partials_exist = True self.log.add_entry("Partial added: OK", "Added partial commit: {} : {}".format( identifier, commit_message), time.strftime("%Y-%m-%d %H:%M:%S"))
def tree(): paths = [] for item in git.status(TOPLEVEL): status = item[:2] f = item[3:] print f for renderer in renderers: if f.endswith(renderer.extension): break else: continue file_path = os.path.join(os.path.join(TOPLEVEL, f)) if os.path.isfile(file_path): paths.append(("/" + f[:f.rfind(".")], status)) paths.sort() args = { "title": "/tree :: lnotes", "path": "/tree", "file_path": "--", "git_status": "--", "git_branch": git.branch_name(TOPLEVEL), "style_files": ("asciidoc.css", ), "paths": paths, } return render_template("tree.html", **args)
def save_dag(dag: DAG, tasks: list, commit_message=None, create_pr=False) -> None: def sort_task(a, b): if b['task_id'] in a['upstream']: return 1 elif a['task_id'] in b['upstream']: return -1 return 0 dag_file = dag.full_filepath + '.new' with open(dag_file, 'w') as fh: dg = DagGenerator(dag) for task in sorted(tasks, key=functools.cmp_to_key(sort_task)): dg.add_task(task) dag_file_string = f'{dg.dag_string}\n{dg.tasks_string}\n{dg.dependencies_string}' fh.write(dg.import_string) fh.write(dag_file_string) dag_bag = DagBag() temp_dag = dag_bag.process_file(dag_file) if not temp_dag: # os.unlink(dag_file) return False else: os.rename(dag_file, dag.full_filepath) if commit_message is not None: os.chdir(os.path.dirname(__file__) + '/kirby') date = datetime.now() git.checkout(f'code-changes-{date:%Y%m%d-%H%M%s}', new=True) print(git.status()) # print(git.diff()) git.commit(commit_message, add_all=True) # git.push() # if create_pr: # git.create_pr('Changes from airflow: ' + commit_message) # git.checkout('master') return True return False
import git import json import os absolutePath = os.path.abspath(__file__).replace( os.path.abspath(__file__).split('/')[-1], '') with open(os.path.join(absolutePath, 'config.json')) as configurationPayload: configuration = json.load(configurationPayload) blenderFilePath = os.path.join(absolutePath, configuration['blend_file_path']) blenderFileRepoPath = os.path.join(absolutePath, configuration['blend_file_repo_path']) repo = git.Repo(blenderFileRepoPath) blenderFilePathRelativeToRepo = blenderFilePath.replace( blenderFileRepoPath, '') git = repo.git if str(git.status(blenderFilePathRelativeToRepo)).find('clean') == -1: os.system('python ' + os.path.join(absolutePath, 'make_assets.py'))
except: git.checkout(b=monit_node) #git.checkout("HEAD", b=monit_node) filename = monit_node + "/" + f['applicationsolution_name'] + "_" + \ f['url'].replace("://", "_").replace("/","_") + ".conf" filepath = telegraf_dir + "/" + filename print(filename) with open(filepath, 'w') as fi: fi.write("[[inputs.url_monitor]]\n" + \ "\tapp = " + '"' + f['applicationsolution_name'] + '"\n' + \ "\taddress = " + '"' + f['url'] + '"\n' + \ "\tresponse_timeout = \"" + response_timeout + '"\n' + \ "\tmethod = " + '"' + f['method'] + '"\n' + \ "\trequire_str = " + "'" + f['require_str'] + "'\n" + \ "\trequire_code = " + "'" + f['require_code'] + "'\n" + \ "\tfailed_count = " + f['failed_count'] + '\n' + \ "\tfailed_timeout = " + f['timeout'] + '\n' + \ "\tfollow_redirects = " + follow_redirects + '\n' + \ "\tbody = " + "'" + f['body'] + "'\n" + \ "\tinsecure_skip_verify = " + insecure_skip_verify + '\n' + \ "\t[inputs.url_monitor.headers]\n\t\t" + h_str + '\n') git.add(filename) try: git.commit(m=filename) except: print(git.status()) git.push("origin", monit_node)
print(ERROR + "Unable to find README. Exiting." + ENDC) sys.exit(1) # open README and update with new version print(INFO + "Updating versions in " + readme_file + " to " + version + ENDC) with open(readme_file, "r+") as readme: text = readme.read() for sub in subs: (find, replace) = sub text = re.sub(find, replace, text) readme.seek(0) readme.write(text) print(INFO + "Adding git changes." + ENDC) git.add(readme_file) if not git.status("-s"): print(INFO + "No changes. Exiting." + ENDC) sys.exit(0) git.commit('-m', f'Update {readme_file} examples to reflect new version {version}') push_failures = 0 while True: try: print(INFO + "Pushing updated README." + ENDC) git.push() break except GitCommandError: push_failures += 1 if push_failures <= 5: print(NOTICE + "Failed to push. Going to pull and try again." +
import git import json import os absolutePath = os.path.abspath(__file__).replace(os.path.abspath(__file__).split('/')[-1], '') with open(os.path.join(absolutePath, 'config.json')) as configurationPayload: configuration = json.load(configurationPayload) blenderFilePath = os.path.join(absolutePath, configuration['blend_file_path']) blenderFileRepoPath = os.path.join(absolutePath, configuration['blend_file_repo_path']) repo = git.Repo(blenderFileRepoPath) blenderFilePathRelativeToRepo = blenderFilePath.replace(blenderFileRepoPath, '') git = repo.git if str(git.status(blenderFilePathRelativeToRepo)).find('clean') == -1: os.system('python ' + os.path.join(absolutePath, 'make_assets.py'))