1+ module . exports = async ( { github, context} ) => {
2+ const owner = context . repo . owner ;
3+ const repo = context . repo . repo ;
4+ const pr = context . payload . pull_request ;
5+ const prNumber = pr . number ;
6+ const username = pr . user . login ;
7+
8+ const backendFiles = [ ] ;
9+ const webFiles = [ ] ;
10+ const mobileFiles = [ ] ;
11+ const devopsFiles = [ ] ;
12+
13+ const labels = [ ] ;
14+ let primaryArea = null ;
15+ let reviewer = null ;
16+
17+ try {
18+ const changedFiles = await github . paginate (
19+ github . rest . pulls . listFiles ,
20+ {
21+ owner,
22+ repo,
23+ pull_number : prNumber
24+ }
25+ ) ;
26+
27+ changedFiles . forEach ( ( file ) => {
28+ const fileName = file . filename ;
29+
30+ if ( fileName . startsWith ( 'apps/backend/' ) ) {
31+ backendFiles . push ( fileName ) ;
32+ } else if ( fileName . startsWith ( 'apps/web/' ) ) {
33+ webFiles . push ( fileName ) ;
34+ } else if ( fileName . startsWith ( 'apps/mobile/' ) ) {
35+ mobileFiles . push ( fileName )
36+ } else if ( fileName . startsWith ( '.github/' ) || fileName . startsWith ( 'infra/' ) || fileName . startsWith ( 'terraform/' ) ) {
37+ devopsFiles . push ( fileName )
38+ }
39+ } )
40+
41+
42+ if ( backendFiles . length > 0 ) {
43+ labels . push ( 'backend' )
44+
45+ if ( ! primaryArea ) {
46+ primaryArea = 'backend' ;
47+ reviewer = '@Harxhit'
48+ }
49+ }
50+ if ( mobileFiles . length > 0 ) {
51+ labels . push ( 'mobile' ) ;
52+ if ( ! primaryArea ) {
53+ primaryArea = 'mobile' ;
54+ reviewer = '@blankirigaya'
55+ }
56+ }
57+ if ( webFiles . length > 0 ) {
58+ labels . push ( 'web' ) ;
59+ if ( ! primaryArea ) {
60+ primaryArea = 'web' ;
61+ reviewer = '@ShantKhatri'
62+ }
63+ }
64+ if ( devopsFiles . length > 0 ) {
65+ labels . push ( 'devops' )
66+ if ( ! primaryArea ) {
67+ primaryArea = 'devops'
68+ reviewer = '@ShantKhatri'
69+ }
70+ }
71+
72+ if ( labels . length === 0 ) {
73+ return ;
74+ }
75+
76+ await github . rest . issues . addLabels ( {
77+ owner,
78+ repo,
79+ issue_number : prNumber ,
80+ labels
81+ } ) ;
82+ const body = `Hi @${ username } ,
83+
84+ Thanks for opening this pull request.
85+
86+ This PR has been automatically classified based on the files modified.
87+
88+ ### Applied Labels
89+
90+ ${ labels . map ( label => `- ${ label } ` ) . join ( '\n' ) }
91+
92+ ### Primary Review Area
93+
94+ * ${ primaryArea }
95+
96+ ### Reviewer
97+
98+ ${ reviewer } has been identified as the primary reviewer for this pull request.
99+
100+ If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer.
101+
102+ Thank you for your contribution! ` ;
103+
104+
105+ await github . rest . issues . createComment ( {
106+ owner,
107+ repo,
108+ issue_number : prNumber ,
109+ body : body
110+ } ) ;
111+
112+ } catch ( error ) {
113+ console . error ( error )
114+ }
115+
116+ }
0 commit comments