#450 Module-overview allows filtering by owner
Merged 2 years ago by onosek. Opened 2 years ago by onosek.

file modified
+11 -3
@@ -3510,7 +3510,7 @@ 

              else:

                  raise

  

-     def module_overview(self, limit=10, finished=True):

+     def module_overview(self, limit=10, finished=True, owner=None):

          """

          Show the overview of the latest builds in MBS

  
@@ -3518,6 +3518,7 @@ 

              to display. This defaults to 10.

          :param bool finished: a boolean that determines if only finished or

              unfinished module builds should be displayed. This defaults to True.

+         :param str owner: list only builds of that user.

          """

          # Don't let the user cause problems by specifying a negative limit

          if limit < 1:
@@ -3540,12 +3541,13 @@ 

              states = [build_states['init'], build_states['wait'],

                        build_states['build']]

  

-         def _get_module_builds(state):

+         def _get_module_builds(state, owner=None):

              """

              Private function that is used for multithreading later on to get

              the desired amount of builds for a specific state.

  

              :param state: an integer representing the build state to query for

+             :param owner: a string; to query for that owner's builds

              :return: a generator to yield dictionaries of the builds found

              """

              total = 0
@@ -3560,6 +3562,8 @@ 

                  'verbose': True,

                  'per_page': per_page

              }

+             if owner:

+                 params['owner'] = owner

              while total < limit:

                  params['page'] = page

                  response = requests.get(baseurl, params=params, timeout=30)
@@ -3592,9 +3596,13 @@ 

          # Eventually, the MBS should support a range of states but for now, we

          # have to be somewhat wasteful and query per state

          module_builds = pool.map(

-             lambda x: list(_get_module_builds(state=x)), states)

+             lambda x: list(_get_module_builds(state=x, owner=owner)), states)

          # Make one flat list with all the modules

          module_builds = [item for sublist in module_builds for item in sublist]

+         # Sort the list with a secondary key first. It should prevent the situation

+         # that two builds with same id (its status was changed during the queries)

+         # are in the list and the record with older status is removed.

+         module_builds.sort(key=lambda x: x['time_modified'], reverse=True)

          # Sort the list of builds to be oldest to newest

          module_builds.sort(key=lambda x: x['id'])

          # Only grab the desired limit starting from the newest builds

file modified
+13 -1
@@ -1242,6 +1242,12 @@ 

          self.module_overview_parser.add_argument(

              '--limit', default=10, type=int,

              help='The number of most recent module builds to display')

+         group = self.module_overview_parser.add_mutually_exclusive_group()

+         group.add_argument(

+             '--owner', metavar='FAS_ID', help='List only items of that owner')

+         group.add_argument(

+             '--mine', action='store_true', default=False,

+             help='Use current Kerberos name or username')

          self.module_overview_parser.set_defaults(

              command=self.module_overview)

  
@@ -2331,9 +2337,15 @@ 

      def module_overview(self):

          """Show the overview of the latest builds in the MBS"""

          self.set_module_api_url()

+         owner = self.args.owner

+         if self.args.mine:

+             owner = self.cmd.user

+             if not owner:

+                 raise rpkgError("Can not obtain current Kerberos name or username")

          self.cmd.module_overview(

              self.args.limit,

-             finished=(not self.args.unfinished))

+             finished=(not self.args.unfinished),

+             owner=owner)

  

      def module_scratch_build(self):

          # A module scratch build is just a module build with --scratch

file modified
+8 -4
@@ -2671,7 +2671,8 @@ 

                      'owner': 'jkaluza',

                      'state_name': 'ready',

                      'stream': 'master',

-                     'version': '20171011093314'

+                     'version': '20171011093314',

+                     'time_modified': '2019-06-03T15:12:06Z',

                  },

                  {

                      'id': 1099,
@@ -2680,7 +2681,8 @@ 

                      'owner': 'jkaluza',

                      'state_name': 'ready',

                      'stream': 'master',

-                     "version": "20171011092951"

+                     "version": "20171011092951",

+                     'time_modified': '2019-06-03T14:46:02Z',

                  }

              ],

              'meta': {
@@ -2699,7 +2701,8 @@ 

                      'scratch': True,

                      'state_name': 'failed',

                      'stream': 'master',

-                     'version': '20171011173928'

+                     'version': '20171011173928',

+                     'time_modified': '2019-06-03T14:47:12Z',

                  },

                  {

                      'id': 1094,
@@ -2708,7 +2711,8 @@ 

                      'owner': 'mprahl',

                      'state_name': 'failed',

                      'stream': 'master',

-                     'version': '20171010151103'

+                     'version': '20171010151103',

+                     'time_modified': '2019-06-03T14:45:26Z',

                  }

              ],

              'meta': {

Adds additional arguments to command fedpkg module-overview:
--owner - param is added to mbs query and shows only builds of that owner
--mine - use current Kerberos user (or system username if Kerberos is not present) for filtering
Arguments are mutually exclusive.

JIRA: COMPOSE-3538
Fixes: https://pagure.io/fedpkg/issue/325

Signed-off-by: Ondrej Nosek onosek@redhat.com

Pull-Request has been merged by onosek

2 years ago