Beispiel #1
0
        public async Task ProjectCreated()
        {
            var createRequest = CreateProjectRequest.FromName(GetRandomProjectName());

            createRequest.Description             = "description1";
            createRequest.EnableContainerRegistry = true;
            createRequest.EnableIssues            = true;
            createRequest.EnableJobs                                = true;
            createRequest.EnableMergeRequests                       = true;
            createRequest.PublicJobs                                = true;
            createRequest.EnableWiki                                = true;
            createRequest.EnableLfs                                 = true;
            createRequest.EnablePrintingMergeRequestLink            = true;
            createRequest.OnlyAllowMergeIfAllDiscussionsAreResolved = true;
            createRequest.OnlyAllowMergeIfPipelineSucceeds          = true;
            createRequest.Visibility                                = ProjectVisibilityLevel.Internal;

            var project = await _sut.CreateAsync(createRequest);

            project.Should().Match <Project>(
                p => p.Description == "description1" &&
                p.ContainerRegistryEnabled &&
                p.IssuesEnabled &&
                p.JobsEnabled &&
                p.MergeRequestsEnabled &&
                p.PublicJobs &&
                p.WikiEnabled &&
                p.OnlyAllowMergeIfAllDiscussionsAreResolved == true &&
                p.OnlyAllowMergeIfPipelineSucceeds == true &&
                p.Visibility == ProjectVisibilityLevel.Internal);

            ProjectIdsToClean.Add(project.Id);
        }
Beispiel #2
0
        public async Task CreatedProjectCanBeUpdated()
        {
            var createRequest = CreateProjectRequest.FromName(GetRandomProjectName());

            createRequest.Description             = "description1";
            createRequest.EnableContainerRegistry = true;
            createRequest.EnableIssues            = true;
            createRequest.EnableJobs                                = true;
            createRequest.EnableMergeRequests                       = true;
            createRequest.PublicJobs                                = true;
            createRequest.EnableWiki                                = true;
            createRequest.EnableLfs                                 = true;
            createRequest.EnablePrintingMergeRequestLink            = true;
            createRequest.OnlyAllowMergeIfAllDiscussionsAreResolved = true;
            createRequest.OnlyAllowMergeIfPipelineSucceeds          = true;
            createRequest.Visibility                                = ProjectVisibilityLevel.Internal;

            var createdProject = await _sut.CreateAsync(createRequest);

            ProjectIdsToClean.Add(createdProject.Id);

            var updatedProject = await _sut.UpdateAsync(new UpdateProjectRequest(createdProject.Id.ToString(), createdProject.Name)
            {
                Description             = "description11",
                EnableContainerRegistry = false,
                EnableIssues            = false,
                EnableJobs          = false,
                EnableMergeRequests = false,
                PublicJobs          = false,
                EnableWiki          = false,
                EnableLfs           = false,
                OnlyAllowMergeIfAllDiscussionsAreResolved = false,
                OnlyAllowMergeIfPipelineSucceeds          = false,
                Visibility = ProjectVisibilityLevel.Public
            });

            updatedProject.Should().Match <Project>(
                p => p.Description == "description11" &&
                !p.ContainerRegistryEnabled &&
                !p.IssuesEnabled &&
                !p.JobsEnabled &&
                !p.MergeRequestsEnabled &&
                p.PublicJobs &&
                !p.WikiEnabled &&
                p.OnlyAllowMergeIfAllDiscussionsAreResolved == false &&
                p.OnlyAllowMergeIfPipelineSucceeds == false &&
                p.Visibility == ProjectVisibilityLevel.Public);
        }
Beispiel #3
0
        private static async Task Main(string[] args)
        {
            const string baseUrl     = "http://localhost";
            const string accessToken = "eyjHuQoFdCE_bP1yXuYN";

            // Gitlab has GraphQL support :)
            // It sucks, but it's there.
            //await _client.PostAsync("http://localhost/api/v4/features/graphql", new StringContent("value=100"));

            var projectName        = "Test5";
            var projectGroup       = "TestProjects";
            var projectDescription = "Test Project";
            var groupDescription   = "Test Group";

            var client = new GitLabClient(baseUrl, accessToken);

            var groups = await client.Groups.GetAsync();

            var group = groups.FirstOrDefault(g =>
                                              string.Equals(g.Name, projectGroup, StringComparison.OrdinalIgnoreCase));

            if (group == null)
            {
                Console.WriteLine("Creating group " + projectGroup);
                group = await client.Groups.CreateAsync(new CreateGroupRequest(projectGroup, projectGroup)
                {
                    LfsEnabled           = true,
                    RequestAccessEnabled = true,
                    Visibility           = GroupsVisibility.Internal,
                    Description          = groupDescription
                });
            }

            var projects = await client.Projects.GetAsync();

            var project = projects.FirstOrDefault(p =>
                                                  p.Namespace.Kind == "group" &&
                                                  p.Namespace.Name.Equals(projectGroup, StringComparison.OrdinalIgnoreCase) &&
                                                  p.Name.Equals(projectName, StringComparison.OrdinalIgnoreCase));

            if (project == null)
            {
                Console.WriteLine("Creating project " + projectName);
                var req = CreateProjectRequest.FromName(projectName);

                req.NamespaceId             = group.Id;
                req.Description             = projectDescription;
                req.EnableContainerRegistry = false;
                req.EnableIssues            = true;
                req.EnableWiki                                = true;
                req.EnableJobs                                = true;
                req.EnableLfs                                 = true;
                req.EnableMergeRequests                       = true;
                req.EnableRequestAccess                       = true;
                req.EnableSharedRunners                       = true;
                req.EnableSnippets                            = true;
                req.EnablePrintingMergeRequestLink            = true;
                req.OnlyAllowMergeIfAllDiscussionsAreResolved = true;
                req.OnlyAllowMergeIfPipelineSucceeds          = true;
                req.PublicBuilds                              = false;
                req.Visibility                                = ProjectVisibilityLevel.Internal;

                project = await client.Projects.CreateAsync(req);
            }
            else
            {
                Console.Error.WriteLine($"Project {projectName} already exists at {project.WebUrl}");
                Console.ReadLine();
                return;
            }


            Console.WriteLine("Committing starter readme to master branch");

            // TODO: Pull the readme...
            await client.Projects.CreateCommit(project.Id, new CreateCommitRequest
            {
                Branch        = "master",
                CommitMessage = "Initial Commit",
                Actions       = new List <CommitAction>
                {
                    new CreateAction
                    {
                        // TODO: Replace this with a boilerplate "project instructions" readme
                        Content  = "# Project Instructions",
                        FilePath = "README.md",
                    }
                }
            });

            Console.WriteLine("Creating develop branch");

            await client.Projects.CreateBranch(project.Id, "master", "develop");

            // Update the default branch to point to develop now that it exists
            await client.Projects.UpdateAsync(new UpdateProjectRequest(project.Id.ToString(), projectName)
            {
                DefaultBranch = "develop"
            });

            // Console.WriteLine("Protecting master branch");
            // await client.Projects.ProtectBranch(project.Id, "master");
            Console.WriteLine("Protecting develop branch");
            await client.Projects.ProtectBranch(project.Id, "develop", AccessLevel.Maintainer, AccessLevel.Maintainer,
                                                AccessLevel.Maintainer);

            Console.WriteLine("Finished creating project. Visit " + project.WebUrl);
            Console.ReadLine();
        }