Example #1
0
        public UpdateResult Update(BuildModel build, string branch, string commitHash)
        {
            try
            {
                var result = new UpdateResult()
                {
                    Id = build.Id
                };

                using (var repo = new Repository(build.Path))
                {
                    _git.Repo = repo;
                    _git.Fetch();
                    var checkoutBranch = _git.Checkout(branch);
                    _git.Pull();

                    if (!string.IsNullOrEmpty(commitHash))
                    {
                        _git.Reset(commitHash, checkoutBranch);
                    }

                    result.Branch        = branch;
                    result.CommitMessage = checkoutBranch.Tip.MessageShort;
                    result.CommitHash    = checkoutBranch.Tip.Sha;
                }

                string buildPath = Path.Combine(build.Path, $"{build.ExecutableName}.dme");
                result.Output = _byond.CompileWorld(buildPath);
                return(result);
            }
            catch (UpdateException ex)
            {
                _logger.LogError(ex, "Error while updating.");
                return(new UpdateResult {
                    Error = true, ErrorMessage = ex.Message
                });
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, "Failed to update.");
                return(new UpdateResult {
                    Error = true, ErrorMessage = ex.Message
                });
            }
        }