コード例 #1
0
        public override async Task ExecuteAsync(IOperationExecutionContext context)
        {
            var github = new GitHubClient(this.ApiUrl, this.UserName, this.Password, this.OrganizationName);
            var data   = new Dictionary <string, object> {
                ["title"] = this.Title
            };

            if (!string.IsNullOrEmpty(this.Body))
            {
                data.Add("body", this.Body);
            }
            if (this.Labels != null)
            {
                data.Add("labels", this.Labels);
            }
            if (this.Assignees != null)
            {
                data.Add("assignees", this.Assignees);
            }
            if (!string.IsNullOrEmpty(this.Milestone))
            {
                data.Add("milestone", await github.CreateMilestoneAsync(this.Milestone, AH.CoalesceString(this.OrganizationName, this.UserName), this.RepositoryName, context.CancellationToken));
            }
            this.IssueNumber = await github.CreateIssueAsync(AH.CoalesceString(this.OrganizationName, this.UserName), this.RepositoryName, data, context.CancellationToken).ConfigureAwait(false);
        }
コード例 #2
0
        public override async Task <IEnumerable <IIssueTrackerIssue> > EnumerateIssuesAsync(IIssueSourceEnumerationContext context)
        {
            var credentials = this.TryGetCredentials <GitLabCredentials>();

            if (credentials == null)
            {
                throw new InvalidOperationException("Credentials must be supplied to enumerate GitLab issues.");
            }

            string projectName = AH.CoalesceString(this.ProjectName, credentials.ProjectName);

            if (string.IsNullOrEmpty(projectName))
            {
                throw new InvalidOperationException("A project name must be defined in either the issue source or associated GitLab credentials in order to enumerate GitLab issues.");
            }

            var client = new GitLabClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.GroupName);

            var filter = new GitLabIssueFilter
            {
                Milestone = this.MilestoneTitle,
                Labels    = this.Labels,
                CustomFilterQueryString = this.CustomFilterQueryString
            };

            var issues = await client.GetIssuesAsync(projectName, filter, CancellationToken.None).ConfigureAwait(false);

            return(from i in issues
                   select new GitLabIssue(i));
        }
コード例 #3
0
 protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
 {
     return(new ExtendedRichDescription(
                new RichDescription("Close GitLab issue #", new Hilite(config[nameof(IssueId)])),
                new RichDescription("in ", new Hilite(AH.CoalesceString(config[nameof(ProjectName)], config[nameof(CredentialName)])))
                ));
 }
コード例 #4
0
 protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
 {
     return(new ExtendedRichDescription(
                new RichDescription("HTTP ", AH.CoalesceString(config[nameof(this.Method)], "POST")),
                new RichDescription("to ", new Hilite(config[nameof(this.Url)]))
                ));
 }
コード例 #5
0
 protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
 {
     return(new ExtendedRichDescription(
                new RichDescription("Create issue titled ", new Hilite(config[nameof(Title)])),
                new RichDescription("in ", new Hilite(AH.CoalesceString(config[nameof(RepositoryName)], config[nameof(CredentialName)])))
                ));
 }
コード例 #6
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];

            if (string.IsNullOrEmpty(credentialName))
            {
                return(Enumerable.Empty <string>());
            }

            var credentials = ResourceCredentials.Create <GitLabCredentials>(credentialName);

            string ownerName      = AH.CoalesceString(credentials.GroupName, credentials.UserName);
            string repositoryName = AH.CoalesceString(config["ProjectName"], credentials.ProjectName);

            if (string.IsNullOrEmpty(ownerName) || string.IsNullOrEmpty(repositoryName))
            {
                return(Enumerable.Empty <string>());
            }

            var client = new GitLabClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.GroupName);

            var milestones = await client.GetMilestonesAsync(repositoryName, "open", CancellationToken.None).ConfigureAwait(false);

            var titles = from m in milestones
                         let title = m["title"]?.ToString()
                                     where !string.IsNullOrEmpty(title)
                                     select title;

            if (SDK.ProductName == "BuildMaster")
            {
                titles = new[] { "$ReleaseName", "$ReleaseNumber" }.Concat(titles);
            }

            return(titles);
        }
コード例 #7
0
        public static PackageDeploymentData Create(IOperationExecutionContext context, ILogSink log, string description)
        {
            string baseUrl = SDK.BaseUrl;

            if (string.IsNullOrEmpty(baseUrl))
            {
                log.LogDebug("Deployment will not be recorded in ProGet because the System.BaseUrl configuration setting is not set.");
                return(null);
            }

            string serverName = AH.CoalesceString(context?.ServerName, Environment.MachineName);
            string relativeUrl;

            if (SDK.ProductName == "BuildMaster")
            {
                relativeUrl = context.ExpandVariables($"applications/{((IStandardContext)context).ProjectId}/builds/build?releaseNumber=$UrlEncode($ReleaseNumber)&buildNumber=$UrlEncode($PackageNumber)").AsString();
            }
            else if (SDK.ProductName == "Hedgehog")
            {
                relativeUrl = "deployment-sets/details?deploymentSetId=" + ((IStandardContext)context).DeploymentSetId;
            }
            else
            {
                relativeUrl = "executions/execution-in-progress?executionId=" + context.ExecutionId;
            }

            return(new PackageDeploymentData(SDK.ProductName, baseUrl, relativeUrl, serverName, description));
        }
コード例 #8
0
 protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
 {
     return(new ExtendedRichDescription(
                new RichDescription("Ensure milestone ", new Hilite(config[nameof(GitLabMilestoneConfiguration.Title)])),
                new RichDescription("in ", new Hilite(AH.CoalesceString(config[nameof(GitLabMilestoneConfiguration.ProjectName)], config[nameof(GitLabMilestoneConfiguration.CredentialName)])))
                ));
 }
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            string ownerName = AH.CoalesceString(config[nameof(GitLabCredentials.GroupName)], config[nameof(GitLabCredentials.UserName)]);

            if (string.IsNullOrEmpty(ownerName))
            {
                return(Enumerable.Empty <string>());
            }

            GitLabClient client;

            try
            {
                client = new GitLabClient(config[nameof(GitLabCredentials.ApiUrl)], config[nameof(GitLabCredentials.UserName)], AH.CreateSecureString(config[nameof(GitLabCredentials.Password)].ToString()), config[nameof(GitLabCredentials.GroupName)]);
            }
            catch (InvalidOperationException)
            {
                return(Enumerable.Empty <string>());
            }

            var repos = await client.GetProjectsAsync(CancellationToken.None).ConfigureAwait(false);

            var names = from m in repos
                        let name = m["path_with_namespace"]?.ToString()
                                   where !string.IsNullOrEmpty(name)
                                   select name;

            return(names);
        }
コード例 #10
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];

            if (string.IsNullOrEmpty(credentialName))
            {
                return(Enumerable.Empty <string>());
            }

            var credentials = ResourceCredentials.Create <GitHubCredentials>(credentialName);

            string ownerName      = AH.CoalesceString(credentials.OrganizationName, credentials.UserName);
            string repositoryName = AH.CoalesceString(config["RepositoryName"], credentials.RepositoryName);

            if (string.IsNullOrEmpty(ownerName) || string.IsNullOrEmpty(repositoryName))
            {
                return(Enumerable.Empty <string>());
            }

            var client = new GitHubClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.OrganizationName);

            var milestones = await client.GetMilestonesAsync(ownerName, repositoryName, "open").ConfigureAwait(false);

            var titles = from m in milestones
                         let title = m["title"]?.ToString()
                                     where !string.IsNullOrEmpty(title)
                                     select title;

            return(new[] { "$ReleaseName", "$ReleaseNumber" }.Concat(titles));
        }
コード例 #11
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];

            if (string.IsNullOrEmpty(credentialName))
            {
                return(Enumerable.Empty <string>());
            }

            var credentials = ResourceCredentials.Create <GitHubCredentials>(credentialName);

            string ownerName = AH.CoalesceString(credentials.OrganizationName, credentials.UserName);

            if (string.IsNullOrEmpty(ownerName))
            {
                return(Enumerable.Empty <string>());
            }

            var client = new GitHubClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.OrganizationName);
            var repos  = await client.GetRepositoriesAsync().ConfigureAwait(false);


            var names = from m in repos
                        let name = m["name"]?.ToString()
                                   where !string.IsNullOrEmpty(name)
                                   select name;

            return(new[] { "$ApplicationName" }.Concat(names));
        }
コード例 #12
0
        internal static GitHubCredentials TryCreate(string name, IOperationConfiguration config)
        {
            int?projectId     = AH.ParseInt(AH.CoalesceString(config["ProjectId"], config["ApplicationId"]));
            int?environmentId = AH.ParseInt(config["EnvironmentId"]);

            return((GitHubCredentials)ResourceCredentials.TryCreate(GitHubCredentials.TypeName, name, environmentId: environmentId, applicationId: projectId, inheritFromParent: false));
        }
コード例 #13
0
        public static PackageDeploymentData Create(IOperationExecutionContext context, ILogSink log, string description)
        {
            string baseUrl = SDK.BaseUrl;

            if (string.IsNullOrEmpty(baseUrl))
            {
                log.LogDebug("Deployment will not be recorded in ProGet because the System.BaseUrl configuration setting is not set.");
                return(null);
            }

            string serverName = AH.CoalesceString(context?.ServerName, Environment.MachineName);
            string relativeUrl;

            if (SDK.ProductName == "BuildMaster")
            {
                dynamic bmContext = context;
                relativeUrl = $"applications/{bmContext.ApplicationId}/builds/build?releaseNumber={Uri.EscapeDataString(bmContext.ReleaseNumber)}&buildNumber={Uri.EscapeDataString(bmContext.BuildNumber)}";
            }
            else
            {
                relativeUrl = "/deployment-sets/details?deploymentSetId=" + ((IStandardContext)context).DeploymentSetId;
            }

            return(new PackageDeploymentData(SDK.ProductName, baseUrl, relativeUrl, serverName, description));
        }
コード例 #14
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];
            var jobName        = config["JobName"];

            if (string.IsNullOrEmpty(credentialName) || string.IsNullOrEmpty(jobName))
            {
                return(Enumerable.Empty <string>());
            }

            int?projectId     = AH.ParseInt(AH.CoalesceString(config["ProjectId"], config["ApplicationId"]));
            int?environmentId = AH.ParseInt(config["EnvironmentId"]);

            var credentials = (JenkinsLegacyCredentials)ResourceCredentials.TryCreate(JenkinsLegacyCredentials.TypeName, credentialName, environmentId: environmentId, applicationId: projectId, inheritFromParent: false);

            if (credentials == null)
            {
                return(Enumerable.Empty <string>());
            }

            using (var cts = new CancellationTokenSource(new TimeSpan(0, 0, 30)))
            {
                var client = this.CreateClient(config, cts.Token);
                return(await client.GetBranchNamesAsync(jobName).ConfigureAwait(false));
            }
        }
コード例 #15
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];

            if (string.IsNullOrEmpty(credentialName))
            {
                return(Enumerable.Empty <string>());
            }

            var credentials = ResourceCredentials.Create <GitLabCredentials>(credentialName);

            string ownerName = AH.CoalesceString(credentials.GroupName, credentials.UserName);

            if (string.IsNullOrEmpty(ownerName))
            {
                return(Enumerable.Empty <string>());
            }

            var client = new GitLabClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.GroupName);
            var groups = await client.GetGroupsAsync(CancellationToken.None).ConfigureAwait(false);

            var names = from m in groups
                        let name = m["full_path"]?.ToString()
                                   where !string.IsNullOrEmpty(name)
                                   select name;

            return(names);
        }
コード例 #16
0
 public ActiveDirectoryUser(UserId userId, string displayName, string emailAddress)
 {
     this.UserName      = userId.Principal;
     this.Domain        = userId.DomainAlias;
     this.DisplayName   = AH.CoalesceString(displayName, this.UserName);
     this.EmailAddress  = emailAddress;
     this.principalName = $"{userId.Principal}@{userId.DomainAlias}";
 }
コード例 #17
0
        public override async Task ConfigureAsync(IOperationExecutionContext context)
        {
            var github = new GitHubClient(this.Template.ApiUrl, this.Template.UserName, this.Template.Password, this.Template.OrganizationName);

            var ownerName = AH.CoalesceString(this.Template.OrganizationName, this.Template.UserName);

            await github.EnsureReleaseAsync(ownerName, this.Template.RepositoryName, this.Template.Tag, this.Template.Target, this.Template.Title, this.Template.Description, this.Template.Draft, this.Template.Prerelease, context.CancellationToken).ConfigureAwait(false);
        }
コード例 #18
0
 protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
 {
     return(new ExtendedRichDescription(
                new RichDescription("Run DFHack test suite"),
                new RichDescription("for ", new Hilite(AH.CoalesceString(config[nameof(OperatingSystem)], "unknown operating system")),
                                    " (", new Hilite(AH.CoalesceString(config[nameof(Architecture)], "unknown architecture")), ")")
                ));
 }
コード例 #19
0
 public SvnClient(UsernamePasswordCredentials credentials, Agent agent, string svnExePath, ILogSink log, CancellationToken?cancellationToken = null)
 {
     this.execOps           = new Lazy <IRemoteProcessExecuter>(() => agent.GetService <IRemoteProcessExecuter>());
     this.userName          = credentials?.UserName;
     this.password          = credentials?.Password;
     this.svnExePath        = AH.CoalesceString(svnExePath, RemoteMethods.GetEmbeddedSvnExePath(agent));
     this.log               = log ?? (ILogSink)Logger.Null;
     this.cancellationToken = cancellationToken ?? CancellationToken.None;
 }
コード例 #20
0
        protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
        {
            string source = AH.CoalesceString(config[nameof(this.RepositoryUrl)], config[nameof(this.CredentialName)]);

            return(new ExtendedRichDescription(
                       new RichDescription("Get Git Source"),
                       new RichDescription("from ", new Hilite(source), " to ", new DirectoryHilite(config[nameof(this.DiskPath)]))
                       ));
        }
コード例 #21
0
        protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
        {
            string source = AH.CoalesceString(config[nameof(this.RepositoryName)], config[nameof(this.CredentialName)]);

            return(new ExtendedRichDescription(
                       new RichDescription("Upload ", new MaskHilite(config[nameof(this.Includes)], config[nameof(this.Excludes)]), " from ", new DirectoryHilite(config[nameof(this.SourceDirectory)]), " to GitHub"),
                       new RichDescription("in ", new Hilite(source), " release ", new Hilite(config[nameof(this.Tag)]))
                       ));
        }
コード例 #22
0
        protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
        {
            string source = AH.CoalesceString(config[nameof(this.Template.RepositoryName)], config[nameof(this.Template.CredentialName)]);

            return(new ExtendedRichDescription(
                       new RichDescription("Ensure GitHub Release"),
                       new RichDescription("in ", new Hilite(source), " for tag ", new Hilite(config[nameof(this.Template.Tag)]))
                       ));
        }
コード例 #23
0
        protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
        {
            string source = AH.CoalesceString(config[nameof(this.RepositoryName)], config[nameof(this.CredentialName)]);

            return(new ExtendedRichDescription(
                       new RichDescription("Tag GitHub Source"),
                       new RichDescription("in ", new Hilite(source), " with ", new Hilite(config[nameof(this.Tag)]))
                       ));
        }
コード例 #24
0
        public override async Task <IEnumerable <IIssueTrackerIssue> > EnumerateIssuesAsync(IIssueSourceEnumerationContext context)
        {
            GitHubCredentials credentials = null;

            if (context is IStandardContext stdcontext)
            {
                credentials = this.TryGetCredentials(stdcontext.EnvironmentId, stdcontext.ProjectId) as GitHubCredentials;
            }
            else
            {
                credentials = this.TryGetCredentials();
            }

            if (credentials == null)
            {
                throw new InvalidOperationException("Credentials must be supplied to enumerate GitHub issues.");
            }

            string repositoryName = AH.CoalesceString(this.RepositoryName, credentials.RepositoryName);

            if (string.IsNullOrEmpty(repositoryName))
            {
                throw new InvalidOperationException("A repository name must be defined in either the issue source or associated GitHub credentials in order to enumerate GitHub issues.");
            }

            var client = new GitHubClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.OrganizationName);

            string ownerName = AH.CoalesceString(credentials.OrganizationName, credentials.UserName);

            var filter = new GitHubIssueFilter
            {
                Labels = this.Labels,
                CustomFilterQueryString = this.CustomFilterQueryString
            };

            if (!string.IsNullOrEmpty(this.MilestoneTitle))
            {
                int?milestoneId = await client.FindMilestoneAsync(this.MilestoneTitle, ownerName, repositoryName, CancellationToken.None).ConfigureAwait(false);

                if (milestoneId == null)
                {
                    throw new InvalidOperationException($"Milestone '{this.MilestoneTitle}' not found in repository '{repositoryName}' owned by '{ownerName}'.");
                }

                filter.Milestone = milestoneId.ToString();
            }
            else
            {
                filter.Milestone = "*";
            }

            var issues = await client.GetIssuesAsync(ownerName, repositoryName, filter, CancellationToken.None).ConfigureAwait(false);

            return(from i in issues
                   select new GitHubIssue(i));
        }
コード例 #25
0
        void IVariableSetter <SelectBuildConfigurationVariable> .BindToVariable(SelectBuildConfigurationVariable variable, string defaultValue)
        {
            if (variable == null)
            {
                throw new ArgumentNullException("variable");
            }

            this.FillItems(TeamCityConfigurer.GetConfigurer(variable.ConfigurationProfileName));
            this.SelectedValue = AH.CoalesceString(variable.Value, defaultValue);
        }
コード例 #26
0
 protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
 {
     return(new ExtendedRichDescription(
                new RichDescription("Add comment to GitHub issue #", new Hilite(config[nameof(IssueNumber)])),
                new RichDescription(
                    "in ", new Hilite(AH.CoalesceString(config[nameof(RepositoryName)], config[nameof(CredentialName)])),
                    " starting with ", new Hilite(config[nameof(Body)])
                    )
                ));
 }
コード例 #27
0
 public override RichDescription GetDescription()
 {
     return(new RichDescription(
                "Ensure drift status is ",
                new Hilite(this.Status.ToString()),
                " for ",
                !string.IsNullOrEmpty(this.Server) ? "server " : "role ",
                new Hilite(AH.CoalesceString(this.Server, this.Role))
                ));
 }
コード例 #28
0
 public async Task StoreConfigurationStatusAsync(ConfigurationPersistenceContext context)
 {
     for (int i = 0; i < this.scriptResults.Configuration?.Count; i++)
     {
         await context.SetConfigurationStatusAsync(
             AH.CoalesceString(this.scriptResults.Configuration[i].ConfigType, "PSConfig"),
             this.scriptResults.Configuration[i].ConfigKey,
             this.comparisonResults[i] == null?ConfigurationStatus.Current : ConfigurationStatus.Drifted);
     }
 }
 public override RichDescription GetDescription()
 {
     return(new RichDescription(
                "Versions of ",
                new Hilite(this.PackageId),
                " from ",
                new Hilite(AH.CoalesceString(this.FeedUrl, this.CredentialName)),
                "."
                ));
 }
コード例 #30
0
        public override BuildImporterBase CreateFromForm()
        {
            string buildNumber = AH.CoalesceString(this.Template.BuildNumber, this.txtBuildNumber.Text, "lastSuccessfulBuild");

            return(new JenkinsBuildImporter
            {
                ArtifactName = this.Template.ArtifactName ?? this.Template.JobName,
                BuildNumber = buildNumber,
                JobName = this.Template.JobName
            });
        }