Пример #1
0
 public void AdjustOptionsToCapability(PullRequestOptions options)
 {
     // VSTS doesn't use GitHub-like fork owner system. See property's doc for more info.
     options.AllowBranchOnAnyRepoOwner = true;
     // VSTS adapter client doesn't support comments or reading CI status yet.
     options.TrackDiscardedCommits = false;
 }
        public void build_query_string_with_sort_direction_specified_as_not_specified_build_correct_query_string()
        {
            var sut = new PullRequestOptions {
                SortDirection = SortDirection.NotSpecified
            };

            Assert.Equal("", sut.QueryString);
        }
        public void build_query_string_with_sort_by_set_as_not_specified_return_empty_string()
        {
            var sut = new PullRequestOptions {
                SortBy = PullRequestSortBy.NotSpecified
            };

            Assert.Equal("", sut.QueryString);
        }
        public void build_query_string_with_sort_by_specified_as_long_running_build_correct_query_string()
        {
            var sut = new PullRequestOptions {
                SortBy = PullRequestSortBy.LongRunning
            };

            Assert.Equal("?sort=long-running", sut.QueryString);
        }
        public void build_query_string_with_sort_by_specified_as_updated_build_correct_query_string()
        {
            var sut = new PullRequestOptions {
                SortBy = PullRequestSortBy.Updated
            };

            Assert.Equal("?sort=updated", sut.QueryString);
        }
        public void build_query_string_with_sort_by_specified_as_popularity_build_correct_query_string()
        {
            var sut = new PullRequestOptions {
                SortBy = PullRequestSortBy.Popularity
            };

            Assert.Equal("?sort=popularity", sut.QueryString);
        }
        public void build_query_string_with_state_specified_as_closed_build_correct_query_string()
        {
            var sut = new PullRequestOptions {
                State = PullRequestState.Closed
            };

            Assert.Equal("?state=closed", sut.QueryString);
        }
        public void build_query_string_with_sort_direction_specified_as_desc_build_correct_query_string()
        {
            var sut = new PullRequestOptions {
                SortDirection = SortDirection.Desc
            };

            Assert.Equal("?direction=desc", sut.QueryString);
        }
        public void build_query_string_with_page_options_return_query_string()
        {
            var sut = new PullRequestOptions {
                PageOptions = new PaginationOptions {
                    ResultsPerPage = 50
                }
            };

            Assert.Equal("?per_page=50", sut.QueryString);
        }
        public void build_query_string_with_multiple_values_specified_build_correct_query_string()
        {
            var sut = new PullRequestOptions
            {
                State       = PullRequestState.Open,
                SortBy      = PullRequestSortBy.Updated,
                PageOptions = new PaginationOptions {
                    ResultsPerPage = 1
                }
            };

            Assert.Equal("?state=open&sort=updated&per_page=1", sut.QueryString);
        }
Пример #11
0
        static void GetPullRequestsForOrg(string org, PullRequestState state)
        {
            try
            {
                var repoClient = new RepositoryClient(_userAgent);
                var repoTask   = repoClient.GetAllRepositoriesByOwnerAsync(org);
                Task.WaitAll(repoTask);

                var pullReqClient = new PullRequestClient(_userAgent);
                var parms         = new PullRequestOptions
                {
                    State       = state,
                    PageOptions = new PaginationOptions {
                        ResultsPerPage = 100
                    }
                };

                var tasks = new List <Task <List <PullRequestResponse> > >();
                Parallel.ForEach(repoTask.Result, repo =>
                {
                    var pullReqTask = pullReqClient.GetPullRequestsAsync(org, repo.Name, parms);
                    tasks.Add(pullReqTask);
                });
                Task.WaitAll(tasks.ToArray());

                var pullRequestsForOrg = new List <PullRequestResponse>();
                foreach (var task in tasks)
                {
                    pullRequestsForOrg.AddRange(task.Result);
                }

                Console.WriteLine(pullRequestsForOrg.Count);
            }
            catch (Exception ex)
            {
                if (ex is AggregateException aggEx)
                {
                    ex = ex.InnerException;
                }
                Console.WriteLine(ex.Message, ex);
            }
            finally
            {
                Console.Read();
            }
        }
Пример #12
0
        private static async Task CreatePullRequestAsync(IEnumerable <IDependencyInfo> buildInfos)
        {
            GitHubAuth         gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail);
            PullRequestCreator prCreator  = new PullRequestCreator(gitHubAuth, Options.GitHubUser);
            PullRequestOptions prOptions  = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{Options.GitHubUpstreamBranch}")
            };

            string commitMessage = $"[{Options.GitHubUpstreamBranch}] Update dependencies from dotnet/core-sdk";

            await prCreator.CreateOrUpdateAsync(
                commitMessage,
                commitMessage,
                string.Empty,
                new GitHubBranch(Options.GitHubUpstreamBranch, new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner)),
                new GitHubProject(Options.GitHubProject, gitHubAuth.User),
                prOptions);
        }
Пример #13
0
        private async Task CreatePullRequestAsync(DependencyUpdateResults updateResults)
        {
            var gitHubAuth = new GitHubAuth(GitHubPassword, GitHubUser, GitHubEmail);
            var prCreator  = new PullRequestCreator(gitHubAuth, GitHubUser);
            var prOptions  = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{GitHubUpstreamBranch}")
            };

            var runtimeVersion = updateResults.UsedInfos.First().SimpleVersion;
            var commitMessage  = $"Update aspnetcore on {GitHubUpstreamBranch} to {runtimeVersion}";

            await prCreator.CreateOrUpdateAsync(
                commitMessage,
                commitMessage,
                string.Empty,
                new GitHubBranch(GitHubUpstreamBranch, new GitHubProject(GitHubProject, GitHubUpstreamOwner)),
                new GitHubProject(GitHubProject, gitHubAuth.User),
                prOptions);
        }
Пример #14
0
        private static async Task CreatePullRequestAsync(DependencyUpdateResults updateResults)
        {
            GitHubAuth         gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail);
            PullRequestCreator prCreator  = new PullRequestCreator(gitHubAuth, Options.GitHubUser);
            PullRequestOptions prOptions  = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{Options.GitHubUpstreamBranch}")
            };

            string sdkVersion    = updateResults.UsedInfos.GetBuildVersion(SdkBuildInfoName);
            string commitMessage = $"Update {Options.GitHubUpstreamBranch} SDK to {sdkVersion}";

            await prCreator.CreateOrUpdateAsync(
                commitMessage,
                commitMessage,
                string.Empty,
                new GitHubBranch(Options.GitHubUpstreamBranch, new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner)),
                new GitHubProject(Options.GitHubProject, gitHubAuth.User),
                prOptions);
        }
Пример #15
0
        private static async Task CreatePullRequestAsync()
        {
            // Replace slashes with hyphens for use in naming the branch
            string versionSourceNameForBranch = Options.VersionSourceName.Replace("/", "-");

            GitHubAuth         gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail);
            PullRequestCreator prCreator  = new PullRequestCreator(gitHubAuth, Options.GitHubUser);

            string             branchSuffix = $"UpdateDependencies-{Options.GitHubUpstreamBranch}-From-{versionSourceNameForBranch}";
            PullRequestOptions prOptions    = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy(branchSuffix)
            };

            string        commitMessage   = $"[{Options.GitHubUpstreamBranch}] Update dependencies from {Options.VersionSourceName}";
            GitHubProject upstreamProject = new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner);
            GitHubBranch  upstreamBranch  = new GitHubBranch(Options.GitHubUpstreamBranch, upstreamProject);

            using (GitHubClient client = new GitHubClient(gitHubAuth))
            {
                GitHubPullRequest pullRequestToUpdate = await client.SearchPullRequestsAsync(
                    upstreamProject,
                    upstreamBranch.Name,
                    await client.GetMyAuthorIdAsync());

                if (pullRequestToUpdate == null || pullRequestToUpdate.Head.Ref != $"{upstreamBranch.Name}-{branchSuffix}")
                {
                    await prCreator.CreateOrUpdateAsync(
                        commitMessage,
                        commitMessage,
                        string.Empty,
                        upstreamBranch,
                        new GitHubProject(Options.GitHubProject, gitHubAuth.User),
                        prOptions);
                }
                else
                {
                    UpdateExistingPullRequest(gitHubAuth, prOptions, commitMessage, upstreamBranch);
                }
            }
        }
Пример #16
0
        private void TraceListenedExecute()
        {
            // GitHub and VSTS have different dev flow conventions.
            GitHubProject origin;

            using (IGitHubClient client = CreateClient(out origin))
            {
                var upstreamBranch = new GitHubBranch(
                    ProjectRepoBranch,
                    new GitHubProject(ProjectRepoName, ProjectRepoOwner));

                string body = Body ?? string.Empty;

                if (NotifyGitHubUsers != null)
                {
                    body += PullRequestCreator.NotificationString(NotifyGitHubUsers.Select(item => item.ItemSpec));
                }

                var options = new PullRequestOptions
                {
                    ForceCreate           = AlwaysCreateNewPullRequest,
                    MaintainersCanModify  = MaintainersCanModifyPullRequest,
                    TrackDiscardedCommits = TrackDiscardedCommits
                };

                var prCreator = new PullRequestCreator(client.Auth, PullRequestAuthor);
                prCreator.CreateOrUpdateAsync(
                    CommitMessage,
                    CommitMessage + $" ({ProjectRepoBranch})",
                    body,
                    upstreamBranch,
                    origin,
                    options,
                    client).Wait();
            }
        }
Пример #17
0
        private static async Task CreatePullRequestAsync()
        {
            GitHubAuth         gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail);
            PullRequestCreator prCreator  = new PullRequestCreator(gitHubAuth, Options.GitHubUser);
            PullRequestOptions prOptions  = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{Options.GitHubUpstreamBranch}")
            };

            string        commitMessage   = $"[{Options.GitHubUpstreamBranch}] Update dependencies from dotnet/core-sdk";
            GitHubProject upstreamProject = new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner);
            GitHubBranch  upstreamBranch  = new GitHubBranch(Options.GitHubUpstreamBranch, upstreamProject);

            using (GitHubClient client = new GitHubClient(gitHubAuth))
            {
                GitHubPullRequest pullRequestToUpdate = await client.SearchPullRequestsAsync(
                    upstreamProject,
                    upstreamBranch.Name,
                    await client.GetMyAuthorIdAsync());

                if (pullRequestToUpdate == null)
                {
                    await prCreator.CreateOrUpdateAsync(
                        commitMessage,
                        commitMessage,
                        string.Empty,
                        upstreamBranch,
                        new GitHubProject(Options.GitHubProject, gitHubAuth.User),
                        prOptions);
                }
                else
                {
                    UpdateExistingPullRequest(gitHubAuth, prOptions, commitMessage, upstreamBranch);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Get pull requests belonging to a particular repository for a particular organization with supplied query parameters.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="repoName"></param>
        /// <param name="queryBuilder"></param>
        /// <returns></returns>
        public async Task <List <PullRequestResponse> > GetPullRequestsAsync(string owner, string repoName, PullRequestOptions queryBuilder)
        {
            EnsureThat.ValueIsNotNull(queryBuilder);
            EnsureThat.ValueIsNotEmpty(owner);
            EnsureThat.ValueIsNotEmpty(repoName);

            return(await GetPullRequestsAsync(owner, repoName, queryBuilder.QueryString));
        }
Пример #19
0
        private static void UpdateExistingPullRequest(
            GitHubAuth gitHubAuth, PullRequestOptions prOptions, string commitMessage, GitHubBranch upstreamBranch)
        {
            // PullRequestCreator ends up force-pushing updates to an existing PR which is not great when the logic
            // gets called on a schedule (see https://github.com/dotnet/dotnet-docker/issues/1114). To avoid this,
            // it needs the ability to only update files that have changed from the existing PR.  Because the
            // PullRequestCreator class doesn't rely on there being a locally cloned repo, it doesn't have an
            // efficient way to determine whether files have changed or not. Update-dependencies would have to
            // implement logic which pulls down each file individually from the API and compare it to what exists
            // in the local repo.  Since that's not an efficient process, this method works by cloning the PR's
            // branch to a temporary repo location, grabbing the whole repo where the original updates from
            // update-dependencies were made and copying it into the temp repo, and committing and pushing
            // those changes in the temp repo back to the PR's branch.

            string tempRepoPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            try
            {
                string       branchName   = prOptions.BranchNamingStrategy.Prefix(upstreamBranch.Name);
                CloneOptions cloneOptions = new CloneOptions
                {
                    BranchName = branchName
                };

                // Clone the PR's repo/branch to a temp location
                Repository.Clone($"https://github.com/{gitHubAuth.User}/{Options.GitHubProject}", tempRepoPath, cloneOptions);

                // Remove all existing directories and files from the temp repo
                ClearRepoContents(tempRepoPath);

                // Copy contents of local repo changes to temp repo
                DirectoryCopy(".", tempRepoPath);

                using Repository repo = new Repository(tempRepoPath);
                RepositoryStatus status = repo.RetrieveStatus(new StatusOptions());

                // If there are any changes from what exists in the PR
                if (status.IsDirty)
                {
                    Commands.Stage(repo, "*");

                    Signature signature = new Signature(Options.GitHubUser, Options.GitHubEmail, DateTimeOffset.Now);
                    repo.Commit(commitMessage, signature, signature);

                    Branch branch = repo.Branches[$"origin/{branchName}"];

                    PushOptions pushOptions = new PushOptions
                    {
                        CredentialsProvider = (url, user, credTypes) => new UsernamePasswordCredentials
                        {
                            Username = Options.GitHubPassword,
                            Password = String.Empty
                        }
                    };

                    Remote remote      = repo.Network.Remotes["origin"];
                    string pushRefSpec = $@"refs/heads/{branchName}";

                    repo.Network.Push(remote, pushRefSpec, pushOptions);
                }
            }
            finally
            {
                // Cleanup temp repo
                DeleteRepoDirectory(tempRepoPath);
            }
        }
        public void build_query_string_with_no_values_supplied_returns_empty_string()
        {
            var sut = new PullRequestOptions();

            Assert.Equal("", sut.QueryString);
        }
Пример #21
0
 public void AdjustOptionsToCapability(PullRequestOptions options)
 {
 }
Пример #22
0
 public void AdjustOptionsToCapability(PullRequestOptions options) =>
 _innerClient.AdjustOptionsToCapability(options);
Пример #23
0
 public IQueryBuilder State(PullRequestOptions option)
 {
     _params.Add("state", $@"""{option}""");
     return(this);
 }