#6411 List NEEDSPONSOR tickets with POST or ASSIGNED status
Closed 2 months ago by kevin. Opened 2 years ago by yecheng.
https://github.com/yceh/fedora-infrastructure-forked.git master  into  master

Add fields for acessing FAS
yceh • 2 years ago  
List NEEDSPONSOR tickets with POST or ASSIGNED status
yceh • 2 years ago  
scripts/review-stats/review-stats.cfg
file modified
+2

@@ -6,4 +6,6 @@

  {% endif %}

  username = "package-review@lists.fedoraproject.org"

  password = "{{ packagereviewbugzilla }}"

+ adminfasusername = "{{ FASusername }}"

+ adminfaspassword = "{{ FASpasswd }}"

  maxpackages = 5

scripts/review-stats/review-stats.py
file modified
+77 -8

@@ -14,7 +14,7 @@

  from genshi.template import TemplateLoader

  from optparse import OptionParser

  from validate import Validator

- 

+ from fedora.client.fas2 import AccountSystem

  VERSION = "4.1"

  

  # Red Hat's bugzilla

@@ -39,6 +39,10 @@

  # So the bugzilla module has some way to complain

  logging.basicConfig()

  

+ fasusernamemap = {}

+ isnewpackager = {}

+ nonefasinfo = {}

+ approvedpackagers = {}

  

  def parse_commandline():

      usage = "usage: %prog [options] -c <bugzilla_config> -d <dest_dir> -t <template_dir>"

@@ -76,6 +80,8 @@

          url = string(default='https://bugzilla.redhat.com/xmlrpc.cgi')

          username = string()

          password = string()

+         adminfasusername = string()

+         adminfaspassword = string()

      '''.splitlines()

  

      cfg = ConfigObj(file, configspec=spec)

@@ -177,7 +183,7 @@

              'alias', 'assigned_to', 'product', 'creator', 'creator_id', 'status', 'resolution',

              'component', 'blocks', 'depends_on', 'summary',

              'whiteboard', 'flags']

-     querydata['bug_status'] = ['NEW', 'ASSIGNED', 'MODIFIED']

+     querydata['bug_status'] = ['NEW', 'ASSIGNED', 'MODIFIED','POST']

      querydata['product'] = ['Fedora', 'Fedora EPEL']

      querydata['component'] = ['Package Review']

      querydata['query_format'] = 'advanced'

@@ -190,6 +196,7 @@

      dbprint("Running main query.")

      t = time.time()

      bugs = filter(lambda b: b.id not in trackers, bz.query(querydata))

+     bugs = bugs[200:500]

      dbprint("Done, took {0:.2f}.".format(time.time() - t))

  

      for bug in bugs:

@@ -337,6 +344,49 @@

          return 1

      return 0

  

+ def get_fas_username(bug):

+     ''' find the fas name of package submiter based on first few comments'''

+     comments = bug.getcomments()

+     # some review ticket have an empty first comment(ex.1282012)

+     for comment in comments:

+         username_idx = comment['text'].find('sername')

+         if username_idx != -1:

+             fas_username = comment['text'][username_idx:]

+             break

+     try:

+         fas_username = fas_username[fas_username.find(':')+1:]

+         if fas_username[0] == '\n':

+ 			fas_username = fas_username[1:][:fas_username.find('\n')]

+         def stripe_spaces(fas_username):

+             if fas_username[0] == ' ':

+                 return fas_username[1:]

+                 stripe_spaces(fas_username)

+             else:

+                 return fas_username

+     except UnboundLocalError:

+         dbprint(comment)

+         return ''

+     #most have space before fas username, but some don't.(ex.879752)

+ 

+ 

+ 

+ def is_new_packager(bug):

+     #global variable used: isnewpackager,fasusernamemap,nonefasinfo

+     try:

+         return isnewpackager[bug.reporter]

+     except KeyError :

+         fasusername = get_fas_username(bug)

+         if fasusername == '' :

+             try:

+                 nonefasinfo[bug.reporter].append(bug)

+             except KeyError :

+                 nonefasinfo[bug.reporter] = [bug]

+             return False

+         else:

+             fasusernamemap[bug.reporter] = fasusername

+             isnewpackager[bug.reporter] = not (fasusername in approvedpackagers)

+             return not (fasusername in approvedpackagers)

+ 

  

  def select_needsponsor(bug, bugd):

      wb = string.lower(bug.whiteboard)

@@ -345,11 +395,12 @@

              and NEEDSPONSOR in bugd['blocks']

              and LEGAL not in bugd['blocks']

              and bug.bug_status != 'CLOSED'

-             and nobody(bug.assigned_to) == '(Nobody)'

              and wb.find('buildfails') < 0

              and wb.find('notready') < 0

              and wb.find('stalledsubmitter') < 0

-             and wb.find('awaitingsubmitter') < 0):

+             and wb.find('awaitingsubmitter') < 0

+             and (nobody(bug.assigned_to) == '(Nobody)'

+             or  is_new_packager(bug))):

          return 1

      return 0

  

@@ -411,6 +462,14 @@

          rowclass = 'bz_row_even'

      return rowclass

  

+ def rowclass_accepted_packages(bug, count):

+     rowclass = 'bz_row_odd'

+     if (bug.bug_status in ['ASSIGNED','POST']

+         or nobody(bug.assigned_to) != '(Nobody)'):

+         rowclass = 'bz_state_NEEDSPONSOR'

+     elif count % 2 == 1:

+         rowclass = 'bz_row_even'

+     return rowclass

  

  # The data from a standard row in a bug list

  def std_row(bug, rowclass):

@@ -516,7 +575,8 @@

  

  def report_needsponsor(bugs, bugdata, loader, usermap, tmpdir, subs):

      data = deepcopy(subs)

-     data['description'] = 'This page lists all new NEEDSPONSOR tickets (those without the fedora-review flag set).'

+     data['description'] = ('This page lists new NEEDSPONSOR tickets submitted by new packagers who are not yet sponsored.'

+             'Tickets colored green are already being assigned for review.')

      data['title'] = 'NEEDSPONSOR tickets'

      curreporter = ''

      curcount = 0

@@ -526,7 +586,14 @@

      for i in bugs:

          if select_needsponsor(i, bugdata[i.id]):

              selected.append(i)

- 

+     #cleanup bugs that have no fas username

+     for i in nonefasinfo:

+         try:

+             if isnewpackager[i]:

+                 selected += nonefasinfo[i]

+         except KeyError :

+             pass

+     

      # Determine the oldest reported bug

      for i in selected:

          if i.reporter not in oldest:

@@ -538,7 +605,6 @@

      selected.sort(key=lambda a: oldest[a.reporter])

  

      for i in selected:

-         rowclass = rowclass_plain(data['count'])

          r = i.reporter

  

          if curreporter != r:

@@ -549,7 +615,7 @@

              data['packagers'].append({'email': r, 'name': name, 'oldest': human_date(oldest[r]), 'bugs': []})

              curreporter = r

              curcount = 0

- 

+         rowclass = rowclass_accepted_packages(i, curcount)

          data['packagers'][-1]['bugs'].append(std_row(i, rowclass))

          data['count'] += 1

          curcount += 1

@@ -630,6 +696,9 @@

      bz = bugzilla.RHBugzilla(url=config['url'], cookiefile=None, user=config['username'], password=config['password'])

      t = time.time()

      (bugs, bugdata, usermap) = run_query(bz)

+     approvedpackagers=[]

+     for indi in AccountSystem(username=config['adminfasusername'],password=config['adminfaspassword']).group_members('packager'):

+         approvedpackagers.append(indi.toDict()['username'].encode('utf-8'))

      querytime = time.time() - t

  

      # Don't bother running this stuff until the query completes, since it fails

no initial comment

Find new packagers waiting for sponsor by checking whether the FAS account name listed in the first few comments of tickets blocking NEEDSPONSOR is already in packager member list of FAS, rather than checking whether the ticket is unassigned.
Notes:
1.adminfasusername and adminfaspassword fields needs to be added to review-stats.cfg for querying the member list.
2.Some new tickets are coloured green because they are assigned to user other than nobody@fedoraproject.org
Potential issues:
The script will stall rather than throwing exception if the network was disconnected while waiting for response from server. Probably, no timeout was set.

rebased onto 5ae344b

7 months ago

rebased onto 0a3276a

3 months ago

Oh, sorry I didn't see this PR at all.

The fedora-infrastructure git repo (ie, here) has only been for a place to have things in public back when we used puppet and our puppet repo was private.

These days our ansible repo is public: https://infrastructure.fedoraproject.org/infra/ansible.git

Can you make a patch against that repo instead and send it to the infrastructure list ?

Or just wait a week or two and we hope to drop the git repo here and replace it with the above repo, so we can then accept prs for it.

Thanks for the patch and if you prefer I can try and redo it against the ansible repo.

Pull-Request has been closed by kevin

2 months ago