Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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
                }
            }));
        }
Beispiel #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
            }));
        }
Beispiel #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
            }));
        }