Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Apps.GitLab/Actions/RepositoryActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ public RepositoryActions(InvocationContext invocationContext, IFileManagementCli
}

[Action("Create new repository", Description = "Create new repository")]
public Task<Project> CreateRepository([ActionParameter] CreateRepositoryInput input)
public async Task<RepositoryResponse> CreateRepository([ActionParameter] CreateRepositoryInput input)
{
var endpoint = "/projects";

if (input.UserId != null)
endpoint += $"/user/{input.UserId}";

var request = new GitLabRequest(endpoint, Method.Post, Creds)
var request = RestClient.CreateRequest(endpoint, Method.Post)
.WithJsonBody(input.GetNewRepositoryRequest(), JsonConfig.JsonSettings);

return RestClient.ExecuteWithErrorHandling<Project>(request);
var project = await RestClient.ExecuteWithErrorHandling<Project>(request);
return RepositoryResponse.FromProject(project);
}

[Action("Get repository file", Description = "Get repository file by path")]
Expand Down Expand Up @@ -143,8 +144,11 @@ public async Task<GetRepositoryFilesFromFilepathsResponse> GetAllFilesInFolder(
}

[Action("Get repository", Description = "Get repository info")]
public Task<Project> GetRepositoryById([ActionParameter] GetRepositoryRequest input)
=> GetProject(ParseProjectId(input.RepositoryId));
public async Task<RepositoryResponse> GetRepositoryById([ActionParameter] GetRepositoryRequest input)
{
var project = await GetProject(ParseProjectId(input.RepositoryId));
return RepositoryResponse.FromProject(project);
}

[Action("Get repository issues", Description = "Get opened issues against repository")]
public async Task<GetIssuesResponse> GetIssuesInRepository([ActionParameter] RepositoryRequest input)
Expand Down
2 changes: 1 addition & 1 deletion Apps.GitLab/Apps.GitLab.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<Product>GitLab</Product>
<Description>Software development &amp; version control</Description>
<Version>1.0.11</Version>
<Version>1.0.12</Version>
<AssemblyName>Apps.GitLab</AssemblyName>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public Dictionary<string, string> GetData()
{
return new()
{
{"0", "Private"},
{"1", "Internal"},
{"2", "Public"},
{"private", "Private"},
{"internal", "Internal"},
{"public", "Public"},
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;
using GitLabApiClient.Models.Projects.Requests;

namespace Apps.Gitlab.Models.Respository.Requests;

Expand Down Expand Up @@ -97,7 +96,7 @@ public CreateRepositoryRequest GetNewRepositoryRequest()
EnableSnippets = EnableSnippets,
EnableContainerRegistry = EnableContainerRegistry,
EnableSharedRunners = EnableSharedRunners,
Visibility = Visibility != null ? (ProjectVisibilityLevel)int.Parse(Visibility) : null,
Visibility = Visibility,
ImportUrl = ImportUrl,
PublicJobs = PublicJobs,
OnlyAllowMergeIfPipelineSucceeds = OnlyAllowMergeIfPipelineSucceeds,
Expand All @@ -110,4 +109,4 @@ public CreateRepositoryRequest GetNewRepositoryRequest()
InitializeWithReadme = InitializeWithReadme
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using GitLabApiClient.Models.Projects.Requests;
using Newtonsoft.Json;

namespace Apps.GitLab.Models.Respository.Requests;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class CreateRepositoryRequest
public bool? EnableSharedRunners { get; set; }

[JsonProperty("visibility")]
public ProjectVisibilityLevel? Visibility { get; set; }
public string? Visibility { get; set; }

[JsonProperty("import_url")]
public string ImportUrl { get; set; }
Expand Down Expand Up @@ -76,4 +75,4 @@ public class CreateRepositoryRequest

[JsonProperty("initialize_with_readme")]
public bool? InitializeWithReadme { get; set; }
}
}
59 changes: 59 additions & 0 deletions Apps.GitLab/Models/Respository/Responses/RepositoryResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Blackbird.Applications.Sdk.Common;
using GitLabApiClient.Models.Projects.Responses;

namespace Apps.GitLab.Models.Respository.Responses;

public class RepositoryResponse
{
[Display("Repository ID")]
public string Id { get; set; } = string.Empty;

public string Name { get; set; } = string.Empty;

[Display("Path")]
public string? Path { get; set; }

[Display("Path with namespace")]
public string? PathWithNamespace { get; set; }

[Display("Default branch")]
public string? DefaultBranch { get; set; }

public string? Description { get; set; }

public string? Visibility { get; set; }

[Display("Web URL")]
public string? WebUrl { get; set; }

[Display("HTTP URL to repo")]
public string? HttpUrlToRepo { get; set; }

[Display("SSH URL to repo")]
public string? SshUrlToRepo { get; set; }

[Display("Created at")]
public string? CreatedAt { get; set; }

[Display("Last activity at")]
public string? LastActivityAt { get; set; }

public static RepositoryResponse FromProject(Project project)
{
return new()
{
Id = project.Id.ToString(),
Name = project.Name,
Path = project.Path,
PathWithNamespace = project.PathWithNamespace,
DefaultBranch = project.DefaultBranch,
Description = project.Description,
Visibility = project.Visibility.ToString(),
WebUrl = project.WebUrl,
HttpUrlToRepo = project.HttpUrlToRepo,
SshUrlToRepo = project.SshUrlToRepo,
CreatedAt = project.CreatedAt,
LastActivityAt = project.LastActivityAt
};
}
}
41 changes: 41 additions & 0 deletions Tests.GitLab/RepositoryActionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Apps.Gitlab.Actions;
using Apps.Gitlab.Models.Respository.Requests;
using Apps.GitLab.Constants;
using Apps.GitLab.Models.Respository.Requests;
using Blackbird.Applications.Sdk.Common.Invocation;
using Tests.GitLab.Base;

namespace Tests.GitLab;

[TestClass]
public class RepositoryActionTests : TestBaseWithContext
{
[TestMethod, ContextDataSource(ConnectionTypes.PersonalAccessToken)]
public async Task GetRepository_WithExistingRepository_ReturnsRepository(InvocationContext context)
{
var action = new RepositoryActions(context, FileManagementClient);

var result = await action.GetRepositoryById(new GetRepositoryRequest
{
RepositoryId = "71835863"
});

Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.Indented));
Assert.IsNotNull(result);
}

[TestMethod, ContextDataSource(ConnectionTypes.PersonalAccessToken)]
public async Task CreateRepository_WithExistingRepository_ReturnsRepository(InvocationContext context)
{
var action = new RepositoryActions(context, FileManagementClient);

var result = await action.CreateRepository(new CreateRepositoryInput
{
Name = "Test Repository",
});

Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.Indented));
Assert.IsNotNull(result);
}
}