def fill_values(values, ui, api_server, finalize=False): cache = bzauth.load_configuration(ui, api_server, BINARY_CACHE_FILENAME) if 'PRODUCT' in values: values['PRODUCT'], values['COMPONENT'] = choose_prodcomponent(ui, cache, values['PRODUCT'], values['COMPONENT'], finalize=finalize) if 'PRODVERSION' in values: if values['PRODVERSION'] == '<default>' and values['PRODUCT'] not in [None, '<choose-from-menu>']: values['PRODVERSION'] = get_default_version(ui, api_server, values['PRODUCT']) ui.write("Using default version '%s' of product %s\n" % (values['PRODVERSION'].encode('utf-8'), values['PRODUCT'].encode('utf-8'))) # 'finalize' means we need the final values. (finalize will be set to false # for prepopulating fields that will be displayed in a form) if not finalize: return values if 'BUGTITLE' in values: if values['BUGTITLE'] in [None, '<required>']: values['BUGTITLE'] = ui.prompt(_("Bug title:"), default='') if 'BUGCOMMENT0' in values: if values['BUGCOMMENT0'] in [None, '<required>']: values['BUGCOMMENT0'] = ui.prompt(_("Bug description:"), default='') if 'ATTACHMENT_DESCRIPTION' in values: if values['ATTACHMENT_DESCRIPTION'] in [None, '<required>']: values['ATTACHMENT_DESCRIPTION'] = ui.prompt(_("Patch description:"), default=values['ATTACHMENT_FILENAME']) return values
def get_default_version(ui, api_server, product): c = bzauth.load_configuration(ui, api_server, BINARY_CACHE_FILENAME) versions = c['product'].get(product, {}).get('version') if not versions: raise util.Abort(_("Product %s has no versions") % product) # Ugh! /configuration returns the versions in sorted order, which makes it # impossible to determine the default. If there's something like # "unspecified" in the list, prefer that for now, until bzapi gets fixed. # https://bugzilla.mozilla.org/show_bug.cgi?id=723170 uns = [v for v in versions if v.startswith("un")] return uns[-1] if uns else versions[-1]
def flag_type_id(ui, api_server, config_cache_filename, flag_name, product, component): """ Look up the numeric type id for the 'review' flag from the given bugzilla server """ configuration = bzauth.load_configuration(ui, api_server, config_cache_filename) if not configuration or not configuration["flag_type"]: raise util.Abort(_("Could not find configuration object")) # Get the set of flag ids used for this product::component prodflags = configuration['product'][product]['component'][component]['flag_type'] flagdefs = configuration['flag_type'] flag_ids = [id for id in prodflags if flagdefs[str(id)]['name'] == flag_name] if len(flag_ids) != 1: raise util.Abort(_("Could not find unique %s flag id") % flag_name) return flag_ids[0]