|
| 1 | +name: Rule Based Reviewer Assignment |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + pull-requests: write |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + assign_reviewers: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout base repo |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ref: ${{ github.event.pull_request.base.ref }} |
| 20 | + fetch-depth: 2 |
| 21 | + |
| 22 | + - name: Get PR Author and Files Changed |
| 23 | + id: pr-info |
| 24 | + run: | |
| 25 | + # Get PR author |
| 26 | + echo "author=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV |
| 27 | +
|
| 28 | + FILES_CHANGED=$(GH_TOKEN="${{ secrets.PAT_CODE_REVIEWER_AUTOMATION }}" gh api \ |
| 29 | + repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files \ |
| 30 | + --jq '.[].filename') |
| 31 | +
|
| 32 | + CORE_FILES_CHANGED="false" |
| 33 | + for FILE in $FILES_CHANGED; do |
| 34 | + echo "$FILE" |
| 35 | + if [[ ! "$FILE" =~ ^modules/[^/]+$ && ! "$FILE" =~ ^test/ && ! "$FILE" =~ ^integrationExamples/ ]]; then |
| 36 | + CORE_FILES_CHANGED="true" |
| 37 | + echo "Found a core change" |
| 38 | + break |
| 39 | + fi |
| 40 | + done |
| 41 | +
|
| 42 | + echo "core_change=$CORE_FILES_CHANGED" >> $GITHUB_ENV |
| 43 | +
|
| 44 | + - name: Assign Reviewers Based on Rules |
| 45 | + run: | |
| 46 | + # Load PR author and core change flag |
| 47 | + AUTHOR=${{ env.author }} |
| 48 | + CORE_CHANGE=${{ env.core_change }} |
| 49 | + echo "PR Author: $AUTHOR" |
| 50 | + echo "Core Change: $CORE_CHANGE" |
| 51 | +
|
| 52 | + # Define groups |
| 53 | + PREBID_LEAD_ENG=("dgirardi") |
| 54 | + PREBID_ENG=("mkomorski") |
| 55 | + VOLUNTEERS=($(GH_TOKEN="${{ secrets.PAT_CODE_REVIEWER_AUTOMATION }}" gh api \ |
| 56 | + -H "Accept: application/vnd.github+json" \ |
| 57 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 58 | + /orgs/prebid/teams/pbjs-reviewers/members \ |
| 59 | + --jq '.[].login')) |
| 60 | + MEMBERS=("3link" "abazylewicz-id5" "Abyfall" "adserver-online" "aleksatr" "alexander-kislitsyn" "AlexBVolcy" "AlexisBRENON" "alexsavelyev" "anastasiiapankivFS" "And1sS" "andre-gielow-ttd" "andreacastello" "andrewmarriott-aws" "andyblackwell" "ankit-thanekar007" "AntoxaAntoxic" "apukh-magnite" "arielmtk" "armando-fs" "AvinashKapre" "bbaresic" "BenBoonsiri" "bjorn-lw" "bokelley" "bretg" "bsardo" "Bugxyb" "bwnodak" "bwschmidt" "carlosfelix" "cciocov" "ccorbo" "chicoman25" "Compile-Ninja" "CTMBNara" "danielsao" "dbemiller" "dbridges12" "decaffeinatedio" "deepthivenkat" "el-chuck" "EmilNadimanov" "Enigo" "EvgeniiMunin" "farukcam" "fatihkaya84" "Fawke" "fliccione" "FlorentDancy" "florianerl" "freestarjonny" "Fuska1" "gargcreation1992" "Gershon-Brainin" "gilbertococchi" "github-matthieu-wipliez" "github-mickael-leclerc" "github-richard-depierre" "gmcgrath11" "gmiedlar-ox" "gpolaert" "guscarreon" "gwhigs" "harpere" "harrykingriches" "headertag" "heatherboveri" "hhhjort" "hjeong12" "ianwow" "idettman" "ikp4success" "IrinLen" "jaiminpanchal27" "jclou" "jdcauley" "jdelhommeau" "jdwieland8282" "jefftmahoney" "jeremy-greenbids" "jerrycychen" "JimTharioAmazon" "jlaso" "jlquaccia" "jlukas79" "jlustig11" "jney" "joedrew" "JoelPM" "johnwier" "JonGoSonobi" "jsnellbaker" "jsut" "justadreamer" "jwrosewell" "kamermans" "kapil-tuptewar" "katherynhrabik" "khang-vu-ttd" "kim-ng93" "kiril-kalchev" "kkharma" "kvnsw" "laurb9" "lcorrigall" "linux019" "lksharma" "lpagnypubstack" "lucor" "MaksymTeqBlaze" "mansinahar" "marki1an" "matthewlane" "MaxSmileWanted" "mbellomi" "mercuryyy" "michachen" "Miroku87" "mkendall07" "mmoschovas" "mmullin" "monis0395" "monisq" "muuki88" "mwilsonmagnite" "nassimlounadi" "ncolletti" "Net-burst" "nhedley" "nicgallardo" "nickllerandi" "NikhilGopalChennissery" "OlenaPostindustria" "ollyburns" "omerDotan" "onkarvhanumante" "optidigital-prebid" "oronno" "osazos" "osulzhenko" "ourcraig" "passani" "patmmccann" "paulborile" "pb-pete" "pdamoc" "peixunzhang" "piotrj-rtbh" "pkowalski-id5" "pm-abhinav-deshpande" "pm-asit-sahoo" "pm-azhar-mulla" "pm-harshad-mane" "pm-isha-bharti" "pm-jaydeep-mohite" "pm-kapil-tuptewar" "pm-komal-kumari" "pm-manasi-moghe" "pm-nikhil-vaidya" "pm-nitin-nimbalkar" "pm-nitin-shirsat" "pm-priyanka-bagade" "pm-priyanka-deshmane" "pm-saurabh-narkhede" "pm-shivam-soni" "pm-tanishka-vishwakarma" "pm-viral-vala" "Pratik3307" "protonate" "Pubmatic-Dhruv-Sonone" "PubMatic-OpenWrap" "Pubmatic-Supriya-Patil" "PyjamaWarrior" "QuentinGallard" "rBeefrz" "richmtk" "rickyblaha" "rimaburder-index" "rishi-parmar" "rmloveland" "robertrmartinez" "schernysh" "scr-oath" "sebastienrufiange" "sebmil-daily" "sergseven" "shahinrahbariasl" "ShriprasadM" "sigma-software-prebid" "SKOCHERI" "smenzer" "snapwich" "softcoder594" "sonali-more-xandr" "ssundahlTTD" "StavBenShlomoBrowsi" "stephane-ein" "teads-antoine-azar" "tej656" "teqblaze-yurii" "thyagram-aws" "ValentinPostindustria" "VeronikaSolovei9" "vivekyadav15" "vkimcm" "vraybaud" "wi101" "yq-yang-qin" "ysfbsf" "YuriyVelichkoPI" "yuva-inmobi-1" "zapo" "zhongshixi" "zxPhoenix") |
| 61 | +
|
| 62 | + # Helpers |
| 63 | + pick_random_from_group() { |
| 64 | + local group=("$@") |
| 65 | + echo "${group[$RANDOM % ${#group[@]}]}" |
| 66 | + } |
| 67 | +
|
| 68 | + pick_random_from_group_excluding() { |
| 69 | + local excludes_str="$1" |
| 70 | + shift |
| 71 | + local group=("$@") |
| 72 | + IFS=" " read -r -a excludes <<< "$excludes_str" |
| 73 | +
|
| 74 | + local filtered=() |
| 75 | + for user in "${group[@]}"; do |
| 76 | + local skip=false |
| 77 | + for ex in "${excludes[@]}"; do |
| 78 | + if [[ "$user" == "$ex" ]]; then |
| 79 | + skip=true |
| 80 | + break |
| 81 | + fi |
| 82 | + done |
| 83 | + if [[ "$skip" == false ]]; then |
| 84 | + filtered+=("$user") |
| 85 | + fi |
| 86 | + done |
| 87 | +
|
| 88 | + if [[ ${#filtered[@]} -eq 0 ]]; then |
| 89 | + echo "" |
| 90 | + else |
| 91 | + echo "${filtered[$RANDOM % ${#filtered[@]}]}" |
| 92 | + fi |
| 93 | + } |
| 94 | +
|
| 95 | + REVIEWERS=() |
| 96 | +
|
| 97 | + if [[ " ${PREBID_LEAD_ENG[@]} " =~ " ${AUTHOR} " ]]; then |
| 98 | + # Prebid Lead authored --> 2 Reviewers (Non-Lead Prebid + Volunteer) |
| 99 | + echo "Prebid Lead engineer authored the PR" |
| 100 | + REVIEWERS+=("$(pick_random_from_group "${PREBID_ENG[@]}")") |
| 101 | + REVIEWERS+=("$(pick_random_from_group "${VOLUNTEERS[@]}")") |
| 102 | + elif [[ " ${PREBID_ENG[@]} " =~ " ${AUTHOR} " ]]; then |
| 103 | + echo "Prebid engineer authored the PR" |
| 104 | + # Any other Prebid engineer authored --> 2 Reviewers (Lead Prebid + Volunteer) |
| 105 | + REVIEWERS+=("${PREBID_LEAD_ENG[0]}") |
| 106 | + REVIEWERS+=("$(pick_random_from_group "${VOLUNTEERS[@]}")") |
| 107 | + elif [[ "$CORE_CHANGE" == "true" ]]; then |
| 108 | + # Core rules apply to anyone else --> 2 Reviewers (Lead Prebid + Volunteer) |
| 109 | + echo "Core change detected, applying core rules" |
| 110 | + REVIEWERS+=("${PREBID_LEAD_ENG[0]}") |
| 111 | + REVIEWERS+=("$(pick_random_from_group_excluding "$AUTHOR" "${VOLUNTEERS[@]}")") |
| 112 | + elif [[ " ${MEMBERS[@]} " =~ " ${AUTHOR} " ]]; then |
| 113 | + echo "Non-core, member authored" |
| 114 | + # Non-core, member authored --> 1 Reviewer (Non-Lead Prebid) |
| 115 | + REVIEWERS+=("$(pick_random_from_group "${PREBID_ENG[@]}")") |
| 116 | + else |
| 117 | + echo "Non-core, non-member authored" |
| 118 | + # Non-core, non-member authored --> 1 Reviewer (Volunteer) |
| 119 | + REVIEWERS+=("$(pick_random_from_group_excluding "$AUTHOR" "${VOLUNTEERS[@]}")") |
| 120 | + fi |
| 121 | +
|
| 122 | + echo "Reviewers selected: ${REVIEWERS[@]}" |
| 123 | +
|
| 124 | + # Assign reviewers using gh api |
| 125 | + for R in "${REVIEWERS[@]}"; do |
| 126 | + if [[ -n "$R" ]]; then |
| 127 | + echo "Assigning reviewer: $R" |
| 128 | + gh api \ |
| 129 | + --method POST \ |
| 130 | + -H "Accept: application/vnd.github+json" \ |
| 131 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 132 | + repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \ |
| 133 | + -f reviewers[]="$R" |
| 134 | + fi |
| 135 | + done |
| 136 | +
|
| 137 | + env: |
| 138 | + GITHUB_TOKEN: ${{ secrets.PAT_CODE_REVIEWER_AUTOMATION }} |
0 commit comments