From abad9afd2a40bf7773d46242a50f65fcba11794d Mon Sep 17 00:00:00 2001 From: Lenka Segura Date: Mar 14 2019 15:54:20 +0000 Subject: pagure instance created for every function --- diff --git a/cranc/cranc.py b/cranc/cranc.py index 05cf542..5dd5353 100644 --- a/cranc/cranc.py +++ b/cranc/cranc.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + import json import logging import os @@ -23,14 +24,10 @@ import pprint from libpagure import libpagure from libpagure import exceptions -api_token = os.getenv("CRANC_TOKEN") -project = "pagure" - +project = 'cranc' +api_token = os.getenv("PAGURE_USER_TOKEN") _log = logging.getLogger(__name__) -# Creating a Pagure object -PAGURE = libpagure.Pagure(pagure_token=api_token, pagure_repository=project) - # Creating group cranc @click.group() def cranc(): @@ -47,30 +44,23 @@ def get(): @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. + """Prints list of pull requests. :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=project) try: - return PAGURE.list_requests(status=status, assignee=assignee, author=author) + prs = PAGURE.list_requests(status=status, assignee=assignee, author=author) except Exception: _log.exception("Failed to connect to the server") - + pprint.pprint(prs) # Adding pr_list into the group 'get' get.add_command(pr_list) + @click.command(name="issues") @click.option("--status") @click.option("--tags") @@ -84,6 +74,7 @@ get.add_command(pr_list) def issue_list(status, tags, assignee, author, milestones, priority, no_stones, since): """Prints list of issues""" + PAGURE = libpagure.Pagure(pagure_token=api_token) try: issues = PAGURE.list_issues(status=status, tags=tags, assignee=assignee, author=author, milestones=milestones, priority=priority, @@ -99,15 +90,19 @@ def issue_list(status, tags, assignee, author, milestones, priority, no_stones, # Adding issue_list into the group 'get' get.add_command(issue_list) + # Create subgroup 'merge' @click.group() def merge(): pass + @click.command(name="pr") @click.option("--request_id") +@click.option("--repo") def merge_pr(request_id): """This command merges a pull request""" + PAGURE = libpagure.Pagure(pagure_token=api_token, pagure_repository=repo) try: request = PAGURE.merge_request(request_id=request_id) pprint.pprint(request) @@ -123,6 +118,7 @@ merge.add_command(merge_pr) def create(): pass + @click.command(name="pr") @click.option("--repo") @click.option("--title") @@ -130,8 +126,11 @@ def create(): @click.option("--branch_from") def create_pr(repo, title, branch_to, branch_from): """this command creates a new pull request""" + PAGURE = libpagure.Pagure(pagure_token=api_token, pagure_repository=repo, + fork_username='lenkaseg') + PAGURE.log_debug(True) try: - request = PAGURE.create_pull_request(repo=repo, title=title, branch_to=branch_to, + request = PAGURE.create_pull_request(title=title, branch_to=branch_to, branch_from=branch_from) pprint.pprint(request) except Exception: diff --git a/docs/commands.md b/docs/commands.md index f3b4135..30f7aae 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -5,14 +5,14 @@ ## PR -cranc create pr [title] [content] +cranc create pr [title] [repo] [branch_from] [branch_to] This command creates a pull request. Its parameters should be: --title for the pr title, - --content for the description of the pr, - --author for the author flag, - --assignee for assignee - # Not in libpagure + --repo for the repo, + --branch_from which the PR comes, + --branch_to the destination branch + --initial_comment is optional cranc get prs