#1443 cli, python: add command to list all builds of a project
Merged 3 years ago by frostyx. Opened 3 years ago by dturecek.
copr/ dturecek/copr list-builds  into  master

@@ -75,6 +75,12 @@ 

          rlRun "copr-cli build ${NAME_PREFIX}Project1 $HELLO"

          # build - FAIL  (syntax error in source code)

          rlRun "copr-cli build ${NAME_PREFIX}Project1 $EVIL_HELLO" 4

+         # check all builds are listed

+         OUTPUT=`mktemp`

+         rlRun "copr-cli list-builds ${NAME_PREFIX}Project1 > $OUTPUT" 0

+         rlAssertEquals "Three builds listed" `cat $OUTPUT | wc -l` 3

+         rlAssertEquals "Two failed builds" `grep -r 'failed' $OUTPUT | wc -l` 2

+         rlAssertEquals "One succeeded build" `grep -r 'succeeded' $OUTPUT | wc -l` 1

          # enable Project1 repo

          rlRun "yes | dnf copr enable $DNF_COPR_ID/${NAME_PREFIX}Project1 $CHROOT"

          # install hello package

file modified
+24
@@ -33,6 +33,7 @@ 

  

  from copr.v3 import (Client, config_from_file, CoprException, CoprRequestException, CoprNoConfigException,

                       CoprConfigException, CoprNoResultException)

+ from copr.v3.pagination import next_page

  

  from .util import ProgressBar, json_dumps, serializable

  from .build_config import MockProfile
@@ -421,6 +422,23 @@ 

              print("Updating packages in {0} from {1}/{2}.\nPlease be aware that it may take a few minutes "

                    "to duplicate backend data.".format(project.full_name, srcownername, srcprojectname))

  

+     def action_list_builds(self, args):

+         """ Method called when the 'list-builds' action has been selected by

+         the user.

+ 

+         :param args: argparse arguments provided by the user

+         """

+         ownername, projectname = self.parse_name(args.project)

+         pagination = {"limit": 100}

+ 

+         builds_list = self.client.build_proxy.get_list(ownername, projectname,

+                                                        pagination=pagination)

+         while builds_list:

+             for build in builds_list:

+                 print("{0}\t{1}\t{2}".format(build["id"], build["source_package"]["name"],

+                                              build["state"]))

+             builds_list = next_page(builds_list)

+ 

      def action_mock_config(self, args):

          """ Method called when the 'mock-config' action has been selected by the

          user.
@@ -891,6 +909,12 @@ 

      parser_delete.add_argument("--confirm", action="store_true", help="Confirm forking into existing project")

      parser_delete.set_defaults(func="action_fork")

  

+     parser_builds = subparsers.add_parser("list-builds", help="List all builds in the project")

+     parser_builds.add_argument("project", help="Which project's builds should be listed.\

+                                Can be just a name of the project or even in format\

+                                username/project or @groupname/project.")

+     parser_builds.set_defaults(func="action_list_builds")

+ 

      #########################################################

      ###             Source-type related options           ###

      #########################################################

I think this is not the correct indentation. The line should IMHO start aligned with build["id"] from the previous one.

The help for other commands also says that it can be in a owner/project format, which is IMHO useful information.

parser_list_packages.add_argument("copr",
                                  help="The copr repo to list the packages of. Can be just name of project or even in format owner/project.")

This feels quite redundant because we already have

class BuildProxy(BaseProxy):
    # ...
    def get_list(self, ownername, projectname, packagename=None, status=None, pagination=None):

Can we also have some beaker tests for this feature, please?
I think it's the ideal candidate for them.

rebased onto 1d8496426386d4bae11ba30eea0426e535b8266c

3 years ago

Thanks for the review, I've addressed your feedback.

rebased onto 833c9963cccc34e5417048404e4bb8304f9cdd5b

3 years ago

Thank you.
I would just squash those commits together but otherwise LGTM.

rebased onto 3f45b32

3 years ago

Pull-Request has been merged by frostyx

3 years ago