Esempio n. 1
0
        public async Task PushFilesAsync(
            List <GitFile> filesToCommit,
            string repoUri,
            string branch,
            string commitMessage)
        {
            using (_logger.BeginScope("Pushing files to {branch}", branch))
            {
                (string owner, string repo) = ParseRepoUri(repoUri);

                string baseCommitSha = await Client.Repository.Commit.GetSha1(owner, repo, branch);

                Octokit.Commit baseCommit = await Client.Git.Commit.Get(owner, repo, baseCommitSha);

                TreeResponse baseTree = await Client.Git.Tree.Get(owner, repo, baseCommit.Tree.Sha);

                TreeResponse newTree = await CreateGitHubTreeAsync(owner, repo, filesToCommit, baseTree);

                Octokit.Commit newCommit = await Client.Git.Commit.Create(
                    owner,
                    repo,
                    new NewCommit(commitMessage, newTree.Sha, baseCommit.Sha));

                await Client.Git.Reference.Update(owner, repo, $"heads/{branch}", new ReferenceUpdate(newCommit.Sha));
            }
        }
        /// <summary>
        /// Creates a new commit.
        /// </summary>
        private async Task <Octokit.Commit> CreateCommitAsync(
            GitHubRepository repository,
            string commitMessage,
            IList <IArchiveFile> fileContents,
            Octokit.Commit parentCommit)
        {
            var newTreeResponse = await RetryGitHubOperationIfNeededAsync
                                  (
                async() => await _client.Git.Tree.Create
                (
                    repository.Owner,
                    repository.Name,
                    await GetTreeToPushAsync
                    (
                        repository,
                        fileContents,
                        parentCommit?.Tree?.Sha
                    )
                )
                                  );

            return(await RetryGitHubOperationIfNeededAsync
                   (
                       () => _client.Git.Commit.Create
                       (
                           repository.Owner,
                           repository.Name,
                           parentCommit != null
                                                ? new NewCommit(commitMessage, newTreeResponse.Sha, parentCommit.Sha)
                                                : new NewCommit(commitMessage, newTreeResponse.Sha)
                       )
                   ));
        }
Esempio n. 3
0
 public PagesBuild(string url, PagesBuildStatus status, ApiError error, User pusher, Commit commit, TimeSpan duration, DateTime createdAt, DateTime updatedAt)
 {
     Url = url;
     Status = status;
     Error = error;
     Pusher = pusher;
     Commit = commit;
     Duration = duration;
     CreatedAt = createdAt;
     UpdatedAt = updatedAt;
 }
Esempio n. 4
0
 public GitHubCommit(string url, string label, string @ref, string sha, User user, Repository repository, Author author, string commentsUrl, Commit commit, Author committer, string htmlUrl, GitHubCommitStats stats, IReadOnlyList<GitReference> parents, IReadOnlyList<GitHubCommitFile> files)
     : base(url, label, @ref, sha, user, repository)
 {
     Author = author;
     CommentsUrl = commentsUrl;
     Commit = commit;
     Committer = committer;
     HtmlUrl = htmlUrl;
     Stats = stats;
     Parents = parents;
     Files = files;
 }
Esempio n. 5
0
        public Merge(Author author, Author committer, Commit commit, IEnumerable<GitReference> parents, string commentsUrl, int commentCount, string htmlUrl)
        {
            Ensure.ArgumentNotNull(parents, "parents");

            Author = author;
            Committer = committer;
            Commit = commit;
            Parents = new ReadOnlyCollection<GitReference>(parents.ToList());
            CommentsUrl = commentsUrl;
            CommentCount = commentCount;
            HtmlUrl = htmlUrl;
        }
Esempio n. 6
0
        public PullRequestCommit(Committer author, Uri commentsUrl, Commit commit, Committer committer, Uri htmlUrl, IEnumerable<GitReference> parents, string sha, Uri url)
        {
            Ensure.ArgumentNotNull(parents, "parents");

            Author = author;
            CommentsUrl = commentsUrl;
            Commit = commit;
            Committer = committer;
            HtmlUrl = htmlUrl;
            Parents = new ReadOnlyCollection<GitReference>(parents.ToList());
            Sha = sha;
            Url = url;
        }
Esempio n. 7
0
        private static void ValidateLocalRepository(Octokit.Commit expectedCommit)
        {
            var root = DirectoryLayout.DetermineRootDirectory();

            using (var repo = new LibGit2Sharp.Repository(root))
            {
                string tip = repo.Head.Tip.Sha;
                if (tip != expectedCommit.Sha)
                {
                    throw new UserErrorException($"Current local commit: {tip}. Aborting.");
                }
                var status = repo.RetrieveStatus("apis/apis.json");
                if (status != FileStatus.Unaltered)
                {
                    throw new UserErrorException($"Expected apis.json to be unaltered. Current status: {status}. Aborting.");
                }
            }
        }
        private async Task <TreeResponse> GetTreeForPathAsync(string owner, string repo, string commitSha, string path)
        {
            var pathSegments = new Queue <string>(path.Split('/', '\\'));
            var currentPath  = new List <string>();

            Octokit.Commit commit = await Client.Git.Commit.Get(owner, repo, commitSha);

            string treeSha = commit.Tree.Sha;

            while (true)
            {
                TreeResponse tree = await Client.Git.Tree.Get(owner, repo, treeSha);

                if (tree.Truncated)
                {
                    throw new NotSupportedException(
                              $"The git repository is too large for the github api. Getting tree '{treeSha}' returned truncated results.");
                }

                if (pathSegments.Count < 1)
                {
                    return(tree);
                }

                string subfolder = pathSegments.Dequeue();
                currentPath.Add(subfolder);
                TreeItem subfolderItem = tree.Tree.Where(ti => ti.Type == TreeType.Tree)
                                         .FirstOrDefault(ti => ti.Path == subfolder);
                if (subfolderItem == null)
                {
                    throw new DirectoryNotFoundException(
                              $"The path '{string.Join("/", currentPath)}' could not be found.");
                }

                treeSha = subfolderItem.Sha;
            }
        }
 public RepositoryContentChangeSet(RepositoryContentInfo content, Commit commit)
 {
     Content = content;
     Commit = commit;
 }
Esempio n. 10
0
        private static async Task MakeReleasesAsync(GitHubClient client, List <ApiMetadata> newReleases, Octokit.Commit commit)
        {
            var originalMessage  = commit.Message;
            var unwrappedMessage = string.Join("\n", UnwrapLines(originalMessage.Split('\n')));

            foreach (var api in newReleases)
            {
                var gitRelease = new NewRelease($"{api.Id}-{api.Version}")
                {
                    Prerelease      = !api.IsReleaseVersion,
                    Name            = $"{api.Version} release of {api.Id}",
                    TargetCommitish = commit.Sha,
                    Body            = unwrappedMessage
                };
                // We could parallelize, but there's very little point.
                await client.Repository.Release.Create(RepositoryOwner, RepositoryName, gitRelease);

                Console.WriteLine($"Created release for {api.Id}");
            }
        }
        /// <summary>
        /// Creates a contribution object given a string
        /// </summary>
        /// <param name="c">The commit object from Github</param>
        /// <param name="sha">The unique Sha from the Github commit object</param>
        /// <returns></returns>
        Contribution CreateContribution(Commit c, string sha)
        {
            var fact = new Contribution()
            {
                Sha = sha,
                Author = new Author()
                {
                    Name = c.Author.Name,
                    Email = c.Author.Email
                },
                Date = c.Author.Date.UtcDateTime,
                Email = c.Author.Email,
                Message = c.Message,

                Spec = new Spec()
                {
                    Name = RegexSpecName(c.Message)
                },

                Organization = new Organization()
                {
                    Name = TrackerData.GetNameAndOrganization(c.Author.Email)[1]
                },
                Tracker = new Tracker()
                {
                    Name = "Github"
                },
                Url = c.Url
            };

            return fact;
        }