Ejemplo n.º 1
0
    public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId()
    {
        var commits = CreateCommits(6);

        foreach (var commit in commits)
        {
            var newDeployment = new NewDeployment(commit.Sha)
            {
                AutoMerge = false
            };
            await _deploymentsClient.Create(_context.Repository.Id, newDeployment);
        }

        var startOptions = new ApiOptions
        {
            PageSize  = 3,
            PageCount = 1
        };

        var firstPage = await _deploymentsClient.GetAll(_context.Repository.Id, startOptions);

        var skipStartOptions = new ApiOptions
        {
            PageSize  = 3,
            PageCount = 1,
            StartPage = 2
        };

        var secondPage = await _deploymentsClient.GetAll(_context.Repository.Id, skipStartOptions);

        Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
        Assert.NotEqual(firstPage[1].Id, secondPage[1].Id);
        Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
    }
Ejemplo n.º 2
0
    public async Task CanCreateDeployment()
    {
        var newDeployment = new NewDeployment {
            Ref = _commit.Sha
        };

        var deployment = await _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment);

        Assert.NotNull(deployment);
    }
            public void CallsCreateOnRegularDeploymentsClientWithRepositoryId()
            {
                SetupWithoutNonReactiveClient();

                var newDeployment = new NewDeployment("ref");

                _client.Create(1, newDeployment);

                _githubClient.Repository.Deployment.Received(1).Create(1, newDeployment);
            }
Ejemplo n.º 4
0
    public async Task CanCreateDeploymentWithRepositoryId()
    {
        var newDeployment = new NewDeployment(_commit.Sha)
        {
            AutoMerge = false
        };

        var deployment = await _deploymentsClient.Create(_context.Repository.Id, newDeployment);

        Assert.NotNull(deployment);
    }
Ejemplo n.º 5
0
            public void CallsCreateOnRegularDeploymentsClient()
            {
                SetupWithoutNonReactiveClient();

                var newDeployment = new NewDeployment();

                _client.Create("owner", "repo", newDeployment);
                _githubClient.Deployment.Received(1).Create(Arg.Is("owner"),
                                                            Arg.Is("repo"),
                                                            Arg.Is(newDeployment));
            }
Ejemplo n.º 6
0
    public async Task CanGetDeployments()
    {
        var newDeployment = new NewDeployment {
            Ref = _commit.Sha
        };
        await _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment);

        var deployments = await _deploymentsClient.GetAll(_repositoryOwner, _repository.Name);

        Assert.NotEmpty(deployments);
    }
Ejemplo n.º 7
0
        public void CanSerialize()
        {
            var deployment = new NewDeployment("ref")
            {
                Payload = new Dictionary <string, string> {
                    { "environment", "production" }
                }
            };
            var deserialized = new SimpleJsonSerializer().Serialize(deployment);

            Assert.Equal(@"{""ref"":""ref"",""task"":""deploy"",""payload"":{""environment"":""production""}}", deserialized);
        }
Ejemplo n.º 8
0
    public async Task ReturnsDeploymentsWithRepositoryId()
    {
        var newDeployment = new NewDeployment(_commit.Sha)
        {
            AutoMerge = false
        };
        await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment);

        var deployments = await _deploymentsClient.GetAll(_context.Repository.Id);

        Assert.NotEmpty(deployments);
    }
Ejemplo n.º 9
0
    public async Task CanCreateDeployment()
    {
        var newDeployment = new NewDeployment(_commit.Sha)
        {
            AutoMerge = false, TransientEnvironment = true, ProductionEnvironment = true
        };

        var deployment = await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment);

        Assert.NotNull(deployment);
        Assert.Equal(newDeployment.TransientEnvironment, deployment.TransientEnvironment);
        Assert.Equal(newDeployment.ProductionEnvironment, deployment.ProductionEnvironment);
    }
    public DeploymentStatusClientTests()
    {
        _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
        {
            Credentials = Helper.Credentials
        };

        _deploymentsClient = _gitHubClient.Repository.Deployment;

        var newRepository = new NewRepository
        {
            Name     = Helper.MakeNameWithTimestamp("public-repo"),
            AutoInit = true
        };

        _repository      = _gitHubClient.Repository.Create(newRepository).Result;
        _repositoryOwner = _repository.Owner.Login;

        var blob = new NewBlob
        {
            Content  = "Hello World!",
            Encoding = EncodingType.Utf8
        };

        var blobResult = _gitHubClient.GitDatabase.Blob.Create(_repositoryOwner, _repository.Name, blob).Result;

        var newTree = new NewTree();

        newTree.Tree.Add(new NewTreeItem
        {
            Type = TreeType.Blob,
            Mode = FileMode.File,
            Path = "README.md",
            Sha  = blobResult.Sha
        });

        var treeResult = _gitHubClient.GitDatabase.Tree.Create(_repositoryOwner, _repository.Name, newTree).Result;
        var newCommit  = new NewCommit("test-commit", treeResult.Sha);

        _commit = _gitHubClient.GitDatabase.Commit.Create(_repositoryOwner, _repository.Name, newCommit).Result;

        var newDeployment = new NewDeployment {
            Ref = _commit.Sha
        };

        _deployment = _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment).Result;
    }
Ejemplo n.º 11
0
        /// <inheritdoc/>
        protected override async Task <object> CallGitHubApi(DialogContext dc, Octokit.GitHubClient gitHubClient, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (Owner != null && Name != null && NewDeployment != null)
            {
                var ownerValue         = Owner.GetValue(dc.State);
                var nameValue          = Name.GetValue(dc.State);
                var newDeploymentValue = NewDeployment.GetValue(dc.State);
                return(await gitHubClient.Repository.Deployment.Create(ownerValue, nameValue, newDeploymentValue).ConfigureAwait(false));
            }
            if (RepositoryId != null && NewDeployment != null)
            {
                var repositoryIdValue  = RepositoryId.GetValue(dc.State);
                var newDeploymentValue = NewDeployment.GetValue(dc.State);
                return(await gitHubClient.Repository.Deployment.Create((Int64)repositoryIdValue, newDeploymentValue).ConfigureAwait(false));
            }

            throw new ArgumentNullException("Required [newDeployment] arguments missing for GitHubClient.Repository.Deployment.Create");
        }
Ejemplo n.º 12
0
        public async Task <IHttpActionResult> Post(string name, string serverName, [FromBody] NewDeployment payload)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(payload?.NetworkPath))
                {
                    return(BadRequest("You must include the field `NetworkPath` in the body."));
                }
                var application = await applicationRepository.GetApplicationAsync(name);

                if (application == null)
                {
                    return(BadRequest("The application " + name + " does not exist."));
                }

                if (!Directory.Exists(payload.NetworkPath))
                {
                    return(BadRequest("The path `" + payload.NetworkPath + "` is invalid or inaccessible."));
                }

                var deployment = new Deployment
                {
                    ApplicationName = name,
                    ServerName      = serverName,
                    NetworkPath     = payload.NetworkPath
                };

                var deploymentAudit = await applicationHashingService.HashDeployment(deployment, application.GetRegularExpressions(), application.HashHiddenFiles, true);

                await deploymentRepository.InsertDeploymentAsync(deployment);

                await auditRepository.CreateAuditAsync(deploymentAudit);

                deployment.FileHashes = null;
                return(Ok(deployment));
            }
            catch (Exception ex)
            {
                Log.Error("Error in deployment controller:", ex);
                return(InternalServerError());
            }
        }
Ejemplo n.º 13
0
    public DeploymentStatusClientTests()
    {
        var github = Helper.GetAuthenticatedClient();

        _deploymentsClient = github.Repository.Deployment;
        _context           = github.CreateRepositoryContext("public-repo").Result;

        var blob = new NewBlob
        {
            Content  = "Hello World!",
            Encoding = EncodingType.Utf8
        };

        var blobResult = github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob).Result;

        var newTree = new NewTree();

        newTree.Tree.Add(new NewTreeItem
        {
            Type = TreeType.Blob,
            Mode = FileMode.File,
            Path = "README.md",
            Sha  = blobResult.Sha
        });

        var treeResult = github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree).Result;
        var newCommit  = new NewCommit("test-commit", treeResult.Sha);

        var commit = github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result;

        var newDeployment = new NewDeployment(commit.Sha)
        {
            Environment = "production",
            AutoMerge   = false
        };

        _deployment = _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment).Result;
    }
        public void NewDeployment_ValidDeployment_DeploymentContext()
        {
            // Arrange
            //"128791C3DE5076FBA441F2EAEE72B4F932C9B377",
            var target = new NewDeployment
            {
                SubscriptionId          = "5889ed88-7690-4ecb-9c16-bd76e737ddd3",
                CertificateThumbprintId = "76619850EDE5B64F41F084BA2C08C7FCF1AB1F41",
                Slot                  = "Production",
                ServiceName           = "shinglworkflow",
                ConfigurationFilePath = "C:\\Users\\stuart\\Desktop\\Shingl.Production.WorkflowHost.cscfg",
                // DeploymentName = "workflow",
                DeploymentLabel = "Shingl.Production.WorkflowHost - 20110813_001132", // Shows up as deployment name in Azure
                PackageUrl      = "http://shingl.blob.core.windows.net/mydeployments/20110813_001132_Shingl.Role.WorkflowHost.cspkg"
            };

            // Act
            IDictionary <string, object> results = WorkflowInvoker.Invoke(target, new Dictionary <string, object>());
            string operationId = (string)results["OperationId"];

            // Assert
            Assert.IsNotNull(operationId);
        }
Ejemplo n.º 15
0
    public async Task ReturnsCorrectCountOfDeploymentsWithoutStart()
    {
        var commits = CreateCommits(6);

        foreach (var commit in commits)
        {
            var newDeployment = new NewDeployment(commit.Sha)
            {
                AutoMerge = false
            };
            await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment);
        }

        var options = new ApiOptions
        {
            PageSize  = 5,
            PageCount = 1
        };

        var releases = await _deploymentsClient.GetAll(_context.RepositoryOwner, _context.RepositoryName, options);

        Assert.Equal(5, releases.Count);
    }
        /// <summary>
        /// Creates a new deployment for the specified repository.
        /// Users with push access can create a deployment for a given ref.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/repos/deployments/#create-a-deployment
        /// </remarks>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
        public IObservable<Deployment> Create(int repositoryId, NewDeployment newDeployment)
        {
            Ensure.ArgumentNotNull(newDeployment, "newDeployment");

            return _client.Create(repositoryId, newDeployment).ToObservable();
        }
        /// <summary>
        /// Creates a new deployment for the specified repository.
        /// Users with push access can create a deployment for a given ref.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/repos/deployments/#create-a-deployment
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
        public IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment)
        {
            Ensure.ArgumentNotNull(newDeployment, "newDeployment");

            return _client.Create(owner, name, newDeployment).ToObservable();
        }
 /// <summary>
 /// Creates a new deployment for the specified repository.
 /// Users with push access can create a deployment for a given ref.
 /// </summary>
 /// <remarks>
 /// http://developer.github.com/v3/repos/deployments/#create-a-deployment
 /// </remarks>
 /// <param name="owner">The owner of the repository</param>
 /// <param name="name">The name of the repository</param>
 /// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
 /// <returns>The created <see cref="Deployment"></returns>
 public IObservable <Deployment> Create(string owner, string name, NewDeployment newDeployment)
 {
     return(_client.Create(owner, name, newDeployment).ToObservable());
 }
            public void CallsCreateOnRegularDeploymentsClient()
            {
                SetupWithoutNonReactiveClient();

                var newDeployment = new NewDeployment();
                _client.Create("owner", "repo", newDeployment);
                _githubClient.Repository.Deployment.Received(1).Create(Arg.Is("owner"),
                                                            Arg.Is("repo"),
                                                            Arg.Is(newDeployment));
            }
            public void CallsCreateOnRegularDeploymentsClientWithRepositoryId()
            {
                SetupWithoutNonReactiveClient();

                var newDeployment = new NewDeployment("ref");

                _client.Create(1, newDeployment);

                _githubClient.Repository.Deployment.Received(1).Create(1, newDeployment);
            }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a new deployment for the specified repository.
        /// Users with push access can create a deployment for a given ref.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/repos/deployments/#create-a-deployment
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
        public IObservable <Deployment> Create(long repositoryId, NewDeployment newDeployment)
        {
            Ensure.ArgumentNotNull(newDeployment, nameof(newDeployment));

            return(_client.Create(repositoryId, newDeployment).ToObservable());
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a new deployment for the specified repository.
        /// Users with push access can create a deployment for a given ref.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/repos/deployments/#create-a-deployment
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
        public IObservable <Deployment> Create(string owner, string name, NewDeployment newDeployment)
        {
            Ensure.ArgumentNotNull(newDeployment, nameof(newDeployment));

            return(_client.Create(owner, name, newDeployment).ToObservable());
        }
 /// <summary>
 /// Creates a new deployment for the specified repository.
 /// Users with push access can create a deployment for a given ref.
 /// </summary>
 /// <remarks>
 /// http://developer.github.com/v3/repos/deployments/#create-a-deployment
 /// </remarks>
 /// <param name="owner">The owner of the repository</param>
 /// <param name="name">The name of the repository</param>
 /// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
 /// <returns>The created <see cref="Deployment"/></returns>
 public IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment)
 {
     return _client.Create(owner, name, newDeployment).ToObservable();
 }