Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PullRequestRetriever"/> class.
        /// </summary>
        /// <param name="builder">The <see cref="IPullRequestBuilder"/> instance to build pull request objects with.</param>
        /// <param name="client">The <see cref="IPullRequestsClient"/> to use for interfacing with GitHub.</param>
        /// <param name="connection">
        /// The <see cref="IConnection"/> object to interface use when interfacing with GitHub.
        /// </param>
        /// <param name="repository">The <see cref="GitHubRepository"/> containing the pull request to comment on.</param>
        public PullRequestRetriever(
            IPullRequestBuilder builder,
            IPullRequestsClient client,
            IConnection connection,
            GitHubRepository repository)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            this.builder = builder;
            this.client = client;
            this.connection = connection;
            this.repository = repository;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PullRequestCommenter"/> class.
        /// </summary>
        /// <param name="client">The <see cref="IPullRequestReviewCommentsClient"/> to use for making comments.</param>
        /// <param name="repository">The <see cref="GitHubRepository"/> containing the pull request to comment on.</param>
        protected PullRequestCommenter(IPullRequestReviewCommentsClient client, GitHubRepository repository)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            this.client = client;
            this.repository = repository;
        }
Exemplo n.º 3
0
        /// <summary>
        /// The entry method into the application.
        /// </summary>
        /// <param name="args">The application arguments.</param>
        public static void Main(string[] args)
        {
            Comments.Value.Clear();

            Arguments arguments;

            try
            {
                arguments = Arguments.Parse(args);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            var client = new GitHubClient(
                new ProductHeaderValue("OctoStyle"),
                new InMemoryCredentialStore(new Credentials(arguments.Login, arguments.Password)));

            var pathResolver = new PathResolver(new FileSystemManager());

            var repository = new GitHubRepository(arguments.RepositoryOwner, arguments.Repository);

            var builder = new PullRequestBuilder(new DiffParser());
            var pullRequestRetriever = new PullRequestRetriever(builder, client.PullRequest, client.Connection, repository);

            var pullRequest = pullRequestRetriever.RetrieveAsync(arguments.PullRequestNumber).GetAwaiter().GetResult();

            foreach (var file in pullRequest.Files)
            {
                if (file.FileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
                {
                    var filePath = Path.Combine(arguments.SolutionDirectory, file.FileName);

                    var projectPath = pathResolver.GetPath(filePath, "*.csproj");
                    var diffRetriever = new GitHubDiffRetriever(new DifferWrapper(), new GitDiffEntryFactory());

                    var factory = new PullRequestCommenterFactory(client.PullRequest.Comment, repository, diffRetriever);
                    var analyzer = new CodeAnalyzer(projectPath);

                    Comments.Value.Add(factory.GetCommenter(file.Status).Create(pullRequest, file, analyzer, filePath));
                }
            }

            Comments.Value.ForEach(task => task.GetAwaiter().GetResult());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PullRequestCommenterFactory"/> class.
        /// </summary>
        /// <param name="client">The <see cref="IPullRequestReviewCommentsClient"/> to use for interfacing with github.</param>
        /// <param name="repository">The <see cref="GitHubRepository"/> the pull requests are in.</param>
        /// <param name="diffRetriever">The <see cref="IGitHubDiffRetriever"/> to used to retrieve diffs.</param>
        public PullRequestCommenterFactory(
            IPullRequestReviewCommentsClient client,
            GitHubRepository repository,
            IGitHubDiffRetriever diffRetriever)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            this.client = client;
            this.repository = repository;

            this.DiffRetriever = diffRetriever;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RenamedPullRequestCommenter"/> class.
 /// </summary>
 /// <param name="client">The <see cref="IPullRequestReviewCommentsClient"/> to use for making comments.</param>
 /// <param name="repository">The <see cref="GitHubRepository"/> containing the pull request to comment on.</param>
 public RenamedPullRequestCommenter(IPullRequestReviewCommentsClient client, GitHubRepository repository)
     : base(client, repository)
 {
 }