@donedeal0/codefather
Version:
Codefather protects your codebase by controlling who can change what. Set authorization levels, lock down files, and enforce your rules—offline via CLI or online with GitHub Actions.
35 lines (34 loc) • 22.2 kB
JavaScript
#!/usr/bin/env node
import v from'fs';import B,{resolve,relative,dirname}from'path';import {transform}from'esbuild';import {getOctokit,context}from'@actions/github';function w(e){console.log(e,`
\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2840\u2804\u2840\u2804\u2840\u2804\u2840\u2880\u2804\u2840\u2880\u2804\u2840\u2804\u2840\u2804\u2804\u2804\u2804\u2880\u2804\u2804\u2840\u2880\u2804\u2804\u2840\u2804\u2804\u2804\u2804
\u2804\u2804\u2804\u2808\u2804\u2801\u2808\u2804\u2802\u2804\u2840\u2804\u2804\u2840\u2880\u2804\u2880\u2804\u2880\u2804\u2840\u2820\u2804\u2804\u2802\u2801\u2808\u2840\u2804\u2804\u2801\u2804\u2804\u2804\u2802\u2804\u2840\u2801\u2804\u2804
\u2804\u2804\u2804\u2801\u2804\u2801\u2804\u2801\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2880\u2804\u2840\u2840\u2804\u2804\u2801\u2880\u2881\u2804\u2840\u2820\u2804\u2801\u2848\u2880\u2808\u2880\u2820\u2804\u2880\u2804\u2804
\u2804\u2804\u2804\u2804\u2801\u2804\u2801\u2804\u2802\u2804\u2860\u28F2\u28A7\u28F3\u2873\u286F\u28DF\u28FC\u28BD\u28FA\u28DC\u2875\u28DD\u289C\u2894\u2814\u2845\u2882\u2804\u2804\u2801\u2804\u2880\u2804\u2840\u2804\u2840\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2808\u2804\u2808\u2804\u2880\u2847\u286F\u287A\u28B5\u28F3\u28BF\u28FB\u28DF\u28FF\u28FF\u28FD\u28BE\u28DD\u28AE\u2873\u28E3\u28A3\u2823\u2843\u2885\u2802\u2810\u2808\u2804\u2804\u2880\u2804\u2840\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2808\u2804\u2810\u2880\u2807\u286A\u2878\u2878\u28DD\u28FE\u28FB\u28EF\u28FF\u28FF\u287F\u28DF\u28FF\u287D\u28D7\u286F\u28DE\u289C\u288C\u2822\u2861\u2888\u2808\u2804\u2801\u2808\u2804\u2804\u2804\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2810\u2804\u2808\u2806\u2815\u2894\u2821\u28D3\u28D5\u28B7\u28FB\u28FD\u28DD\u28B7\u28FB\u28FB\u28DD\u28AF\u28BF\u2839\u2838\u2851\u2845\u2815\u2820\u2820\u2804\u2805\u2804\u2802\u2804\u2802\u2808\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2804\u2802\u2821\u2851\u288D\u280C\u284A\u28A2\u28A2\u28B1\u283C\u28FA\u28BF\u289D\u282E\u28AA\u28EA\u287A\u28D8\u285C\u28D1\u28A4\u2890\u2805\u2821\u2882\u2821\u2810\u2840\u2880\u2820\u2810\u2804\u2810\u2804\u2804
\u2804\u2804\u2804\u2804\u2888\u2880\u2821\u2828\u2862\u2851\u284C\u2854\u286E\u2877\u28ED\u28A7\u28F3\u282D\u28EA\u28F2\u28FC\u28FE\u28DF\u28FB\u28FD\u28FA\u28F8\u28DC\u288C\u2886\u288C\u2810\u2804\u2840\u2804\u2840\u2804\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2804\u2820\u2804\u280C\u2862\u2875\u283A\u281E\u281F\u281B\u282F\u281F\u281F\u281D\u286B\u2897\u281F\u281D\u2819\u2809\u280A\u2811\u2809\u2809\u2809\u2811\u2892\u2820\u2801\u2804\u2840\u2820\u2804\u2804\u2804\u2804
\u2804\u2804\u2804\u2810\u2840\u2804\u2804\u2805\u286A\u2804\u2802\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2880\u2895\u2894\u2804\u2804\u2804\u2804\u2840\u2820\u2810\u2808\u2880\u2804\u2820\u2804\u2841\u2804\u2840\u2802\u2820\u2804\u2804
\u2804\u2804\u2804\u2820\u2804\u2804\u2802\u2851\u2804\u2804\u2820\u2810\u2804\u2801\u2804\u2801\u2804\u2804\u28B8\u28FF\u28FF\u2842\u2804\u2804\u2880\u2804\u2840\u2804\u2802\u2820\u2810\u2804\u2850\u2840\u2802\u2880\u2810\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2890\u2804\u2802\u2895\u2885\u2884\u2804\u28C0\u2840\u2884\u2804\u2801\u28C0\u28D4\u2875\u28FF\u28EF\u2827\u2863\u28E2\u2860\u2880\u2880\u2860\u2810\u2880\u2890\u2820\u2880\u2810\u2804\u2804\u2804\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2810\u2854\u2880\u2818\u28BD\u28FB\u28F6\u28E5\u28C9\u2825\u2863\u28F1\u28F7\u283B\u28EA\u28FB\u28F7\u2863\u2863\u28AB\u28DE\u28D7\u2866\u2875\u28BB\u283A\u2878\u2810\u2840\u2810\u2804\u2802\u2840\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2802\u2818\u2840\u2814\u2880\u2811\u280D\u280D\u287D\u28FD\u28FF\u28FB\u2802\u2877\u28EF\u287F\u28DF\u287F\u280C\u2846\u2818\u28FE\u28FB\u28B5\u2895\u2814\u2880\u2801\u2820\u2808\u2840\u2801\u2804\u2840\u2804\u2804
\u2804\u2804\u2804\u2804\u2820\u2804\u2804\u2850\u28B0\u2888\u2884\u2831\u28BD\u28FA\u28B3\u2801\u28C8\u2804\u2804\u2808\u280A\u2808\u2804\u2804\u28A1\u28D0\u28AB\u28AF\u2862\u288A\u2884\u28AA\u2828\u2820\u2804\u2840\u2801\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2802\u2804\u2802\u2820\u2831\u28D5\u2863\u2847\u284F\u28AE\u2895\u28F8\u28FE\u2820\u2804\u2804\u2804\u2802\u2804\u2804\u280C\u289F\u28DC\u2875\u28EF\u28B7\u2874\u2845\u2805\u2842\u2820\u2804\u2888\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2802\u2801\u2880\u2808\u280C\u286A\u289D\u28BE\u28DD\u28CE\u2812\u280F\u2819\u2820\u2811\u2801\u2806\u2812\u2810\u2810\u2809\u2880\u2811\u28CD\u287F\u28FD\u287D\u2842\u2815\u2804\u2804\u2802\u2880\u2820\u2804\u2804
\u2804\u2804\u2804\u2810\u2804\u2848\u2804\u2880\u2804\u280A\u280D\u28AF\u28F7\u28CF\u288A\u2880\u28C8\u28E0\u28E4\u28E4\u28E4\u28F4\u28F6\u28B6\u28F4\u28A4\u28AC\u28CC\u28BB\u287A\u287B\u2808\u2804\u2802\u2804\u2802\u2840\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2802\u2880\u2810\u2804\u2804\u2802\u2821\u2811\u2815\u2805\u2855\u287D\u2851\u2841\u2809\u2809\u2809\u2809\u2801\u2801\u2801\u2820\u288A\u280A\u2822\u2808\u2804\u2828\u2804\u2804\u2801\u2810\u2880\u2808\u2804\u2804
\u2804\u2804\u2804\u2808\u2880\u2804\u2804\u2808\u2840\u2882\u2810\u2804\u2802\u2801\u2820\u2801\u2862\u286A\u28E2\u28F2\u28E6\u28D6\u2854\u2864\u2868\u2850\u2884\u280C\u2820\u2808\u2810\u2804\u2802\u2820\u2801\u2888\u2820\u2804\u2804\u2804
\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2882\u2804\u2822\u2802\u2808\u2840\u2808\u2840\u2808\u2830\u2839\u2868\u2811\u2851\u2815\u2815\u280A\u280C\u280C\u2804\u2810\u2804\u2802\u2801\u2888\u2804\u2841\u2810\u2804\u2850\u2880\u2802\u2804
\u2804\u2804\u2804\u2804\u2850\u2884\u2811\u2804\u2804\u2847\u2841\u2804\u2804\u2804\u2804\u2848\u2804\u2804\u2804\u2804\u2880\u2820\u2804\u2802\u2880\u2810\u2804\u2848\u2820\u2808\u2804\u2804\u2820\u2810\u2804\u2801\u2820\u2804\u2804\u2804
\u2804\u2804\u2840\u288A\u2828\u2880\u288A\u2804\u2828\u2842\u2842\u2804\u2802\u2804\u2880\u2804\u2820\u2804\u2802\u2804\u2804\u2840\u2820\u2804\u2804\u2804\u2810\u2804\u2804\u2840\u2801\u2840\u2802\u2804\u2802\u2801\u2828\u2804\u2805\u2804
\u2804\u2804\u2810\u2804\u2882\u2822\u2840\u2804\u282C\u2804\u2802\u2805\u2840\u2808\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2840\u2802\u2804\u2802\u2804\u2880\u2804\u2804\u2804\u2804\u2802\u2804\u2802\u2888\u2810\u2804\u2804
\u2804\u2804\u2808\u2840\u2804\u2804\u2804\u2804\u2805\u2805\u2810\u2804\u2804\u2840\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2801\u2804\u2804\u2804\u2802\u2890\u2804\u2810\u2804
\u2804\u2804\u2804\u2804\u2804\u2802\u2804\u2804\u2815\u2808\u2842\u2840\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2804\u2808\u2804\u2804\u2802\u2804
`);}var y=e=>e.replace(/\\/g,"/");function z(e){if(e instanceof RegExp)return e;let t=y(e.trim().replace(/^\.?\/+/,""));t.endsWith("/")&&(t+="**");let o=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\xA7\xA7").replace(/\*/g,"[^/]*").replace(/§§/g,".*");return new RegExp(`^${o}$`)}function b(e,t,o){let s=t.map(z),i=y(o);return e.filter(r=>{let n=y(r.trim()),u=y(relative(i,n));return s.some(a=>a.test(u))})}var m={success:"\x1B[32m",error:"\x1B[31m",warning:"\x1B[33m",info:"\x1B[37m"};var G=["\u2713 _committers_, you handled the code with respect. The family is proud.","\u2713 _committers_, you honored the business. That\u2019s how trust is built.","\u2713 _committers_: You made your bones with this one.","\u2713 _committers_: Code like this keeps the peace in the family.","\u2713 _committers_, you handled your business quietly. The family respects discretion.","\u2713 _committers_: That\u2019s how professionals operate. You moved smart, you moved clean.","\u2713 _committers_: You didn\u2019t just commit, you showed class.","\u2713 _committers_: Good code, good manners, good reputation.","\u2713 _committers_, your respect for the code speaks louder than a thousand pull requests.","\u2713 _committers_: You moved with honor. You\u2019re earning your place at my table.","\u2713 _committers_, there\u2019s no fanfare for doing it right\u2014but I noticed how you behave.","\u2713 _committers_: This code needs no apology. That's rare.","\u2713 _committers_, that\u2019s not just a commit\u2026 it\u2019s a tribute to our rules.","\u2713 _committers_: If only all developers had your instincts.","\u2713 _committers_: You touched the code and made it better. That's art.","\u2713 _committers_, you've earned silence. I don't critique perfection.","\u2713 _committers_: You walked in, did your job, and left no trace. That\u2019s respect.","\u2713 _committers_, this code smells like loyalty.","\u2713 _committers_: Quiet hands. Clean commit. No questions.","\u2713 _committers_, you just raised the bar. Be careful, others might trip over it.","\u2713 _committers_: Even my consigliere asked who wrote that one."],T=["\u{10102} _committers_: Look how you massacred my code... Contact _goodfellas_ and make amend.","\u{10102} _committers_: You will sleep with the fishes! Don't touch this part! Get in touch with _goodfellas_ to arrange things.","\u{10102} _committers_: This ain't how we do things. Talk to _goodfellas_ before there's a sit-down.","\u{10102} _committers_: You crossed a line. Only _goodfellas_ can fix this mess.","\u{10102} _committers_: Unauthorized moves like that? I'm very disappointed.","\u{10102} _committers_: You broke the rules. That\u2019s not how this family operates.","\u{10102} _committers_: You acted solo. This thing of ours? It's built on trust. Get _goodfellas_ involved.","\u{10102} _committers_: You broke sacred ground. Only _goodfellas_ can grant access.","\u{10102} _committers_: I saw the commit\u2026 I ain't smiling. Speak with _goodfellas_.","\u{10102} _committers_: Mistakes like these leave bodies in the file history. Get it cleared with _goodfellas_.","\u{10102} _committers_: You stepped on protected turf. You want forgiveness? Start with _goodfellas_.","\u{10102} _committers_, you took a liberty that wasn't yours. Talk to _goodfellas_ before things escalate.","\u{10102} _committers_: You moved without permission. This isn\u2019t amateur hour.","\u{10102} _committers_, the code isn't yours to break. _goodfellas_ handle this part.","\u{10102} _committers_: You crossed the line. Now you owe the Family a conversation.","\u{10102} _committers_, disrespect is easy. Fixing it? That\u2019s a job for _goodfellas_.","\u{10102} _committers_: You made a move without my blessing. Never wise.","\u{10102} _committers_, you broke a rule and you broke trust. _goodfellas_ can guide you back.","\u{10102} _committers_, touch a sacred file and you better bring permission.","\u{10102} _committers_, your fingerprint's on a forbidden section. Better clean it up with _goodfellas_.","\u{10102} _committers_: There are rules for a reason. Get _goodfellas_ involved before this becomes a problem.","\u{10102} _committers_: You messed with the wrong files.","\u{10102} _committers_: That commit screams betrayal. _goodfellas_ heard it loud and clear.","\u{10102} _committers_: You broke something built on trust. Now it needs fixing.","\u{10102} _committers_, this act smells like ambition. Careful\u2014ambition got Fredo killed.","\u{10102} _committers_: You acted like a enemy. We don\u2019t deal with enemies.","\u{10102} _committers_: That move lacked honor. Fix it or fade out.","\u{10102} _committers_: You weren\u2019t subtle. You weren\u2019t careful. Call _goodfella_ to clear things out."],W={success:["\u2713 Thank you _committers_. You respected the codebase.","\u2713 Grazie mille, _committers_! You're a honorable developer.","\u2713 _committers_: You respected the limits. Your friendship is greatly appreciated.","\u2713 _committers_: You're a stand-up developer. Loyalty like this doesn't go unnoticed.","\u2713 _committers_, this commit is art. You\u2019ve earned your cannoli.",...G],"multi-success":["\u2713 Thank you _committers_. You respected the codebase.","\u2713 Grazie mille, _committers_! You're honorable developers.","\u2713 _committers_: You respected the limits. Youre friendship is greatly appreciated.","\u2713 _committers_: You're stand-up developers. Loyalty like that doesn't go unnoticed.","\u2713 _committers_, this commit is art. You\u2019ve earned your cannolis.",...G],error:["\u{10102} _committers_! You need permission from my trusted associate: _goodfellas_. Nobody touches this without approval.","\u{10102} _committers_: You messed up. Big. _goodfellas_ is already talking.",...T],"multi-errors":["\u{10102} _committers_! You need permission from my trusted associates: _goodfellas_. Nobody touches this without approval.","\u{10102} _committers_: You messed up. Big. _goodfellas_ are already talking.",...T],warning:["\u26A0 _committers_: You ain't made, but we\u2019ll let it slide this time. Get _goodfellas_ to vouch for ya.","\u26A0 _committers_: Be cautious if you don't want to get whacked... Contact _goodfellas_ to clear things out.","\u26A0 _committers_: You get a pass this time, but don't push it. Get in touch _goodfellas_ and you'll be alright.","\u26A0 _committers_: You danced too close to the edge. Get _goodfellas_ to keep you in the circle.","\u26A0 _committers_: You\u2019re walking a fine line\u2026 _goodfellas_ might have your back.","\u26A0 _committers_: You pulled a risky move. Lucky for you, it\u2019s just a warning. Consult _goodfellas_.","\u26A0 _committers_: One more slip and it\u2019s concrete shoes. Chat with _goodfellas_ first.","\u26A0 _committers_: You're not made yet. Show respect\u2014talk to _goodfellas_.","\u26A0 _committers_: I'm watching you. Walk the line and speak to _goodfellas_.","\u26A0 _committers_: You skirted the rules. Make peace with _goodfellas_ before the next job.","\u26A0 _committers_: Careful\u2026 Loyalty is proven, not assumed. _goodfellas_ can guide you.","\u26A0 _committers_: Almost crossed the line. Best check with _goodfellas_ next time.","\u26A0 _committers_: You're not in trouble\u2026 yet. _goodfellas_ can keep it that way.","\u26A0 _committers_: One toe over the line. _goodfellas_ can help you get back.","\u26A0 _committers_, you bent the rules. Just don\u2019t break them.","\u26A0 _committers_: You slipped once. That\u2019s all you get.","\u26A0 _committers_: Your code raised a brow. Next time, _goodfellas_ better be in the room.","\u26A0 _committers_, almost took a wrong turn. _goodfellas_ know the right way.","\u26A0 _committers_: You grazed the edge. Next time, show respect.","\u26A0 _committers_: You\u2019re walking a thin line. Watch your step.","\u26A0 _committers_, you touched sensitive ground. The Don expects caution.","\u26A0 _committers_: We\u2019re watching. Keep it clean and consult _goodfellas_.","\u26A0 _committers_: The rules were tested... but not broken. Don't test them again.","\u26A0 _committers_: You flirted with danger. But I don't flirt back.","\u26A0 _committers_: Careful. That path leads to 'meeting in a warehouse' territory.","\u26A0 _committers_: You touched something you shouldn\u2019t. The Family is watching.","\u26A0 _committers_: Not a full betrayal... but you danced too close.","\u26A0 _committers_: You\u2019re whispering around rules. They don\u2019t whisper back.","\u26A0 _committers_: One more move like that and you\u2019ll need a favor. We don\u2019t like favors.","\u26A0 _committers_: You've entered a gray zone. Hope you brought a flashlight\u2014and permission."],"no-changes":["\u2713 You haven't modified a single file, _committers_. It's nice to be low-key, but one day, you gotta take action.","\u2713 Tutto bene, _committers_. No suspicious activity detected.","\u2713 _committers_, you kept your hands clean\u2026 This time.","\u2713 No files touched, _committers_. The silence is noted.","\u2713 _committers_: You walked in, made no noise, left without a trace. Respect.","\u2713 _committers_, sometimes doing nothing is the smartest move. Sometimes.","\u2713 _committers_: You didn\u2019t touch a thing. Makes me wonder what you're planning.","\u2713 No activity detected, _committers_. Either you're careful, or you're lazy.","\u2713 _committers_, staying under the radar, huh? Just don\u2019t make it a habit.","\u2713 _committers_: I\u2019ve seen quieter nights... but not many.","\u2713 _committers_: No footprints, no fingerprints. You\u2019re either clean or hiding something.","\u2713 _committers_, you moved like a ghost. But ghosts don\u2019t write good code.","\u2713 _committers_, the files sleep undisturbed. You know the value of silence.","\u2713 _committers_: Nothing changed, but I see your discipline.","\u2713 _committers_: Sometimes doing nothing is wisdom. Today was one of those times.","\u2713 _committers_, the files are untouched\u2014but your reputation isn\u2019t.","\u2713 _committers_: You showed restraint. I respect restraint."],"not-found":["\u{10102} The codefather.ts file doesn't exist. Maybe someone whacked it?"],"no-gitconfig":["\u{10102} You don't have a git config... Are you a cop?"]};function U(e,t){let o=[...new Set(e.map(({name:s})=>s?.trim()).filter(Boolean))];return new Intl.ListFormat("en",{style:"long",type:t}).format(o)}function H(e,t={}){let{committers:o=[],goodfellas:s=[]}=t;return e==="success"&&o?.length>1?"multi-success":e==="error"&&s?.length>1?"multi-errors":e}function f(e,t={}){let o=H(e,t),s=W[o],i=s[Math.floor(Math.random()*s.length)];if(t.goodfellas){let n=U(t.goodfellas,"disjunction")||"a goodfella";i=i.replace("_goodfellas_",n);}if(t.committers){let n=U(t.committers,"conjunction")||"Committer";i=i.replace("_committers_",n);}return i.replace(/_committers_/g,"Committer").replace(/_goodfellas_/g,"a goodfella").replace(/\s+/g," ").trim().replace(/^./,r=>r.toUpperCase())}function E(){let e=process.cwd(),t=resolve(e,"codefather.json"),o=resolve(e,"codefather.ts");return v.existsSync(o)?dirname(o):v.existsSync(t)?dirname(t):e}function F(e,t){return e?.length?t.every(({name:o})=>e.some(s=>o&&s.name===o)):false}function $(e,t){return t.filter(({name:o})=>!e.some(s=>o&&s.name===o))}function I(e,t,o){let{caporegimes:s=[],rules:i=[]}=o,r={errors:[],warnings:[]};if(F(s,t))return r;let u=E();for(let a of i){let p=b(e,a.match,u);if(p.length===0)continue;let g=[...s,...a.goodfellas||[]];if(a.crews&&o.crews){let d=a.crews.flatMap(h=>o.crews?.[h]).filter(Boolean);g.push(...d);}if(!F(g,t)){let d=a?.allowForgiveness?"warning":"error",h=$(a.goodfellas,t),k=`${a.message||f(d,{goodfellas:g,committers:h})}
Unauthorized files:
${p.map(D=>` - ${D}`).join(`
`)}
`;a.allowForgiveness?r.warnings.push(k):r.errors.push(k);}}return r}function A(e){try{return JSON.parse(e)}catch{throw new Error("Your codefather.json file is invalid. You gotta respect the rules if you want my help.")}}async function O(e){return import(e)}async function P(){try{let e=process.cwd(),t=B.resolve(e,"codefather.ts"),o=B.resolve(e,"codefather.json");if(v.existsSync(t)){let s=v.readFileSync(t,"utf-8"),{code:i}=await transform(s,{loader:"ts",format:"esm"}),r=`data:text/javascript;base64,${Buffer.from(i).toString("base64")}`,n=await O(r);return n?.default?.default||n?.default||n}if(v.existsSync(o)){let s=v.readFileSync(o,"utf-8");return A(s)}throw new Error(f("not-found"))}catch(e){throw new Error(e instanceof Error?e.message:String(e))}}function j(e,t=true){let o=e.errors.length?m.error:e.warnings.length?m.warning:void 0;t&&o&&w(o);for(let s of e.warnings)console.log(m.warning,s);for(let s of e.errors)console.log(m.error,s);e.errors.length>0&&process.exit(1);}var C=class e{octokit;constructor(){this.octokit=getOctokit(process.env.GITHUB_TOKEN||"");}static init(){return new e}getUniqueCommittersList(t){let o=new Set;return t.reduce((s,{committer:i})=>{let r=i?.login;if(!r)return s;if(!o.has(r)){let u={name:r};r&&o.add(r),s.push(u);}return s},[])}async getCommitters(t,o=true){let{data:s}=await this.octokit.rest.pulls.listCommits({owner:context.repo.owner,repo:context.repo.repo,pull_number:t});if(!s.length)throw new Error("\u{10102} Couldn't find any commits in this pull request.");let i=o?s:[s[0]],r=this.getUniqueCommittersList(i);if(r.length===0)throw new Error("\u{10102} The username could not be found in the commit author metadata.");return r}getPullRequestID(){let t=context.payload?.pull_request?.number;return t||(console.log(m.error,"\u{10102} Missing pull request number. Can't proceed without it."),process.exit(1)),t}async getModifiedFiles(t){let{data:o}=await this.octokit.rest.pulls.listFiles({owner:context.repo.owner,repo:context.repo.repo,pull_number:t});return o.map(s=>resolve(s.filename))}getRelevantReviewers(t,o,s){let{caporegimes:i=[],rules:r=[]}=s,n=s.codeReviews?.autoAssignCaporegimes?i:[],u=[],a=process.cwd();for(let d of t){let h=r.find(R=>b([d],R.match,a).length>0);h&&(h.crews&&u.push(...h.crews),n.push(...h.goodfellas||[]));}let p=n.filter(({name:d})=>!o.some(h=>d&&h.name===d)),g=[...new Set(p.map(({name:d})=>d).filter(Boolean))],x=[...new Set(u)];return {reviewers:g,crews:x}}async assignReviewers(t,o,s,i){let{reviewers:r,crews:n}=this.getRelevantReviewers(o,s,i);if(r.length!==0)return await this.octokit.rest.pulls.requestReviewers({owner:context.repo.owner,repo:context.repo.repo,pull_number:t,reviewers:r,...n.length>0?{team_reviewers:n}:{}})}};async function q(){try{!process.env.CI&&process.env.GITHUB_ACTIONS!=="true"&&(console.log(m.error,"\u{10102} This script is intended to run inside GitHub Actions."),process.exit(1)),process.env.GITHUB_TOKEN||(console.log(m.error,"\u{10102} GITHUB_TOKEN is missing. Pass it via `env:` in your workflow to make this work."),process.exit(1));let e=await P(),t=e.options?.showAscii??!0,o=C.init(),s=o.getPullRequestID(),i=await o.getCommitters(s,e.options?.vouchForAllCommitters),r=await o.getModifiedFiles(s),n=I(r,i,e),u=e.codeReviews?.autoAssignGoodfellas??!0;return !v.existsSync(B.resolve(process.cwd(),"./.github/CODEOWNERS"))&&(u||e.codeReviews?.autoAssignCaporegimes)&&await o.assignReviewers(s,r,i,e),n.errors.length===0&&n.warnings.length===0&&(t&&w(m.success),console.log(m.success,f("success",{committers:i})),process.exit(0)),j(n,t)}catch(e){let t=e instanceof Error?e.message:String(e);console.log(m.error,t),process.exit(1);}}q();