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

Add sastre and tailor CLI options for apply_pr #62

Merged
merged 8 commits into from
Aug 24, 2018
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
61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ from GitHub and set to the `GITHUB_TOKEN` environment variable.
This repository uses the [Click](http://click.pocoo.org/5/) package to
register commands that call the fabric scripts.

The following commands are supported with apply_pr:

| Console Command | Description | Wiki page |
|:---------------:|:----------------------------------------------------------------------------|:--------------------------------------------------------------------------------------|
| apply_pr | Apply a PR to a remote server | [Apply a Pull Request](https://github.com/gisce/apply_pr/wiki/Apply-a-Pull-Request) |
| check_pr | Check if the PR's commits are applied on the server | [Check Applied patches](https://github.com/gisce/apply_pr/wiki/Check-Applied-patches) |
| status_pr | Update the deploy status on GitHub for the PR | [Mark deploy status](https://github.com/gisce/apply_pr/wiki/Mark-deploy-status) |
| check_prs_status| Check the PRs status (whether they are or not merged and at which milestone)| [Check PRs Status](https://github.com/gisce/apply_pr/wiki/Check-the-PRs-status) |
| create_changelog| Creates the changelog for all PRs merged in a milestone | [Create Changelog](https://github.com/gisce/apply_pr/wiki/Create-Changelog) |
The following commands are supported with `sastre`:

| Console Command | Description | Wiki page |
|:---------------: |:--------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------|
| `deploy` | Apply a PR to a remote server | [Deploy a pull request](https://github.com/gisce/apply_pr/wiki/Apply-a-Pull-Request) |
| `check_prs` | Check the status of the PRs for a set of PRs | [Check pull requests status](https://github.com/gisce/apply_pr/wiki/Check-pull-requests-status) |
| `status` | Update the status of a deploy into GitHub | [Mark deploy status](https://github.com/gisce/apply_pr/wiki/Mark-deploy-status) |
| `create_changelog` | Create a chnagelog for the given milestone | [Create Changelog](https://github.com/gisce/apply_pr/wiki/Create-Changelog) |
| `check_pr` | **Deprecated:** Check if the PR's commits are applied on the server | [Check Applied patches](https://github.com/gisce/apply_pr/wiki/Check-applied-patches-(deprecated)) |

## Install

Expand All @@ -35,14 +34,14 @@ pip install apply_pr

**NOTE**: do not include braces on the following commands

### APPLY PR
### DEPLOY

```bash
Usage: apply_pr [OPTIONS]
Usage: deploy [OPTIONS]

Options:
--pr TEXT Pull request to apply [required]
--host TEXT Host to apply [required]
--pr TEXT Pull request to deploy [required]
--host TEXT Host to where to be deployed [required]
--from-number INTEGER From commit number
--from-commit TEXT From commit hash (included)
--force-hostname TEXT Force hostname [default: False]
Expand All @@ -52,24 +51,10 @@ Options:
--help Show this message and exit.
```

### CHECK PR

```bash
Usage: check_pr [OPTIONS]

Options:
--pr TEXT Pull request to check [required]
--host TEXT Host to check [required]
--owner TEXT GitHub owner name [default: gisce]
--repository TEXT GitHub repository name [default: erp]
--src TEXT Remote src path [default: /home/erp/src]
--help Show this message and exit.
```

### STATUS PR
### STATUS

```bash
Usage: status_pr [OPTIONS]
Usage: status [OPTIONS]

Options:
--deploy-id TEXT Deploy id to mark
Expand All @@ -80,10 +65,10 @@ Options:
--help Show this message and exit.
```

### CHECK PRS STATUS
### CHECK PRS

```bash
Usage: check_prs_status [OPTIONS]
Usage: check_prs [OPTIONS]

Options:
--prs TEXT List of pull request separated by space (by default)
Expand All @@ -108,4 +93,18 @@ Options:
--owner TEXT GitHub owner name [default: gisce]
--repository TEXT GitHub repository name [default: erp]
--help Show this message and exit.
```

### CHECK PR (deprecated)

```bash
Usage: check_pr [OPTIONS]

Options:
--pr TEXT Pull request to check [required]
--host TEXT Host to check [required]
--owner TEXT GitHub owner name [default: gisce]
--repository TEXT GitHub repository name [default: erp]
--src TEXT Remote src path [default: /home/erp/src]
--help Show this message and exit.
```
155 changes: 101 additions & 54 deletions apply_pr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@

from fabric.tasks import execute, WrappedCallableTask
from fabric.api import env
from fabric import colors
import click

DEFAULT_LOG_LEVEL = 'ERROR'

github_options = [
click.option('--owner', help='GitHub owner name', default='gisce', show_default=True),
click.option('--repository', help='GitHub repository name', default='erp', show_default=True),

]

deployment_options = github_options + [
click.option("--host", help="Host to apply", required=True),
click.option('--src', help='Remote src path', default='/home/erp/src', show_default=True),
]

apply_pr_options = deployment_options + [
click.option("--pr", help="Pull request to apply", required=True),
click.option("--from-number", help="From commit number", default=0),
click.option("--from-commit", help="From commit hash (included)", default=None),
click.option("--force-hostname", help="Force hostname", default=False)
]


def add_options(options):
def _add_options(func):
for option in reversed(options):
func = option(func)
return func
return _add_options


def configure_logging():
log_level = getattr(logging, os.environ.get(
Expand All @@ -16,29 +43,36 @@ def configure_logging():
logging.basicConfig(level=log_level)


@click.command(name="apply_pr")
@click.option("--pr", help="Pull request to apply", required=True)
@click.option("--host", help="Host to apply", required=True)
@click.option("--from-number", help="From commit number", default=0)
@click.option("--from-commit", help="From commit hash (included)",
default=None, show_default=True)
@click.option("--force-hostname", help="Force hostname",
default=False, show_default=True)
@click.option('--owner', help='GitHub owner name',
default='gisce', show_default=True)
@click.option('--repository', help='GitHub repository name',
default='erp', show_default=True)
@click.option('--src', help='Remote src path',
default='/home/erp/src', show_default=True)
def apply_pr(
pr, host, from_number, from_commit, force_hostname,
owner, repository, src
):
@click.group(name='tailor')
def tailor(**kwargs):
from apply_pr.version import check_version
check_version()

from apply_pr import fabfile

def apply_pr(
pr, host, from_number, from_commit, force_hostname,
owner, repository, src
):
"""
Deploy a PR into a remote server via Fabric
:param pr: Number of the PR to deploy
:type pr: str
:param host: Host to connect
:type host: str
:param from_number: Number of the commit to deploy from
:type from_number: str
:param from_commit: Hash of the commit to deploy from
:type from_commit: str
:param force_hostname: Hostname used in GitHub
:type force_hostname: str
:param owner: Owner of the repository of GitHub
:type owner: str
:param repository: Name of the repository of GitHub
:type repository: str
:param src: Source path to the repository directory
:type src: str
"""
from apply_pr import fabfile
url = urlparse(host)
env.user = url.username
env.password = url.password
Expand All @@ -53,16 +87,25 @@ def apply_pr(
)


@click.command(name='check_pr')
@tailor.command(name="deploy")
@add_options(apply_pr_options)
def deploy(**kwargs):
"""Deploy a PR into a remote server via Fabric"""
return apply_pr(**kwargs)


@tailor.command(name='check_pr')
@click.option('--pr', help='Pull request to check', required=True)
@click.option('--host', help='Host to check', required=True)
@click.option('--owner', help='GitHub owner name',
default='gisce', show_default=True)
@click.option('--repository', help='GitHub repository name',
default='erp', show_default=True)
@click.option('--src', help='Remote src path',
default='/home/erp/src', show_default=True)
def check_pr(pr, src, owner, repository, host):
@click.option('--force/--no-force', default=False,
help='Forces the usage of this command')
@add_options(deployment_options)
def check_pr(pr, force, src, owner, repository, host):
"""DEPRECATED - Check for applied commits on PR"""
print(colors.red("This option has been deprecated as it doesn't work"))
if not force:
print(colors.red(
"Use '--force' to force the usage for this command (as is)"))
exit()
from apply_pr import fabfile

url = urlparse(host)
Expand All @@ -76,15 +119,8 @@ def check_pr(pr, src, owner, repository, host):
src=src, owner=owner, repository=repository, host=url.hostname)


@click.command(name='status_pr')
@click.option('--deploy-id', help='Deploy id to mark')
@click.option('--status', type=click.Choice(['success', 'error', 'failure']),
help='Status to set', default='success', show_default=True)
@click.option('--owner', help='GitHub owner name',
default='gisce', show_default=True)
@click.option('--repository', help='GitHub repository name',
default='erp', show_default=True)
def status_pr(deploy_id, status, owner, repository):
"""Update the status of a deploy into GitHub"""
from apply_pr import fabfile

configure_logging()
Expand All @@ -94,19 +130,18 @@ def status_pr(deploy_id, status, owner, repository):
owner=owner, repository=repository)


@click.command(name='check_prs_status')
@click.option('--prs', required=True,
help='List of pull request separated by space (by default)')
@click.option('--separator',
help='Character separator of list by default is space',
default=' ', required=True, show_default=True)
@click.option('--version',
help="Compare with milestone and show if included in prs")
@click.option('--owner', help='GitHub owner name',
default='gisce', show_default=True)
@click.option('--repository', help='GitHub repository name',
default='erp', show_default=True)
@tailor.command(name='status')
@click.option('--deploy-id', help='Deploy id to mark')
@click.option('--status', type=click.Choice(['success', 'error', 'failure']),
help='Status to set', default='success', show_default=True)
@add_options(github_options)
def status(**kwargs):
"""Update the status of a deploy into GitHub"""
status_pr(**kwargs)


def check_prs_status(prs, separator, version, owner, repository):
"""Check the status of the PRs for a set of PRs"""
from apply_pr import fabfile

log_level = getattr(logging, os.environ.get('LOG_LEVEL', 'INFO').upper())
Expand All @@ -120,18 +155,30 @@ def check_prs_status(prs, separator, version, owner, repository):
version=version)


@click.command(name='check_prs_status')
@tailor.command(name='check_prs')
@click.option('--prs', required=True,
help='List of pull request separated by space (by default)')
@click.option('--separator',
help='Character separator of list by default is space',
default=' ', required=True, show_default=True)
@click.option('--version',
help="Compare with milestone and show if included in prs")
@add_options(github_options)
def check_prs(**kwargs):
"""Check the status of the PRs for a set of PRs"""
check_prs_status(**kwargs)


@tailor.command(name='create_changelog')
@click.option('-m', '--milestone', required=True,
help='Milestone to get the issues from (version)')
@click.option('--issues/--no-issues', default=False, show_default=True,
help='Also get the data on the issues')
@click.option('--changelog_path', default='/tmp', show_default=True,
help='Path to drop the changelog file in')
@click.option('--owner', help='GitHub owner name',
default='gisce', show_default=True)
@click.option('--repository', help='GitHub repository name',
default='erp', show_default=True)
@add_options(github_options)
def create_changelog(milestone, issues, changelog_path, owner, repository):
"""Create a changelog for the given milestone"""
from apply_pr import fabfile

log_level = getattr(logging, os.environ.get('LOG_LEVEL', 'INFO').upper())
Expand All @@ -146,4 +193,4 @@ def create_changelog(milestone, issues, changelog_path, owner, repository):


if __name__ == '__main__':
apply_pr()
tailor()
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
description='Apply Pull Requests from GitHub',
entry_points='''
[console_scripts]
apply_pr=apply_pr.cli:apply_pr
check_pr=apply_pr.cli:check_pr
status_pr=apply_pr.cli:status_pr
check_prs_status=apply_pr.cli:check_prs_status
create_changelog=apply_pr.cli:create_changelog
sastre=apply_pr.cli:tailor
tailor=apply_pr.cli:tailor
''',
install_requires=[
'fabric<2.0',
Expand Down