Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH actions pipeline improvements #4

Merged
merged 2 commits into from
May 22, 2024
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
25 changes: 23 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
name: "CI: Build and Test"

on:
push:
branches: [main]
paths:
- "**.cs"
- "**.tsx"
- "**.js"
- "**.csproj"
- "**.props"
- "**.targets"
- "**.sln"
pull_request:
branches: [main]
paths:
Expand All @@ -15,9 +25,20 @@ on:
- "**.sln"

jobs:
dotnet-format:
name: dotnet-format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run dotnet format
run: dotnet format --exclude ./examples/** --verify-no-changes

build_and_test:
name: Build and Test
runs-on: ubuntu-latest
needs: dotnet-format
defaults:
run:
shell: pwsh
Expand All @@ -29,10 +50,10 @@ jobs:
DOTNET_NOLOGO: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Kentico.Xperience.Ecommerce.Common.ContentItemSynchronization;

/// <summary>
/// Interface for synchronized content items.
/// </summary>
public class ContentItemAddParams
{
public required ContentItemSynchronizationBase ContentItem { get; set; }

public required string LanguageName { get; set; }

public int UserID { get; set; }
}
namespace Kentico.Xperience.Ecommerce.Common.ContentItemSynchronization;
/// <summary>
/// Interface for synchronized content items.
/// </summary>
public class ContentItemAddParams
{
public required ContentItemSynchronizationBase ContentItem { get; set; }
public required string LanguageName { get; set; }
public int UserID { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,130 +1,130 @@
using CMS.ContentEngine;

namespace Kentico.Xperience.Ecommerce.Common.ContentItemSynchronization;

/// <summary>
/// Service for content items management
/// </summary>
public class ContentItemServiceBase : IContentItemService
{
protected readonly IContentItemManagerFactory ContentItemManagerFactory;

protected readonly IContentQueryExecutor ContentQueryExecutor;

protected readonly IContentQueryResultMapper ContentQueryResultMapper;


public ContentItemServiceBase(
IContentItemManagerFactory contentItemManagerFactory,
IContentQueryExecutor contentQueryExecutor,
IContentQueryResultMapper contentQueryResultMapper)
{
ContentItemManagerFactory = contentItemManagerFactory;
ContentQueryExecutor = contentQueryExecutor;
ContentQueryResultMapper = contentQueryResultMapper;
}


///<inheritdoc/>
public async Task<int> AddContentItem(ContentItemAddParams addParams)
{
ArgumentNullException.ThrowIfNull(addParams);

var createParams = new CreateContentItemParameters(
addParams.ContentItem.ContentTypeName,
addParams.ContentItem.GenerateCodeName(),
addParams.ContentItem.DisplayName,
addParams.LanguageName);
var itemData = new ContentItemData(addParams.ContentItem.ToDict());

var contentItemManager = ContentItemManagerFactory.Create(addParams.UserID);
int itemID = await contentItemManager.Create(createParams, itemData);
await contentItemManager.TryPublish(itemID, addParams.LanguageName);

return itemID;
}


///<inheritdoc/>
public async Task<bool> UpdateContentItem(ContentItemUpdateParams updateParams)
{
var contentItemManager = ContentItemManagerFactory.Create(updateParams.UserID);
var versionStatus = updateParams.VersionStatus;

// If content item version is not draft, create draft in order to edit it
if (versionStatus != VersionStatus.Draft &&
versionStatus != VersionStatus.InitialDraft &&
!await contentItemManager.TryCreateDraft(updateParams.ContentItemID, updateParams.LanguageName))
{
return false;
}

var itemData = new ContentItemData(updateParams.ContentItemParams);
if (!await contentItemManager.TryUpdateDraft(updateParams.ContentItemID, updateParams.LanguageName, itemData))
{
return false;
}

return versionStatus switch
{
VersionStatus.Published => await contentItemManager.TryPublish(updateParams.ContentItemID, updateParams.LanguageName),
VersionStatus.Archived => await contentItemManager.TryArchive(updateParams.ContentItemID, updateParams.LanguageName),
VersionStatus.InitialDraft => true,
VersionStatus.Draft => true,
_ => true,
};
}


///<inheritdoc/>
public async Task<IEnumerable<T>> GetContentItems<T>(string contentType, Action<ContentTypeQueryParameters> queryParams)
where T : IContentItemFieldsSource, new()
{
var builder = new ContentItemQueryBuilder()
.ForContentType(contentType, queryParams);

return await ContentQueryExecutor.GetResult(builder, ContentQueryResultMapper.Map<T>);
}


///<inheritdoc/>
public async Task<IEnumerable<T>> GetContentItems<T>(string contentType)
where T : IContentItemFieldsSource, new() => await GetContentItems<T>(contentType, 0);


///<inheritdoc/>
public async Task<IEnumerable<T>> GetContentItems<T>(string contentType, int linkedItemsLevel)
where T : IContentItemFieldsSource, new()
{
var builder = new ContentItemQueryBuilder()
.ForContentType(contentType, config => config.WithLinkedItems(linkedItemsLevel));

return await ContentQueryExecutor.GetResult(builder, ContentQueryResultMapper.Map<T>);
}


///<inheritdoc/>
public async Task DeleteContentItem(int contentItemID, string languageName, int userID)
{
var contentItemManager = ContentItemManagerFactory.Create(userID);
await contentItemManager.Delete(contentItemID, languageName);
}


///<inheritdoc/>
public async Task DeleteContentItems(IEnumerable<int> contentItemIDs, string languageName, int userID)
{
if (!contentItemIDs.Any())
{
return;
}

var contentItemManager = ContentItemManagerFactory.Create(userID);

foreach (int contentItemID in contentItemIDs)
{
await contentItemManager.Delete(contentItemID, languageName);
}
}
}

using CMS.ContentEngine;
namespace Kentico.Xperience.Ecommerce.Common.ContentItemSynchronization;
/// <summary>
/// Service for content items management
/// </summary>
public class ContentItemServiceBase : IContentItemService
{
protected readonly IContentItemManagerFactory ContentItemManagerFactory;
protected readonly IContentQueryExecutor ContentQueryExecutor;
protected readonly IContentQueryResultMapper ContentQueryResultMapper;
public ContentItemServiceBase(
IContentItemManagerFactory contentItemManagerFactory,
IContentQueryExecutor contentQueryExecutor,
IContentQueryResultMapper contentQueryResultMapper)
{
ContentItemManagerFactory = contentItemManagerFactory;
ContentQueryExecutor = contentQueryExecutor;
ContentQueryResultMapper = contentQueryResultMapper;
}
///<inheritdoc/>
public async Task<int> AddContentItem(ContentItemAddParams addParams)
{
ArgumentNullException.ThrowIfNull(addParams);
var createParams = new CreateContentItemParameters(
addParams.ContentItem.ContentTypeName,
addParams.ContentItem.GenerateCodeName(),
addParams.ContentItem.DisplayName,
addParams.LanguageName);
var itemData = new ContentItemData(addParams.ContentItem.ToDict());
var contentItemManager = ContentItemManagerFactory.Create(addParams.UserID);
int itemID = await contentItemManager.Create(createParams, itemData);
await contentItemManager.TryPublish(itemID, addParams.LanguageName);
return itemID;
}
///<inheritdoc/>
public async Task<bool> UpdateContentItem(ContentItemUpdateParams updateParams)
{
var contentItemManager = ContentItemManagerFactory.Create(updateParams.UserID);
var versionStatus = updateParams.VersionStatus;
// If content item version is not draft, create draft in order to edit it
if (versionStatus != VersionStatus.Draft &&
versionStatus != VersionStatus.InitialDraft &&
!await contentItemManager.TryCreateDraft(updateParams.ContentItemID, updateParams.LanguageName))
{
return false;
}
var itemData = new ContentItemData(updateParams.ContentItemParams);
if (!await contentItemManager.TryUpdateDraft(updateParams.ContentItemID, updateParams.LanguageName, itemData))
{
return false;
}
return versionStatus switch
{
VersionStatus.Published => await contentItemManager.TryPublish(updateParams.ContentItemID, updateParams.LanguageName),
VersionStatus.Archived => await contentItemManager.TryArchive(updateParams.ContentItemID, updateParams.LanguageName),
VersionStatus.InitialDraft => true,
VersionStatus.Draft => true,
_ => true,
};
}
///<inheritdoc/>
public async Task<IEnumerable<T>> GetContentItems<T>(string contentType, Action<ContentTypeQueryParameters> queryParams)
where T : IContentItemFieldsSource, new()
{
var builder = new ContentItemQueryBuilder()
.ForContentType(contentType, queryParams);
return await ContentQueryExecutor.GetResult(builder, ContentQueryResultMapper.Map<T>);
}
///<inheritdoc/>
public async Task<IEnumerable<T>> GetContentItems<T>(string contentType)
where T : IContentItemFieldsSource, new() => await GetContentItems<T>(contentType, 0);
///<inheritdoc/>
public async Task<IEnumerable<T>> GetContentItems<T>(string contentType, int linkedItemsLevel)
where T : IContentItemFieldsSource, new()
{
var builder = new ContentItemQueryBuilder()
.ForContentType(contentType, config => config.WithLinkedItems(linkedItemsLevel));
return await ContentQueryExecutor.GetResult(builder, ContentQueryResultMapper.Map<T>);
}
///<inheritdoc/>
public async Task DeleteContentItem(int contentItemID, string languageName, int userID)
{
var contentItemManager = ContentItemManagerFactory.Create(userID);
await contentItemManager.Delete(contentItemID, languageName);
}
///<inheritdoc/>
public async Task DeleteContentItems(IEnumerable<int> contentItemIDs, string languageName, int userID)
{
if (!contentItemIDs.Any())
{
return;
}
var contentItemManager = ContentItemManagerFactory.Create(userID);
foreach (int contentItemID in contentItemIDs)
{
await contentItemManager.Delete(contentItemID, languageName);
}
}
}
Loading