Ejemplo n.º 1
0
        public PullRequestRequest(string head, string title, string baseRef, bool deleteBranchAfterMerge, bool setAutoMerge, GitPullRequestMergeStrategy mergeStrategy)
        {
            Head  = head;
            Title = title;
            DeleteBranchAfterMerge = deleteBranchAfterMerge;
            SetAutoMerge           = setAutoMerge;
            MergeStrategy          = mergeStrategy;

            //This can be a remote that has been passed in, this happens when run locally against a targetbranch that is remote
            BaseRef = baseRef?.Replace("origin/", string.Empty);
        }
Ejemplo n.º 2
0
        public async Task <RepositorySettings> RepositorySettings(Uri repositoryUri, bool setAutoMerge, string targetBranch = null, GitPullRequestMergeStrategy gitPullRequestMergeStrategy = GitPullRequestMergeStrategy.NoFastForward)
        {
            if (repositoryUri == null)
            {
                throw new NuKeeperException(
                          $"The provided uri was is not in the correct format. Provided null and format should be {UrlPattern}");
            }

            var settings = repositoryUri.IsFile
                ? await CreateSettingsFromLocal(repositoryUri, targetBranch)
                : await CreateSettingsFromRemote(repositoryUri, targetBranch);

            return(settings);
        }
Ejemplo n.º 3
0
        public Task <RepositorySettings> RepositorySettings(Uri repositoryUri, bool setAutoMerge, string targetBranch = null, GitPullRequestMergeStrategy gitPullRequestMergeStrategy = GitPullRequestMergeStrategy.NoFastForward)
        {
            if (repositoryUri == null)
            {
                throw new NuKeeperException(
                          $"The provided uri was is not in the correct format. Provided null and format should be {UrlPattern}");
            }

            // Assumption - url should look like https://gitlab.com/{username}/{projectname}.git";
            var path      = repositoryUri.AbsolutePath;
            var pathParts = path.Split('/')
                            .Where(s => !string.IsNullOrWhiteSpace(s))
                            .ToList();

            if (pathParts.Count != 2)
            {
                throw new NuKeeperException(
                          $"The provided uri was is not in the correct format. Provided {repositoryUri} and format should be {UrlPattern}");
            }

            var repoOwner = pathParts[0];
            var repoName  = pathParts[1].Replace(".git", string.Empty);

            var uriBuilder = new UriBuilder(repositoryUri)
            {
                Path = "/api/v4/"
            };

            return(Task.FromResult(new RepositorySettings
            {
                ApiUri = uriBuilder.Uri,
                RepositoryUri = repositoryUri,
                RepositoryName = repoName,
                RepositoryOwner = repoOwner,
                RemoteInfo = targetBranch == null
                    ? null
                    : new RemoteInfo {
                    BranchName = targetBranch
                }
            }));
        }
Ejemplo n.º 4
0
        public Task <RepositorySettings> RepositorySettings(Uri repositoryUri, bool setAutoMerge, string targetBranch = null, GitPullRequestMergeStrategy gitPullRequestMergeStrategy = GitPullRequestMergeStrategy.NoFastForward)
        {
            if (repositoryUri == null)
            {
                return(Task.FromResult <RepositorySettings>(null));
            }

            var path      = repositoryUri.AbsolutePath;
            var pathParts = path.Split('/')
                            .Where(s => !string.IsNullOrWhiteSpace(s))
                            .ToList();

            if (pathParts.Count != 2)
            {
                throw new NuKeeperException($"The provided uri was is not in the correct format. Provided {repositoryUri} and format should be https://[email protected]/projectname/repositoryname.git");
            }

            if (string.IsNullOrWhiteSpace(repositoryUri.UserInfo))
            {
                Username = pathParts[0];
            }
            else
            {
                Username = repositoryUri.UserInfo.Split(':').First();
            }

            var repoName = pathParts[1];

            //Trim off any .git extension from repo name
            repoName = repoName.EndsWith(".git", StringComparison.InvariantCultureIgnoreCase) ?
                       repoName.Substring(0, repoName.LastIndexOf(".git", StringComparison.InvariantCultureIgnoreCase))
                : repoName;
            var owner = pathParts[0];

            return(Task.FromResult(new RepositorySettings
            {
                ApiUri = new Uri("https://api.bitbucket.org/2.0/"),
                RepositoryUri = repositoryUri,
                RepositoryName = repoName,
                RepositoryOwner = owner,
                RemoteInfo = targetBranch != null ? new RemoteInfo {
                    BranchName = targetBranch
                } : null
            }));
        }
Ejemplo n.º 5
0
        public Task <RepositorySettings> RepositorySettings(Uri repositoryUri, bool setAutoMerge, string targetBranch = null, GitPullRequestMergeStrategy gitPullRequestMergeStrategy = GitPullRequestMergeStrategy.NoFastForward)
        {
            if (repositoryUri == null)
            {
                return(Task.FromResult <RepositorySettings>(null));
            }

            var path      = repositoryUri.AbsolutePath;
            var pathParts = path.Split('/')
                            .Where(s => !string.IsNullOrWhiteSpace(s))
                            .ToList();

            Username = Concat.FirstValue(repositoryUri.UserInfo, _environmentVariablesProvider.GetUserName());

            if (pathParts.Count < 2)
            {
                return(Task.FromResult <RepositorySettings>(null));
            }

            var repoName = pathParts[pathParts.Count - 1].ToLower(CultureInfo.CurrentCulture).Replace(".git", string.Empty);
            var project  = pathParts[pathParts.Count - 2];

            return(Task.FromResult(new RepositorySettings
            {
                ApiUri = new Uri($"{repositoryUri.Scheme}://{repositoryUri.Authority}"),
                RepositoryUri = repositoryUri,
                RepositoryName = repoName,
                RepositoryOwner = project
            }));
        }