Skip to content

Commit

Permalink
Code corresponding to the initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
therealphildini committed May 25, 2017
1 parent 55b04ea commit 93af570
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 65 deletions.
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
History
=======

0.0.1 (2017-05-24)
0.0.1 (2017-05-25)
------------------

* First release on PyPI.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Manage your labels.
Features
--------

* TODO
* Allows you to list all the labels on a repo, or all repos on an organization.

Credits
---------
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To install Epithet, run this command in your terminal:
$ pip install epithet
This is the preferred method to install Epithet, as it will always install the most recent stable release.
This is the preferred method to install Epithet, as it will always install the most recent stable release.

If you don't have `pip`_ installed, this `Python installation guide`_ can guide
you through the process.
Expand Down
26 changes: 25 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
Usage
=====

These docs are a little lacking at the moment, and we'd love to see them
improved!

To use Epithet in a project::

import epithet
$ epithet

Usage: epithet [OPTIONS] COMMAND [ARGS]...

Options:
--dryrun Don't actually change or create labels
--help Show this message and exit.

Commands:
add
list

$ epithet add --help
Usage: epithet add [OPTIONS]

Options:
--name TEXT Name of new label
--color TEXT Color of new label
--key TEXT OAuth Token
--org TEXT Organization to get repos from
--repo TEXT Optionally select a single repo
--help Show this message and exit.
56 changes: 37 additions & 19 deletions epithet/epithet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
def main():
cli(obj={})


@click.group()
@click.option('--key', help="OAuth Token")
@click.option('--org', help="Organization to get repos from")
@click.option('--repo', help="Optionally select a single repo")
@click.pass_context
def cli(ctx, key, org, repo):
def get_repos(key, org, repo):
g = Github(key)
if org:
g_org = g.get_organization(login=org)
Expand All @@ -24,34 +18,58 @@ def cli(ctx, key, org, repo):
repos = [g_org.get_repo(repo)]
else:
repos = g_org.get_repos()
ctx.obj['repos'] = repos
return repos


@click.group()
@click.option('--dryrun', is_flag=True, help="Don't actually change or create labels")
@click.pass_context
def cli(ctx, dryrun):
ctx.obj['dryrun'] = dryrun


@cli.command()
@click.option('--key', help="OAuth Token")
@click.option('--org', help="Organization to get repos from")
@click.option('--repo', help="Optionally select a single repo")
@click.pass_context
def list(ctx):
for repo in ctx.obj['repos']:
click.echo("{}labels:\n".format(repo.name))
def list(ctx, key, org, repo):
for repo in get_repos(key, org, repo):
click.echo("\n * {}:\n".format(repo.name))
for label in repo.get_labels():
click.echo("- {} ({})".format(label.name, label.color))
click.echo(" - {} ({})".format(label.name, label.color))


@cli.command()
@click.option('--name', help="Name of new label")
@click.option('--color', help="Color of new label")
@click.option('--key', help="OAuth Token")
@click.option('--org', help="Organization to get repos from")
@click.option('--repo', help="Optionally select a single repo")
@click.pass_context
def add(ctx, name, color):
def add(ctx, name, color, key, org, repo):
click.echo("name: {}, color: {}".format(name, color))
for repo in ctx.obj['repos']:
click.echo("Checking {}".format(repo.name))
for repo in get_repos(key, org, repo):
click.echo(" * Checking {}".format(repo.name))
labels = {}
for label in repo.get_labels():
labels[label.name] = label
if name in labels:
click.echo("Found {} on {}".format(labels[name].name, repo.name))
if labels[name].color != color:
click.echo(
" - Found {} on {} (Dryrun: {})".format(
labels[name].name, repo.name, ctx.obj['dryrun']
)
)
if labels[name].color != color and not ctx.obj['dryrun']:
labels[name].edit(name=name, color=color)
else:
click.echo("Creating {} on {}".format(name, repo.name))
repo.create_label(name=name, color=color)
click.echo(
" - Creating {} on {} (Dryrun: {})".format(
name, repo.name, ctx.obj['dryrun']
)
)
if not ctx.obj['dryrun']:
repo.create_label(name=name, color=color)


if __name__ == "__main__":
Expand Down
42 changes: 0 additions & 42 deletions main.py

This file was deleted.

2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ coverage==4.1
Sphinx==1.4.8
cryptography==1.7
PyYAML==3.11
Click>=6.0,
PyGithub==1.34,

0 comments on commit 93af570

Please sign in to comment.