From 09406ac09be9ecb0603a104b10cc6d16053a1c21 Mon Sep 17 00:00:00 2001 From: Lenka Segura Date: Dec 19 2018 14:46:24 +0000 Subject: split function for easy testing --- diff --git a/cranc/cranc.py b/cranc/cranc.py index 195e37f..5f543be 100644 --- a/cranc/cranc.py +++ b/cranc/cranc.py @@ -1,42 +1,56 @@ +import json +import logging +import os + import click import pprint from libpagure import libpagure +api_token = os.getenv("CRANC_TOKEN") +project = "pagure" + +# Creating a Pagure object +PAGURE = libpagure.Pagure(pagure_token=api_token, pagure_repository=project) + + @click.group() def cranc(): pass -api_token = os.getenv('CRANC_TOKEN') - ################################################################################ # PR section ################################################################################ + @click.group() def pr(): pass -@click.command() -#@click.option('--author', default='all') -def list(): +@click.command(name="list") +@click.option("--status") +@click.option("--assignee") +@click.option("--author") +def pr_list(status, assignee, author): + """Prints list of pull requests""" + prs = filter_pull_requests(status=status, assignee=assignee, author=author) + pprint.pprint(prs) + + +def filter_pull_requests(status, assignee, author): """ Get all pull requests of a project. :param status: filters the status of the requests :param assignee: filters the assignee of the requests :param author: filters the author of the requests :return: - """ - pagure = libpagure.Pagure(pagure_token=api_token, pagure_repository='pagure') - prs = pagure.list_requests() - - pprint.pprint(prs) - -pr.add_command(list) + """ + return PAGURE.list_requests(status=status, assignee=assignee, author=author) +pr.add_command(pr_list) ################################################################################ # General section diff --git a/requirements.txt b/requirements.txt index e5b399c..b316fec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,17 @@ # Used for when working from a virtualenv. # Use this file by running "$ pip install -r requirements.txt" +############################################## +# general +############################################## + click libpagure requests + +############################################## +# tests +############################################## + +pytest +black