From 9902f7d72c1d521384c6ee8841ccbb0068ea8df5 Mon Sep 17 00:00:00 2001 From: RobbinBouwmeester Date: Thu, 7 Dec 2023 11:30:43 +0100 Subject: [PATCH] Return pr url --- proteobench/github/gh.py | 50 ++++++++++++++++++++----- proteobench/modules/dda_quant/module.py | 4 +- pyproject.toml | 3 +- webinterface/pages/DDA_Quant.py | 4 +- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/proteobench/github/gh.py b/proteobench/github/gh.py index c5af0c9e..50a60e03 100644 --- a/proteobench/github/gh.py +++ b/proteobench/github/gh.py @@ -4,6 +4,8 @@ import pandas as pd from git import Repo +from github import Github + def clone_repo_anon( clone_dir="K:/pb/", @@ -37,20 +39,50 @@ def clone_repo( def pr_github( clone_dir="K:/pb/", - token="", - remote_git="github.com/Proteobot/Results_Module2_quant_DDA.git", + token="YOUR_GITHUB_TOKEN", + remote_git="Proteobot/Results_Module2_quant_DDA", username="Proteobot", branch_name="test", commit_message="New commit", + repo_name="Proteobot/Results_Module2_quant_DDA", ): - remote = f"https://{username}:{token}@{remote_git}" - repo = Repo(clone_dir) + # Construct the remote URL with the token + remote_url = f"https://{username}:{token}@{remote_git}" - repo.git.pull() + # Clone the repository if it doesn't exist + try: + repo = Repo(clone_dir) + except: + repo = Repo.clone_from(remote_url, clone_dir) - current = repo.create_head(branch_name) - current.checkout() + # Fetch the latest changes from the remote + origin = repo.remote(name="origin") + origin.fetch() + # Create and checkout the new branch + current_branch = repo.create_head(branch_name) + current_branch.checkout() + + # Stage all changes, commit, and push to the new branch repo.git.add(A=True) - repo.git.commit(m=commit_message) - repo.git.push("--set-upstream", "origin", current) + repo.index.commit(commit_message) + repo.git.push("--set-upstream", "origin", current_branch) + + # Create a pull request using PyGithub + g = Github(token) + repo = g.get_repo(repo_name) + base = repo.get_branch("master") + head = f"{username}:{branch_name}" + title = commit_message + body = "Pull request body" + + pr = repo.create_pull( + title=title, + body=body, + base=base.name, + head=head, + ) + + pr_number = pr.number + print(pr_number) + return pr_number diff --git a/proteobench/modules/dda_quant/module.py b/proteobench/modules/dda_quant/module.py index 8c959f16..c77e48ca 100644 --- a/proteobench/modules/dda_quant/module.py +++ b/proteobench/modules/dda_quant/module.py @@ -332,7 +332,7 @@ def clone_pr( f.close() commit_message = f"Added new run with id {branch_name} \n user comments: {submission_comments}" - pr_github( + pr_id = pr_github( clone_dir=t_dir, token=token, remote_git=remote_git, @@ -341,6 +341,8 @@ def clone_pr( commit_message=commit_message, ) + return "https://" + remote_git.replace(".git", "") + "/pull/" + str(pr_id) + def write_json_local_development(self, temporary_datapoints): t_dir = TemporaryDirectory().name os.mkdir(t_dir) diff --git a/pyproject.toml b/pyproject.toml index af8d7d95..ff28fbcb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ dependencies = [ "matplotlib", "importlib-metadata; python_version < '3.8'", "toml", - "psm_utils", + "PyGithub", + "GitPython", ] dynamic = ["version", "description"] keywords = ['proteomics', 'peptides', 'retention time', 'mass spectrometry'] diff --git a/webinterface/pages/DDA_Quant.py b/webinterface/pages/DDA_Quant.py index ddeb6a20..2b02feba 100644 --- a/webinterface/pages/DDA_Quant.py +++ b/webinterface/pages/DDA_Quant.py @@ -308,7 +308,7 @@ def generate_results( st.session_state[SUBMIT] = True user_comments = self.user_input["comments_for_submission"] if not LOCAL_DEVELOPMENT: - Module().clone_pr( + pr_url = Module().clone_pr( st.session_state[ALL_DATAPOINTS], st.secrets["gh"]["token"], username="Proteobot", @@ -339,6 +339,8 @@ def generate_results( if st.session_state[SUBMIT]: # status_placeholder.success(":heavy_check_mark: Successfully uploaded data!") st.subheader("SUCCESS") + st.write(f"Follow your submission approval here: [{pr_url}]({pr_url})") + st.session_state[SUBMIT] = False rain(emoji="🎈", font_size=54, falling_speed=5, animation_length=1)