/// <summary>
        /// Builds a <see cref="GitHubPullRequest"/>.
        /// </summary>
        /// <param name="number">The pull request number.</param>
        /// <param name="lastCommitId">The last commit ID.</param>
        /// <param name="files">The files in the pull request.</param>
        /// <param name="diff">The full pull request unified diff.</param>
        /// <param name="branches">The <see cref="GitHubPullRequestBranches"/>.</param>
        /// <returns>A <see cref="GitHubPullRequest"/> object.</returns>
        public GitHubPullRequest Build(
            int number,
            string lastCommitId,
            IReadOnlyList<PullRequestFile> files,
            string diff,
            GitHubPullRequestBranches branches)
        {
            if (files == null)
            {
                throw new ArgumentNullException("files");
            }

            var diffs = this.parser.Split(diff);

            var pullRequestFiles =
                files.Select(
                    file =>
                    new GitHubPullRequestFile(
                        file.FileName,
                        (GitHubPullRequestFileStatus)Enum.Parse(typeof(GitHubPullRequestFileStatus), file.Status, true),
                        file.Changes,
                        diffs[file.FileName])).ToList();

            var pullRequest = new GitHubPullRequest(number, lastCommitId, pullRequestFiles, diff, branches);

            return pullRequest;
        }
Esempio n. 2
0
        public GitHubPullRequest(int number, string lastCommitId, IEnumerable<GitHubPullRequestFile> files, string diff, GitHubPullRequestBranches branches)
        {
            const string lastCommitIdParamName = "lastCommitId";

            if (lastCommitId == null)
            {
                throw new ArgumentNullException(lastCommitIdParamName);
            }

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

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

            if (lastCommitId.Length == 0)
            {
                throw new ArgumentException("Cannot be empty", lastCommitIdParamName);
            }

            if (number < 1)
            {
                throw new ArgumentException("Must be greater than 0", "number");
            }

            this.Number = number;
            this.LastCommitId = lastCommitId;
            this.Diff = diff;
            this.Branches = branches;
            this.Files = files.ToList();
        }