@@ -21,7 +21,6 @@ private static bool TryConnect( ConsoleHelper console, string url, [NotNullWhen(
2121 {
2222 var user = Environment . GetEnvironmentVariable ( EnvironmentVariableNames . AzureDevOpsUser ) ?? "teamcity@postsharp.net" ;
2323
24-
2524 var token = Environment . GetEnvironmentVariable ( EnvironmentVariableNames . AzureDevOpsToken ) ;
2625
2726 if ( string . IsNullOrEmpty ( token ) )
@@ -79,7 +78,7 @@ private static bool TryConnect( ConsoleHelper console, string url, [NotNullWhen(
7978 var pullRequestWithAutoCompleteEnabled = new GitPullRequest
8079 {
8180 AutoCompleteSetBy = new IdentityRef { Id = createdPullRequest . CreatedBy . Id } ,
82- CompletionOptions = new GitPullRequestCompletionOptions { DeleteSourceBranch = true , MergeCommitMessage = title } ,
81+ CompletionOptions = new GitPullRequestCompletionOptions { DeleteSourceBranch = true , MergeCommitMessage = title }
8382 } ;
8483
8584 console . WriteMessage ( "Setting the new pull request to get completed automatically." ) ;
@@ -117,10 +116,13 @@ public static async Task<bool> TrySetBranchPoliciesAsync(
117116 var project = azureDevOpsRepository . Project ;
118117 var projectIdArgs = $ "--org { org } --project { project } ";
119118
120- context . Console . WriteMessage ( "Fetching repository ID." ) ;
119+ var console = context . Console ;
120+ var product = context . Product ;
121+
122+ console . WriteMessage ( "Fetching repository ID." ) ;
121123
122124 if ( ! AzHelper . Query (
123- context . Console ,
125+ context ,
124126 $ "repos show --repository { repository } { projectIdArgs } ",
125127 dry ,
126128 out var repositoryJson ) )
@@ -138,24 +140,24 @@ string GetCommonArgs( string branch )
138140 return $ "{ branchIdArgs } --blocking true --enabled true";
139141 }
140142
141- var branch = context . Product . DependencyDefinition . Branch ;
143+ var branch = product . DependencyDefinition . Branch ;
142144 var commonArgs = GetCommonArgs ( branch ) ;
143145
144146 bool TryRequireApproversAndCommentResolution ( )
145147 {
146- context . Console . WriteMessage ( $ "Requiring approvers for '{ branch } ' branch." ) ;
148+ console . WriteMessage ( $ "Requiring approvers for '{ branch } ' branch." ) ;
147149
148150 if ( ! AzHelper . Run (
149- context . Console ,
151+ context ,
150152 $ "repos policy approver-count create { commonArgs } --allow-downvotes false --creator-vote-counts true --minimum-approver-count 1 --reset-on-source-push false",
151153 dry ) )
152154 {
153155 return false ;
154156 }
155157
156- context . Console . WriteMessage ( $ "Requiring comment resolution for '{ branch } ' branch." ) ;
158+ console . WriteMessage ( $ "Requiring comment resolution for '{ branch } ' branch." ) ;
157159
158- if ( ! AzHelper . Run ( context . Console , $ "repos policy comment-required create { commonArgs } ", dry ) )
160+ if ( ! AzHelper . Run ( context , $ "repos policy comment-required create { commonArgs } ", dry ) )
159161 {
160162 return false ;
161163 }
@@ -170,11 +172,11 @@ bool TryRequireApproversAndCommentResolution()
170172
171173 if ( buildStatusName == null )
172174 {
173- context . Console . WriteMessage ( $ "Success status for '{ branch } ' branch is not required." ) ;
175+ console . WriteMessage ( $ "Success status for '{ branch } ' branch is not required." ) ;
174176 }
175177 else
176178 {
177- context . Console . WriteMessage ( $ "Requiring success status for '{ branch } ' branch." ) ;
179+ console . WriteMessage ( $ "Requiring success status for '{ branch } ' branch." ) ;
178180
179181 // This is not covered by "az repos policy" command. https://github.com/Azure/azure-devops-cli-extension/issues/1040
180182 var statusCheckPayload = $@ "{{
@@ -207,7 +209,7 @@ bool TryRequireApproversAndCommentResolution()
207209 {
208210 await File . WriteAllTextAsync ( statusCheckPayloadFile , statusCheckPayload ) ;
209211
210- if ( ! AzHelper . Run ( context . Console , $ "repos policy create { projectIdArgs } --config { statusCheckPayloadFile } ", dry ) )
212+ if ( ! AzHelper . Run ( context , $ "repos policy create { projectIdArgs } --config { statusCheckPayloadFile } ", dry ) )
211213 {
212214 return false ;
213215 }
@@ -218,26 +220,26 @@ bool TryRequireApproversAndCommentResolution()
218220 }
219221 }
220222
221- if ( context . Product . DependencyDefinition . ReleaseBranch != null )
223+ if ( product . DependencyDefinition . ReleaseBranch != null )
222224 {
223225 var developBranch = branch ;
224- branch = context . Product . DependencyDefinition . ReleaseBranch ;
226+ branch = product . DependencyDefinition . ReleaseBranch ;
225227 commonArgs = GetCommonArgs ( branch ) ;
226228
227229 if ( ! TryRequireApproversAndCommentResolution ( ) )
228230 {
229231 return false ;
230232 }
231233
232- context . Console . WriteMessage ( $ "Requiring reviewers for '{ branch } ' branch." ) ;
234+ console . WriteMessage ( $ "Requiring reviewers for '{ branch } ' branch." ) ;
233235
234236 var message =
235237 $ "\" TeamCity is a required reviewer because only automated merges during publishing are allowed to a release branch. For development, use '{ developBranch } ' branch as a target branch of your PR.\" ";
236238
237239 var options = new ToolInvocationOptions ( new Dictionary < string , string ? > { { "ReviewerMessage" , message } } . ToImmutableDictionary ( ) ) ;
238240
239241 if ( ! AzHelper . Run (
240- context . Console ,
242+ context ,
241243 $ "repos policy required-reviewer create { commonArgs } --message %ReviewerMessage% --required-reviewer-ids teamcity@postsharp.net",
242244 dry ,
243245 options ) )
@@ -248,9 +250,9 @@ bool TryRequireApproversAndCommentResolution()
248250
249251 return await Task . FromResult ( true ) ;
250252 }
251-
253+
252254 public static async Task < bool > TrySetDefaultBranchAsync (
253- ConsoleHelper console ,
255+ BuildContext context ,
254256 AzureDevOpsRepository azureDevOpsRepository ,
255257 string defaultBranch ,
256258 bool dry )
@@ -261,10 +263,10 @@ public static async Task<bool> TrySetDefaultBranchAsync(
261263 var projectIdArgs = $ "--org { org } --project { project } ";
262264 var repositoryIdArgs = $ "{ projectIdArgs } --repository { repository } ";
263265
264- console . WriteMessage ( $ "Setting repository default branch to '{ defaultBranch } '." ) ;
266+ context . Console . WriteMessage ( $ "Setting repository default branch to '{ defaultBranch } '." ) ;
265267
266268 if ( ! AzHelper . Run (
267- console ,
269+ context ,
268270 $ "repos update { repositoryIdArgs } --default-branch { defaultBranch } ",
269271 dry ) )
270272 {
0 commit comments