Skip to content

Commit

Permalink
Merge pull request #2822 from mashehu/add-force_pr-to-sync
Browse files Browse the repository at this point in the history
Add `force_pr` flag to sync, to force a PR even though there are no changes committed
  • Loading branch information
mirpedrol authored May 7, 2024
2 parents dda0b91 + d0de101 commit 2d136fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
- "ubuntu-latest"
- "self-hosted"
default: "self-hosted"
force_pr:
description: "Force a PR to be created"
type: boolean
default: false

# Cancel if a newer run is started
concurrency:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

- Update CI to use nf-core/setup-nextflow v2 ([#2819](https://github.com/nf-core/tools/pull/2819))
- Changelog bot: handle also patch version before dev suffix ([#2820](https://github.com/nf-core/tools/pull/2820))
- Add `force_pr` flag to sync, to force a PR even though there are no changes committed ([#2822](https://github.com/nf-core/tools/pull/2822))
- Update prettier to 3.2.5 ([#2830](https://github.com/nf-core/tools/pull/2830))
- Update GitHub Actions ([#2827](https://github.com/nf-core/tools/pull/2827)), ([#2902](https://github.com/nf-core/tools/pull/2902)), ([#2927](https://github.com/nf-core/tools/pull/2927)), ([#2939](https://github.com/nf-core/tools/pull/2939))
- Switch to setup-nf-test ([#2834](https://github.com/nf-core/tools/pull/2834))
Expand Down
10 changes: 8 additions & 2 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,10 +2147,16 @@ def logo(logo_text, dir, name, theme, width, format, force):
default=False,
help="Make a GitHub pull-request with the changes.",
)
@click.option(
"--force_pr",
is_flag=True,
default=False,
help="Force the creation of a pull-request, even if there are no changes.",
)
@click.option("-g", "--github-repository", type=str, help="GitHub PR: target repository.")
@click.option("-u", "--username", type=str, help="GitHub PR: auth username.")
@click.option("-t", "--template-yaml", help="Pass a YAML file to customize the template")
def sync(dir, from_branch, pull_request, github_repository, username, template_yaml):
def sync(dir, from_branch, pull_request, github_repository, username, template_yaml, force_pr):
"""
Sync a pipeline [cyan i]TEMPLATE[/] branch with the nf-core template.
Expand All @@ -2170,7 +2176,7 @@ def sync(dir, from_branch, pull_request, github_repository, username, template_y
is_pipeline_directory(dir)

# Sync the given pipeline dir
sync_obj = PipelineSync(dir, from_branch, pull_request, github_repository, username, template_yaml)
sync_obj = PipelineSync(dir, from_branch, pull_request, github_repository, username, template_yaml, force_pr)
try:
sync_obj.sync()
except (SyncExceptionError, PullRequestExceptionError) as e:
Expand Down
9 changes: 8 additions & 1 deletion nf_core/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PipelineSync:
gh_username (str): GitHub username
gh_repo (str): GitHub repository name
template_yaml_path (str): Path to template.yml file for pipeline creation settings. DEPRECATED
force_pr (bool): Force the creation of a pull request, even if there are no changes to the template
Attributes:
pipeline_dir (str): Path to target pipeline directory
Expand All @@ -64,6 +65,7 @@ def __init__(
gh_repo=None,
gh_username=None,
template_yaml_path=None,
force_pr=False,
):
"""Initialise syncing object"""

Expand All @@ -76,6 +78,7 @@ def __init__(
self.make_pr = make_pr
self.gh_pr_returned_data = {}
self.required_config_vars = ["manifest.name", "manifest.description", "manifest.version", "manifest.author"]
self.force_pr = force_pr

self.gh_username = gh_username
self.gh_repo = gh_repo
Expand Down Expand Up @@ -132,8 +135,12 @@ def sync(self):
self.make_template_pipeline()
self.commit_template_changes()

if not self.made_changes and self.force_pr:
log.info("No changes made to TEMPLATE, but PR forced")
self.made_changes = True

# Push and make a pull request if we've been asked to
if self.made_changes and self.make_pr:
if self.made_changes and self.make_pr or self.force_pr:
try:
# Check that we have an API auth token
if os.environ.get("GITHUB_AUTH_TOKEN", "") == "":
Expand Down

0 comments on commit 2d136fc

Please sign in to comment.