@@ -43,8 +43,12 @@ static async Task AsyncMain(IConfigurationRoot config)
4343 var gitHubConfig = config . GetSection ( "github" ) ;
4444 var query = new Query ( gitHubConfig [ "token" ] ) ;
4545
46+ Console . WriteLine ( $ "GitHub organisation: { gitHubConfig [ "organization" ] } ") ;
47+ Console . WriteLine ( $ "GitHub team: { gitHubConfig [ "team" ] } ") ;
48+ Console . WriteLine ( $ "GitHub repository: { gitHubConfig [ "repository" ] } ") ;
49+
4650 var members = await query . GetTeamMembers ( gitHubConfig [ "organization" ] , gitHubConfig [ "team" ] ) ;
47- Console . WriteLine ( $ "Org ' { gitHubConfig [ "organization" ] } ' team ' { gitHubConfig [ "team" ] } ' members ({ members . Count } )") ;
51+ Console . WriteLine ( $ "Team members ({ members . Count } ): ") ;
4852 foreach ( var member in members )
4953 {
5054 Console . WriteLine ( $ " { member . Login } ") ;
@@ -53,7 +57,7 @@ static async Task AsyncMain(IConfigurationRoot config)
5357
5458 var pullRequests = await query . GetOpenPullRequests ( gitHubConfig [ "organization" ] , gitHubConfig [ "repository" ] ) ;
5559 var autoMergePullRequests = new List < GraphPullRequest > ( ) ;
56- Console . WriteLine ( $ "Org ' { gitHubConfig [ "organization" ] } ' repo ' { gitHubConfig [ "repository" ] } ' open pull requests ({ pullRequests . Count } )") ;
60+ Console . WriteLine ( $ "Open pull requests ({ pullRequests . Count } ): ") ;
5761 foreach ( var pullRequest in pullRequests )
5862 {
5963 var autoMerge = memberLogins . Contains ( pullRequest . Author . Login )
@@ -69,11 +73,53 @@ static async Task AsyncMain(IConfigurationRoot config)
6973 }
7074 }
7175
72- Console . WriteLine ( $ "Org '{ gitHubConfig [ "organization" ] } ' repo '{ gitHubConfig [ "repository" ] } ' auto-merge pull requests ({ autoMergePullRequests . Count } )") ;
76+ Console . WriteLine ( $ "Pull requests suitable for auto-merging ({ autoMergePullRequests . Count } ):") ;
77+ foreach ( var pullRequest in autoMergePullRequests )
78+ {
79+ Console . WriteLine ( $ " #{ pullRequest . Number } { pullRequest . Title } ") ;
80+ }
81+
82+ var git = new Git . Project ( GetGitPath ( ) , false ) ;
83+ git . Init ( $ "https://github.com/{ gitHubConfig [ "organization" ] } /{ gitHubConfig [ "repository" ] } .git") ;
84+ git . Fetch ( ) ;
85+ git . ResetHard ( ) ;
86+ var baseCommit = git . ParseRef ( "master" ) ;
87+ git . CheckoutDetached ( baseCommit ) ;
88+ var autoMergePullRequestsSuccess = new List < GraphPullRequest > ( ) ;
89+ var autoMergePullRequestsFailure = new List < GraphPullRequest > ( ) ;
7390 foreach ( var pullRequest in autoMergePullRequests )
91+ {
92+ var mergeCommit = git . ParseRef ( $ "pull/{ pullRequest . Number } /head") ;
93+ try
94+ {
95+ git . Merge ( mergeCommit ) ;
96+ autoMergePullRequestsSuccess . Add ( pullRequest ) ;
97+ }
98+ catch ( ApplicationException )
99+ {
100+ autoMergePullRequestsFailure . Add ( pullRequest ) ;
101+ git . ResetHard ( ) ;
102+ }
103+ }
104+ Console . WriteLine ( $ "Final commit: { git . ParseRef ( "HEAD" ) } ") ;
105+
106+ Console . WriteLine ( $ "Pull requests successfully auto-merged ({ autoMergePullRequestsSuccess . Count } ):") ;
107+ foreach ( var pullRequest in autoMergePullRequestsSuccess )
108+ {
109+ Console . WriteLine ( $ " #{ pullRequest . Number } { pullRequest . Title } ") ;
110+ }
111+
112+ Console . WriteLine ( $ "Pull requests not auto-merged ({ autoMergePullRequestsFailure . Count } ):") ;
113+ foreach ( var pullRequest in autoMergePullRequestsFailure )
74114 {
75115 Console . WriteLine ( $ " #{ pullRequest . Number } { pullRequest . Title } ") ;
76116 }
77117 }
118+
119+ static string GetGitPath ( )
120+ {
121+ var appFilePath = System . Reflection . Assembly . GetEntryAssembly ( ) . Location ;
122+ return Path . Combine ( Path . GetDirectoryName ( appFilePath ) , "git" ) ;
123+ }
78124 }
79125}
0 commit comments