morgan pushed to branch main at The Tor Project / Applications / tor-browser-build

Commits:

2 changed files:

Changes:

  • tools/browser/README.md
    1 1
     # Tools
    
    2 2
     
    
    3
    +### generate-bugzilla-triage-csv
    
    4
    +
    
    5
    +This script generates a csv file (to be hosted on Google Sheets) which enumerates all of the Bugzilla issues resolved for a particular Firefox release as defined by Mozilla's bug-tracker AND the set of patches in a provided commit range. Each entry will include the Bugzilla issue title and a link which creates an issue in [tpo/applications/tor-browser](https://gitlab.torproject.org/tpo/applications/tor-browser) for further review.
    
    6
    +
    
    7
    +This script should be invoked, the output written to a .csv file, and uploaded to a shared Google Sheets spreadsheet for team triage + review.
    
    8
    +
    
    9
    +#### Prerequisites
    
    10
    +
    
    11
    +- The user must create the following soft-links:
    
    12
    +    - `/tools/browser/torbrowser` -> `/path/to/local/tor-browser.git`
    
    13
    +
    
    14
    +#### Usage
    
    15
    +
    
    16
    +```
    
    17
    +Usage: ./tools/browser/generate-bugzilla-triage-csv <ff-version> <begin-commit> <end-commit> <gitlab-audit-issue> <reviewers...>
    
    18
    +
    
    19
    +ff-version             rapid-release Firefox version to audit
    
    20
    +begin-commit           starting gecko-dev commit of this Firefox version
    
    21
    +end-commit             ending gecko-dev commit of this Firefox version
    
    22
    +gitlab-audit-issue     tor-browser GitLab issue number for this audit
    
    23
    +reviewers...           space-separated list of reviewers responsible for this audit
    
    24
    +```
    
    25
    +
    
    26
    +#### Examples
    
    27
    +
    
    28
    +Generates a spreadsheet derived from the Firefox 129 resolved issues and all commits between `FIREFOX_NIGHTLY_128_END` and `FIREFOX_NIGHTLY_129_END`. New issues will automatically link themslves to [tor-browser#43303](https://gitlab.torproject.org/tpo/applications/tor-browser/-/issues/43303). The requested reviewers will be morgan, pierov, and henry.
    
    29
    +
    
    30
    +```bash
    
    31
    +./tools/browser/generate-bugzilla-triage-csv 129 FIREFOX_NIGHTLY_128_END FIREFOX_NIGHTLY_129_END 43303 morgan pierov henry
    
    32
    +```
    
    33
    +
    
    3 34
     ### sign-tag
    
    4 35
     
    
    5 36
     This script gpg signs a git tag associated with a particular browser commit in the user's tor-browser.git or mullvad-browser.git repo.
    

  • tools/browser/generate-bugzilla-triage-csv
    1
    +#!/usr/bin/env bash
    
    2
    +
    
    3
    +# gitlab labels for review tickets
    
    4
    +browser_label="15.0 stable"
    
    5
    +esr_label="esr-140"
    
    6
    +
    
    7
    +# prints to stderr
    
    8
    +function echoerr() { echo "$@" 1>&2; }
    
    9
    +
    
    10
    +script_dir=$(dirname "${BASH_ARGV0:-$0}")
    
    11
    +
    
    12
    +# help dialog
    
    13
    +if [ "$#" -lt 5 ]; then
    
    14
    +    echoerr "Usage: $0 <ff-version> <begin-commit> <end-commit> <gitlab-audit-issue> <reviewers...>"
    
    15
    +    echoerr
    
    16
    +    echoerr "ff-version             rapid-release Firefox version to audit"
    
    17
    +    echoerr "begin-commit           starting gecko-dev commit of this Firefox version"
    
    18
    +    echoerr "end-commit             ending gecko-dev commit of this Firefox version"
    
    19
    +    echoerr "gitlab-audit-issue     tor-browser GitLab issue number for this audit"
    
    20
    +    echoerr "reviewers...           space-separated list of reviewers responsible for this audit"
    
    21
    +    echoerr ""
    
    22
    +    echoerr "Example:"
    
    23
    +    echoerr ""
    
    24
    +    echoerr "$0 129 FIREFOX_NIGHTLY_128_END FIREFOX_NIGHTLY_129_END 43303 morgan pierov henry"
    
    25
    +    exit 1
    
    26
    +fi
    
    27
    +
    
    28
    +# exit on error
    
    29
    +set -e
    
    30
    +
    
    31
    +
    
    32
    +# Ensure various required tools are available
    
    33
    +function check_exists() {
    
    34
    +    local cmd=$1
    
    35
    +    if ! which ${cmd} > /dev/null ; then
    
    36
    +        echoerr "missing ${cmd} dependency"
    
    37
    +        exit 1
    
    38
    +    fi
    
    39
    +}
    
    40
    +
    
    41
    +check_exists git
    
    42
    +check_exists jq
    
    43
    +check_exists mktemp
    
    44
    +check_exists perl
    
    45
    +check_exists printf
    
    46
    +check_exists sed
    
    47
    +check_exists sort
    
    48
    +check_exists touch
    
    49
    +check_exists uniq
    
    50
    +check_exists wget
    
    51
    +
    
    52
    +# Assign arguments to named variables
    
    53
    +firefox_version=$1
    
    54
    +git_begin=$2
    
    55
    +git_end=$3
    
    56
    +audit_issue=$4
    
    57
    +reviewers="${@:5}"
    
    58
    +
    
    59
    +# Check valid Firefox version
    
    60
    +if ! [[ "${firefox_version}" =~ ^[1-9][0-9]{2}$ ]]; then
    
    61
    +    echoerr "invalid Firefox version (probably)"
    
    62
    +    exit 1
    
    63
    +fi
    
    64
    +
    
    65
    +# Check valid Gitlab issue number
    
    66
    +if ! [[ "${audit_issue}" =~ ^[1-9][0-9]{4}$ ]]; then
    
    67
    +    echoerr "invalid gitlab audit issue number (probably)"
    
    68
    +    exit 1
    
    69
    +fi
    
    70
    +
    
    71
    +#
    
    72
    +# Encoding/Decoding Functions
    
    73
    +#
    
    74
    +
    
    75
    +# escape " and \
    
    76
    +function json_escape() {
    
    77
    +    local input="$1"
    
    78
    +    echo "${input}" | sed 's/["\]/\\"/g'
    
    79
    +}
    
    80
    +
    
    81
    +
    
    82
    +# un-escape \"
    
    83
    +function jq_unescape() {
    
    84
    +    local input="$1"
    
    85
    +    echo "${input}" | sed 's/\\"/"/g'
    
    86
    +}
    
    87
    +
    
    88
    +# change quotes to double-quotes
    
    89
    +function csv_escape() {
    
    90
    +    local input="$1"
    
    91
    +    echo "${input}" | sed 's/"/""/g'
    
    92
    +}
    
    93
    +
    
    94
    +# we need to urlencode the strings used in the new issue link
    
    95
    +function url_encode() {
    
    96
    +    local input="$1"
    
    97
    +    echo "${input}" | perl -MURI::Escape -wlne 'print uri_escape $_'
    
    98
    +}
    
    99
    +
    
    100
    +
    
    101
    +#
    
    102
    +# Create temp json files
    
    103
    +#
    
    104
    +git_json=$(mktemp -t git-audit-${firefox_version}-XXXXXXXXXXX.json)
    
    105
    +bugzilla_json=$(mktemp -t bugzilla-audit-${firefox_version}-XXXXXXXXXXX.json)
    
    106
    +union_json=$(mktemp -t union-audit-${firefox_version}-XXXXXXXXXXX.json)
    
    107
    +touch "${git_json}"
    
    108
    +touch "${bugzilla_json}"
    
    109
    +touch "${union_json}"
    
    110
    +
    
    111
    +function json_cleanup {
    
    112
    +    rm -f "${git_json}"
    
    113
    +    rm -f "${bugzilla_json}"
    
    114
    +    rm -f "${union_json}"
    
    115
    +    popd > /dev/null
    
    116
    +}
    
    117
    +pushd "${script_dir}/torbrowser" > /dev/null
    
    118
    +trap json_cleanup EXIT
    
    119
    +
    
    120
    +#
    
    121
    +# Generate Git Commit Triage List
    
    122
    +#
    
    123
    +
    
    124
    +# Try and extract bug id and summary from git log
    
    125
    +# Mozilla's commits are not always 100% consistently named, so this
    
    126
    +# regex is a bit flexible to handle various inputs such as:
    
    127
    +# "Bug 1234 -", "Bug 1234:", "Bug Bug 1234 -", "[Bug 1234] -", " bug 1234 -".
    
    128
    +sed_extract_id_summary="s/^[[ ]*[bug –-]+ ([1-9][0-9]*)[]:\., –-]*(.*)\$/\\1 \\2/pI"
    
    129
    +
    
    130
    +# Generate a json array of objects in the same format as bugzilla: {component: string, id: number, summary: string}
    
    131
    +printf "[\n" >> "${git_json}"
    
    132
    +
    
    133
    +first_object=true
    
    134
    +git log --format='%s' $git_begin..$git_end  \
    
    135
    +| sed -En "${sed_extract_id_summary}" \
    
    136
    +| sort -h \
    
    137
    +| uniq \
    
    138
    +| while IFS= read -r line; do
    
    139
    +    read -r id summary <<< "${line}"
    
    140
    +    summary=$(json_escape "${summary}")
    
    141
    +
    
    142
    +    # json does not allow trailing commas
    
    143
    +    if [[ "${first_object}" = true ]]; then
    
    144
    +        first_object=false
    
    145
    +    else
    
    146
    +        printf ",\n" >> "${git_json}"
    
    147
    +    fi
    
    148
    +
    
    149
    +    printf "  { \"component\": \"Unknown\", \"id\": %s, \"summary\": \"%s\" }" ${id} "${summary}" >> "${git_json}"
    
    150
    +done
    
    151
    +printf "\n]\n" >> "${git_json}"
    
    152
    +
    
    153
    +#
    
    154
    +# Download Bugzilla Triage List
    
    155
    +#
    
    156
    +
    
    157
    +# search for:
    
    158
    +# + Product is NOT "Thunderbird,Calander,Chat Core,MailNews Core" (&f1=product&n1=1&o1=anyexact&v1=Thunderbird%2CCalendar%2CChat%20Core%2CMailNews%20Core). AND
    
    159
    +# + Target Milestone contains "${firefox_version}" (e.g. 115 Branch or Firefox 115) (&f2=target_milestone&o2=substring&v2=${firefox_version}).
    
    160
    +# "&limit=0" shows all matching bugs.
    
    161
    +
    
    162
    +query_tail="&f1=product&n1=1&o1=anyexact&v1=Thunderbird%2CCalendar%2CChat%20Core%2CMailNews%20Core&f2=target_milestone&o2=substring&v2=${firefox_version}&limit=0"
    
    163
    +
    
    164
    +bugzilla_query="https://bugzilla.mozilla.org/buglist.cgi?${query_tail}"
    
    165
    +bugzilla_json_query="https://bugzilla.mozilla.org/rest/bug?include_fields=id,component,summary${query_tail}"
    
    166
    +
    
    167
    +wget "${bugzilla_json_query}" -O ${bugzilla_json}
    
    168
    +
    
    169
    +
    
    170
    +#
    
    171
    +# Create Union of these two sets of issues
    
    172
    +#
    
    173
    +
    
    174
    +# bugzilla array is actually on a root object: { bugs: [...] }
    
    175
    +jq -s '[ (.[0].bugs)[], (.[1])[] ] | group_by(.id) | map(.[0])' "${bugzilla_json}" "${git_json}" > "${union_json}"
    
    176
    +
    
    177
    +#
    
    178
    +# Generate Triage CSV
    
    179
    +#
    
    180
    +
    
    181
    +echo "\"Review\",,\"Bugzilla Component\",\"Bugzilla Bug\""
    
    182
    +
    
    183
    +jq '. | sort_by([.component, .id])[] | "\(.id)|\(.component)|\(.summary)"' ${union_json} \
    
    184
    +| while IFS='|' read -r id component summary; do
    
    185
    +
    
    186
    +    # bugzilla info
    
    187
    +    id="${id:1}"
    
    188
    +    component="${component:0}"
    
    189
    +    summary="${summary:0:-1}"
    
    190
    +    summary=$(jq_unescape "${summary}")
    
    191
    +    # short summary for gitlab issue title
    
    192
    +    [[ ${#summary} -gt 80 ]] && summary_short="${summary:0:77}..." || summary_short="${summary}"
    
    193
    +
    
    194
    +    # filter out some issue types that we never care about
    
    195
    +    skip_issue=false
    
    196
    +
    
    197
    +    # skip `[wpt-sync] Sync PR`
    
    198
    +    if [[ "${summary}" =~ ^\[wpt-sync\]\ Sync\ PR.*$ ]]; then
    
    199
    +        skip_issue=true
    
    200
    +    # skip `Crash in [@` and variants
    
    201
    +    elif [[ "${summary}" =~ ^Crash[esin\ ]*\ \[\@.*$ ]]; then
    
    202
    +        skip_issue=true
    
    203
    +    # skip `Assertion failuire: `
    
    204
    +    elif [[ "${summary}" =~ ^Assertion\ failure:\ .*$ ]]; then
    
    205
    +        skip_issue=true
    
    206
    +    # skip `Hit MOZ_CRASH`
    
    207
    +    elif [[ "${summary}" =~ ^Hit\ MOZ_CRASH.*$ ]]; then
    
    208
    +        skip_issue=true
    
    209
    +    fi
    
    210
    +
    
    211
    +    if [[ "${skip_issue}" = true ]]; then
    
    212
    +        echoerr "Skipped Bugzilla ${id}: ${summary_short}"
    
    213
    +    else
    
    214
    +        csv_summary=$(csv_escape "${summary}")
    
    215
    +        csv_component=$(csv_escape "${component}")
    
    216
    +
    
    217
    +        # parent issue
    
    218
    +        bugzilla_url="https://bugzilla.mozilla.org/show_bug.cgi?id=${id}"
    
    219
    +        # review issue title
    
    220
    +        new_issue_title=$(url_encode "Review Mozilla ${id}: ${summary_short}")
    
    221
    +        # review issue description + labeling (14.0 stable, FF128-esr, Next)
    
    222
    +        new_issue_description=$(url_encode "### Bugzilla: ${bugzilla_url}")%0A$(url_encode "/label ~\"${browser_label}\" ~\"${esr_label}\" ~\"Bugzilla Review\" ~Next")%0A$(url_encode "/relate tpo/applications/tor-browser#${audit_issue}")%0A%0A$(url_encode "<!-- briefly describe why this issue needs further review -->")%0A
    
    223
    +        # url which create's new issue with title and description pre-populated
    
    224
    +        new_issue_url="https://gitlab.torproject.org/tpo/applications/tor-browser/-/issues/new?issue[title]=${new_issue_title}&issue[description]=${new_issue_description}"
    
    225
    +
    
    226
    +        # this link will start the creation of a new gitlab issue to review
    
    227
    +        create_issue=$(csv_escape "=HYPERLINK(\"${new_issue_url}\", \"New Issue\")")
    
    228
    +        bugzilla_link=$(csv_escape "=HYPERLINK(\"${bugzilla_url}\", \"Bugzilla ${id}: ${csv_summary}\")")
    
    229
    +
    
    230
    +        echo "FALSE,\"${create_issue}\",\"${csv_component}\",\"${bugzilla_link}\","
    
    231
    +    fi
    
    232
    +done
    
    233
    +
    
    234
    +echo
    
    235
    +echo "\"Triaged by:\""
    
    236
    +for reviewer in $reviewers; do
    
    237
    +    reviewer=$(csv_escape "${reviewer}")
    
    238
    +    echo "\"FALSE\",\"${reviewer}\""
    
    239
    +done
    
    240
    +echo
    
    241
    +
    
    242
    +bugzilla_query="=HYPERLINK(\"${bugzilla_query}\", \"Bugzilla query\")"
    
    243
    +echo \"$(csv_escape "${bugzilla_query}")\"