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

Fix 2.4 sync #1585

Merged
merged 5 commits into from
May 16, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# nf-core/tools: Changelog

## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]

- Patch release to try to fix the template sync ([#1585](https://github.com/nf-core/tools/pull/1585)).

## [v2.4 - Cobolt Koala](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]

### Template
Expand Down
10 changes: 6 additions & 4 deletions nf_core/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ def __init__(
self.gh_repo = gh_repo
self.pr_url = ""

# Set up the API auth if supplied on the command line
self.gh_api = nf_core.utils.gh_api
if self.gh_username and "GITHUB_AUTH_TOKEN" in os.environ:
self.gh_api.auth = requests.auth.HTTPBasicAuth(self.gh_username, os.environ["GITHUB_AUTH_TOKEN"])
self.gh_api.return_ok = [200, 201]
self.gh_api.lazy_init()
if self.gh_username and "GITHUB_AUTH_TOKEN" in os.environ:
log.debug(f"Authenticating sync as {self.gh_username}")
self.gh_api.setup_github_auth(
requests.auth.HTTPBasicAuth(self.gh_username, os.environ["GITHUB_AUTH_TOKEN"])
)

def sync(self):
"""Find workflow attributes, create a new template pipeline on TEMPLATE"""
Expand Down Expand Up @@ -320,7 +323,6 @@ def make_pull_request(self):

# Make new pull-request
stderr = rich.console.Console(stderr=True, force_terminal=nf_core.utils.rich_force_colors())
log.debug("Submitting PR to GitHub API")
with self.gh_api.cache_disabled():
try:
r = self.gh_api.request_retry(
Expand Down
14 changes: 10 additions & 4 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,25 @@ def __call__(self, r):

log.debug(f"Using GitHub auth: {self.auth_mode}")

def log_content_headers(self, request):
def log_content_headers(self, request, post_data=None):
"""
Try to dump everything to the console, useful when things go wrong.
"""
log.debug(f"Requested URL: {request.url}")
log.debug(f"From requests cache: {request.from_cache}")
log.debug(f"Request status code: {request.status_code}")
log.debug(f"Request reason: {request.reason}")
if post_data is None:
post_data = {}
try:
log.debug(json.dumps(dict(request.headers), indent=4))
log.debug(json.dumps(request.json(), indent=4))
log.debug(json.dumps(post_data, indent=4))
except Exception as e:
log.debug(f"Could not parse JSON response from GitHub API! {e}")
log.debug(request.headers)
log.debug(request.content)
log.debug(post_data)

def safe_get(self, url):
"""
Expand Down Expand Up @@ -504,14 +508,16 @@ def request_retry(self, url, post_data=None):
while True:
# GET request
if post_data is None:
log.debug(f"Seding GET request to {url}")
r = self.get(url=url)
# POST request
else:
log.debug(f"Seding POST request to {url}")
r = self.post(url=url, json=post_data)

# Failed but expected - try again
if r.status_code in self.return_retry:
self.log_content_headers(r)
self.log_content_headers(r, post_data)
log.debug(f"GitHub API PR failed - got return code {r.status_code}")
wait_time = float(re.sub("[^0-9]", "", str(r.headers.get("Retry-After", 0))))
if wait_time == 0:
Expand All @@ -522,8 +528,8 @@ def request_retry(self, url, post_data=None):

# Unexpected error - raise
elif r.status_code not in self.return_ok:
self.log_content_headers(r)
raise AssertionError(f"GitHub API PR failed - got return code {r.status_code} from {url}")
self.log_content_headers(r, post_data)
raise RuntimeError(f"GitHub API PR failed - got return code {r.status_code} from {url}")

# Success!
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

version = "2.4"
version = "2.4.1"

with open("README.md") as f:
readme = f.read()
Expand Down