Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return pr url #155

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions proteobench/github/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pandas as pd
from git import Repo

from github import Github


def clone_repo_anon(
clone_dir="K:/pb/",
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion proteobench/modules/dda_quant/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
4 changes: 3 additions & 1 deletion webinterface/pages/DDA_Quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down