11import { Probot } from 'probot' ;
22
3- import { labels } from '../labels.js' ;
43import PullRequest from '../classes/PullRequest.js' ;
4+ import { labels } from '../labels.js' ;
5+ import { syncPullRequestLabels } from '../labels/labelCalculator.js' ;
56
67export default ( app : Probot ) => {
78 app . on ( [ 'pull_request.opened' , 'pull_request.reopened' ] , async context => {
@@ -14,7 +15,7 @@ export default (app: Probot) => {
1415 await pr . setTitle ( title ) ;
1516 }
1617
17- await pr . addLabel ( 'wip' ) ;
18+ await syncPullRequestLabels ( context , pr ) ;
1819 } ) ;
1920
2021 app . on ( [ 'pull_request.edited' ] , async context => {
@@ -30,36 +31,23 @@ export default (app: Probot) => {
3031 return ;
3132 }
3233
33- if ( pr . wip ) {
34- await pr . addLabel ( 'wip' ) ;
35- } else {
36- await pr . addLabel ( 'readyForReview' ) ;
37- }
34+ await syncPullRequestLabels ( context , pr ) ;
3835 } ) ;
3936
4037 app . on ( [ 'pull_request.synchronize' ] , async context => {
4138 const pr = new PullRequest ( context ) ;
4239
43- if ( pr . wip || pr . data . draft ) return ;
44-
45- const reviewStatus = await pr . getReviewStatus ( ) ;
46-
47- await pr . addLabel ( reviewStatus ) ;
40+ await syncPullRequestLabels ( context , pr ) ;
4841 } ) ;
4942
5043 app . on ( [ 'pull_request.closed' ] , async context => {
5144 const pr = new PullRequest ( context ) ;
52-
53- if ( pr . data . merged_at !== null ) {
54- await pr . addLabel ( 'merged' ) ;
55- } else {
56- await pr . clearLabels ( ) ;
57- }
45+ await syncPullRequestLabels ( context , pr ) ;
5846 } ) ;
5947
6048 app . on ( [ 'pull_request.converted_to_draft' ] , async context => {
6149 const pr = new PullRequest ( context ) ;
62- await pr . addLabel ( 'wip' ) ;
50+ await syncPullRequestLabels ( context , pr ) ;
6351 } ) ;
6452
6553 app . on ( [ 'pull_request.ready_for_review' ] , async context => {
@@ -68,6 +56,6 @@ export default (app: Probot) => {
6856 const title = pr . data . title . replace ( labels . wip . regex ?? '' , '' ) ;
6957 await pr . setTitle ( title ) ;
7058
71- await pr . addLabel ( 'readyForReview' ) ;
59+ await syncPullRequestLabels ( context , pr ) ;
7260 } ) ;
7361} ;
0 commit comments