private async Task <AzureDevOpsClient> GetAzureDevOpsClientForAccount(string account)
        {
            IAzureDevOpsTokenProvider azdoTokenProvider = Context.GetService <IAzureDevOpsTokenProvider>();
            string accessToken = await azdoTokenProvider.GetTokenForAccount(account);

            return(new AzureDevOpsClient(accessToken, Logger, null));
        }
示例#2
0
        private async Task <AzureDevOpsClient> GetAzureDevOpsClientForAccount(string account)
        {
            IAzureDevOpsTokenProvider azdoTokenProvider = Context.GetService <IAzureDevOpsTokenProvider>();
            string accessToken = await azdoTokenProvider.GetTokenForAccount(account);

            // The release pipeline runner does not need a git client.
            return(new AzureDevOpsClient(null, accessToken, Logger, null));
        }
        /// <summary>
        /// Returns an Azure DevOps client for a given account
        /// </summary>
        /// <param name="account">Azure DevOps account that the client will get its token from</param>
        /// <returns>Azure DevOps client for the given account</returns>
        private AzureDevOpsClient GetAzureDevOpsClientForAccountAsync(string account)
        {
            IAzureDevOpsTokenProvider azdoTokenProvider = Context.GetService <IAzureDevOpsTokenProvider>();
            string accessToken = azdoTokenProvider.GetTokenForAccount(account).GetAwaiter().GetResult();

            // FeedCleaner does not need Git, or a temporaryRepositoryPath
            return(new AzureDevOpsClient(null, accessToken, Logger, null));
        }
 public DarcRemoteFactory(
     IConfigurationRoot configuration,
     IGitHubTokenProvider gitHubTokenProvider,
     IAzureDevOpsTokenProvider azureDevOpsTokenProvider,
     BuildAssetRegistryContext context)
 {
     Configuration            = configuration;
     GitHubTokenProvider      = gitHubTokenProvider;
     AzureDevOpsTokenProvider = azureDevOpsTokenProvider;
     Context = context;
 }
示例#5
0
        public static Task <string> GetTokenForRepository(this IAzureDevOpsTokenProvider that, string repositoryUrl)
        {
            Match m = AccountNameRegex.Match(repositoryUrl);

            if (!m.Success)
            {
                throw new ArgumentException($"{repositoryUrl} is not a valid Azure DevOps repository URL");
            }
            string account = m.Groups["account"].Value;

            return(that.GetTokenForAccount(account));
        }
示例#6
0
 public DarcRemoteFactory(
     BuildAssetRegistryContext context,
     IKustoClientProvider kustoClientProvider,
     IGitHubTokenProvider gitHubTokenProvider,
     IAzureDevOpsTokenProvider azureDevOpsTokenProvider,
     DarcRemoteMemoryCache memoryCache)
 {
     Context                  = context;
     KustoClientProvider      = (KustoClientProvider)kustoClientProvider;
     GitHubTokenProvider      = gitHubTokenProvider;
     AzureDevOpsTokenProvider = azureDevOpsTokenProvider;
     Cache = memoryCache;
 }
示例#7
0
 public DarcRemoteFactory(
     IConfiguration configuration,
     IGitHubTokenProvider gitHubTokenProvider,
     IAzureDevOpsTokenProvider azureDevOpsTokenProvider,
     DarcRemoteMemoryCache memoryCache,
     BuildAssetRegistryContext context,
     TemporaryFiles tempFiles)
 {
     _tempFiles               = tempFiles;
     Configuration            = configuration;
     GitHubTokenProvider      = gitHubTokenProvider;
     AzureDevOpsTokenProvider = azureDevOpsTokenProvider;
     Cache   = memoryCache;
     Context = context;
 }
示例#8
0
 public DarcRemoteFactory(
     IConfiguration configuration,
     IGitHubTokenProvider gitHubTokenProvider,
     IAzureDevOpsTokenProvider azureDevOpsTokenProvider,
     DarcRemoteMemoryCache memoryCache,
     BuildAssetRegistryContext context,
     TemporaryFiles tempFiles,
     ILocalGit localGit,
     OperationManager operations)
 {
     _tempFiles                = tempFiles;
     _localGit                 = localGit;
     _operations               = operations;
     _configuration            = configuration;
     _gitHubTokenProvider      = gitHubTokenProvider;
     _azureDevOpsTokenProvider = azureDevOpsTokenProvider;
     _cache   = memoryCache;
     _context = context;
 }
        private async Task CreateGitHubIssueAsync(int buildId, int releaseId, string releaseName)
        {
            Logger.LogInformation($"Something failed in release definition {releaseId} triggered by build {buildId}");

            Build  build = Context.Builds.Where(b => b.Id == buildId).First();
            string whereToCreateIssue = "https://github.com/dotnet/arcade";
            string fyiHandles = "@JohnTortugo, @jcagme";
            string gitHubToken = null, azureDevOpsToken = null;
            string repo = build.GitHubRepository ?? build.AzureDevOpsRepository;

            using (Logger.BeginScope($"Opening GitHub issue for release definition {releaseId} " +
                                     $"triggered by build {buildId} from repo '{repo}'."))
            {
                try
                {
                    // We get the token of the repo which triggered the release so we can get the author.
                    if (!string.IsNullOrEmpty(build.GitHubRepository))
                    {
                        IGitHubTokenProvider gitHubTokenProvider = Context.GetService <IGitHubTokenProvider>();
                        long installationId = await Context.GetInstallationId(build.GitHubRepository);

                        gitHubToken = await gitHubTokenProvider.GetTokenForInstallation(installationId);

                        Logger.LogInformation($"GitHub token acquired for '{build.GitHubRepository}'!");
                    }

                    if (!string.IsNullOrEmpty(build.AzureDevOpsRepository))
                    {
                        IAzureDevOpsTokenProvider azdoTokenProvider = Context.GetService <IAzureDevOpsTokenProvider>();
                        azureDevOpsToken = await azdoTokenProvider.GetTokenForAccount(build.AzureDevOpsAccount);

                        Logger.LogInformation($"AzureDevOPs token acquired for '{build.AzureDevOpsRepository}'!");
                    }

                    IssueManager issueManager = new IssueManager(gitHubToken, azureDevOpsToken);

                    string title       = $"Release '{releaseName}' with id {releaseId} failed";
                    string description = $"Something failed while running an async release pipeline for build " +
                                         $"[{build.AzureDevOpsBuildNumber}](https://dnceng.visualstudio.com/internal/_build/results?buildId={build.AzureDevOpsBuildId})." +
                                         $"{Environment.NewLine} {Environment.NewLine}" +
                                         $"Please click [here](https://dnceng.visualstudio.com/internal/_releaseProgress?_a=release-pipeline-progress&releaseId={releaseId}) to check the error logs." +
                                         $" {Environment.NewLine} {Environment.NewLine}" +
                                         $"/FYI: {fyiHandles}";

                    if (build.GitHubRepository != whereToCreateIssue)
                    {
                        // We get the token of the Arcade installation since there's where the actual issue will be
                        // created. We cannot reuse the previously acquired token since its generated for a
                        // different repo.
                        IGitHubTokenProvider gitHubTokenProvider = Context.GetService <IGitHubTokenProvider>();
                        long installationId = await Context.GetInstallationId(whereToCreateIssue);

                        gitHubToken = await gitHubTokenProvider.GetTokenForInstallation(installationId);

                        Logger.LogInformation($"GitHub token acquired for '{whereToCreateIssue}'!");

                        issueManager = new IssueManager(gitHubToken, azureDevOpsToken);
                    }

                    int issueId = await issueManager.CreateNewIssueAsync(whereToCreateIssue, title, description);

                    Logger.LogInformation($"Issue {issueId} was created in '{whereToCreateIssue}'");
                }
                catch (Exception exc)
                {
                    Logger.LogError(exc, $"Something failed while attempting to create an issue based on repo '{repo}' " +
                                    $"and commit {build.Commit}.");
                }
            }
        }
示例#10
0
 public AzDevController(IAzureDevOpsTokenProvider tokenProvider)
 {
     TokenProvider = tokenProvider;
 }