public async Task CreatePipeline()
        {
            using var context = await CreateContextAsync();

            using var client = await context.CreateNewUserAsync();

            var project = await client.Projects.CreateAsync("test", defaultBranch : "main");

            await client.RepositoryFiles.CreateFileAsync(project, ".gitlab-ci.yml", "main", TextOrBinaryData.FromString(@"
build1:
  stage: build
  script:
    - echo test
"), "add gitlab-ci");

            var pipelines = await RetryUntilAsync(() => client.Pipelines.GetPipelines(project).ToListAsync(), pipelines => pipelines.Count != 0, TimeSpan.FromSeconds(60));

            var pipeline = await client.Pipelines.CreatePipelineAsync(project, "main", new[] { new PipelineVariableCreate("test", "value") });

            var variables = await client.Pipelines.GetPipelineVariablesAsync(project, pipeline);

            Assert.Collection(variables, variable => Assert.Equal(("test", "value"), (variable.Key, variable.Value)));
        }
Beispiel #2
0
        public async Task GetJob()
        {
            using var context = await CreateContextAsync();

            using var client = await context.CreateNewUserAsync();

            var project = await client.Projects.CreateAsync("test");

            await client.RepositoryFiles.CreateFileAsync(project, ".gitlab-ci.yml", "master", TextOrBinaryData.FromString(@"
build1:
  stage: build
  script:
    - echo test
"), "add gitlab-ci");

            var jobs = await RetryUntilAsync(() => client.Jobs.GetJobs(project).ToListAsync(), jobs => jobs.Count != 0, TimeSpan.FromSeconds(60));

            Assert.Single(jobs);
            Assert.Null(jobs[0].StartedAt);

            using (await context.StartRunnerForOneJobAsync(project))
            {
                var job = await RetryUntilAsync(() => client.Jobs.GetJobAsync(project, jobs[0]), job => job.Status.IsCompleted(), TimeSpan.FromSeconds(60));

                Assert.NotNull(job);
                Assert.NotNull(job.FinishedAt);
            }
        }
        public static async Task <MergeRequest> CreateMergeRequestAsync(this GitLabTestContext context, IGitLabClient client, ProjectIdOrPathRef project,
                                                                        bool assignedToMe = false,
                                                                        bool hasConflict  = false,
                                                                        Action <CreateMergeRequestRequest> configure = null)
        {
            var filePath   = context.GetRandomString();
            var branchName = context.GetRandomString();
            var assignee   = assignedToMe ? await client.Users.GetCurrentUserAsync() : null;

            await client.RepositoryFiles.CreateFileAsync(new CreateFileRepositoryFileRequest(project, filePath, "master", content : context.GetRandomString(), commitMessage : context.GetRandomString()));

            await client.RepositoryFiles.UpdateFileAsync(new UpdateFileRepositoryFileRequest(project, filePath, branchName, content : TextOrBinaryData.FromString(context.GetRandomString(), Encoding.UTF8), commitMessage : context.GetRandomString())
            {
                StartBranch = "master",
            });

            if (hasConflict)
            {
                await client.RepositoryFiles.UpdateFileAsync(new UpdateFileRepositoryFileRequest(project, filePath, "master", content : context.GetRandomString(), commitMessage : context.GetRandomString()));
            }

            // Create merge request
            var request = new CreateMergeRequestRequest(project, branchName, "master", title: context.GetRandomString())
            {
                AssigneeId = assignee,
            };

            configure?.Invoke(request);

            var mergeRequest = await client.MergeRequests.CreateMergeRequestAsync(request);

            return(mergeRequest);
        }
Beispiel #4
0
        public async Task GetArchive()
        {
            using var context = await CreateContextAsync();

            using var client = await context.CreateNewUserAsync();

            var project = await client.Projects.CreateAsync(new CreateProjectRequest { Name = "test" });

            await client.RepositoryFiles.CreateFileAsync(project, "test.txt", "main", TextOrBinaryData.FromString("abc"), "Add test file");

            await using var file1 = await client.Repositories.DownloadFileArchiveAsync(project);

            await using var file2 = await client.Repositories.DownloadFileArchiveAsync(project, format : RepositoryFileArchiveFormat.Zip);

            Assert.EndsWith(".tar.gz", file1.FileName, System.StringComparison.Ordinal);
            Assert.EndsWith(".zip", file2.FileName, System.StringComparison.Ordinal);
        }