-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b02cd0f
commit 1e8db5f
Showing
15 changed files
with
654 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Bellatrix.Plugins.Jira.Zephyr/Bellatrix.Plugins.Jira.Zephyr.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="RestSharp" Version="110.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Bellatrix.Core\Bellatrix.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// <copyright file="ZephyrPlugin.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
using System.Reflection; | ||
using Bellatrix.Plugins.Jira.Zephyr.Attributes; | ||
using Bellatrix.Plugins.Jira.Zephyr.Data; | ||
using Bellatrix.Plugins.Jira.Zephyr.Eventargs; | ||
using Bellatrix.Plugins.Jira.Zephyr.Services; | ||
using Plugins.Jira.Zephyr.Services; | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr; | ||
|
||
public class ZephyrPlugin : Plugin | ||
{ | ||
internal static ZephyrSettings Settings => ConfigurationService.GetSection<ZephyrSettings>(); | ||
|
||
internal static ZephyrLocalData Data = new ZephyrLocalData(); | ||
|
||
private readonly ZephyrPluginProvider _zephyrPluginProvider = new ZephyrPluginProvider(); | ||
private static bool IsEnabled => Settings.IsEnabled; | ||
|
||
protected override void PostTestsArrange(object sender, PluginEventArgs e) | ||
{ | ||
if (IsEnabled) | ||
{ | ||
var testCycleName = $"{DateTimeUtilities.GetUtcNow()} {Settings.TestCycleName}"; | ||
|
||
var testCycle = new ZephyrTestCycle(Settings.DefaultProjectKey, testCycleName, "In Progress"); | ||
Check warning on line 39 in src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPlugin.cs GitHub Actions / build
|
||
testCycle.PlannedStartDate = DateTimeUtilities.GetUtcNow(); | ||
Data.TestCycle = testCycle; | ||
|
||
Data.TestCycleResponse = ZephyrApiService.CreateTestCycle(Data); | ||
|
||
e.Container.RegisterInstance(Data); | ||
|
||
_zephyrPluginProvider.ZephyrCycleCreated(e, Data.TestCycle); | ||
} | ||
|
||
base.PostTestsArrange(sender, e); | ||
} | ||
|
||
protected override void PostTestCleanup(object sender, PluginEventArgs e) | ||
{ | ||
if (IsEnabled) | ||
{ | ||
var data = e.Container.Resolve<ZephyrLocalData>(); | ||
var testCase = new ZephyrTestCase(GetProjectId(e.TestMethodMemberInfo), data.TestCycleResponse.key, GetExecutionId(e.TestMethodMemberInfo), GetTestStatus(e.TestOutcome)); | ||
|
||
if (string.IsNullOrEmpty(testCase.TestCaseId) || string.IsNullOrEmpty(testCase.Status) || string.IsNullOrEmpty(testCase.ProjectId)) | ||
{ | ||
_zephyrPluginProvider.ZephyrTestCaseExecutionFailed(e, testCase); | ||
} | ||
else | ||
{ | ||
var response = ZephyrApiService.ExecuteTestCase(testCase); | ||
|
||
if (!response.IsSuccessful) | ||
_zephyrPluginProvider.ZephyrTestCaseExecutionFailed(e, testCase); | ||
else | ||
_zephyrPluginProvider.ZephyrTestCaseExecuted(e, testCase); | ||
} | ||
} | ||
|
||
base.PostTestCleanup(sender, e); | ||
} | ||
|
||
protected override void PostTestsCleanup(object sender, PluginEventArgs e) | ||
{ | ||
if (IsEnabled) | ||
{ | ||
var data = e.Container.Resolve<ZephyrLocalData>(); | ||
|
||
data.TestCycle.PlannedEndDate = DateTimeUtilities.GetUtcNow(); | ||
var response = ZephyrApiService.MarkTestCycleDone(data); | ||
|
||
if (!response.IsSuccessful) | ||
{ | ||
_zephyrPluginProvider.ZephyrCycleStatusUpdateFailed(e, data.TestCycle); | ||
} | ||
} | ||
|
||
base.PostTestsCleanup(sender, e); | ||
} | ||
|
||
internal class ZephyrLocalData | ||
{ | ||
internal ZephyrTestCycleResponse TestCycleResponse { get; set; } | ||
internal ZephyrTestCycle TestCycle { get; set; } | ||
} | ||
|
||
private string GetExecutionId(MemberInfo memberInfo) | ||
{ | ||
var zephyrTestCaseAttribute = memberInfo.GetCustomAttribute<ZephyrTestCaseAttribute>(); | ||
return zephyrTestCaseAttribute != null ? zephyrTestCaseAttribute.Id : string.Empty; | ||
} | ||
|
||
private string GetProjectId(MemberInfo memberInfo) | ||
{ | ||
var zephyrProjectAttribute = memberInfo.DeclaringType.GetCustomAttribute<ZephyrProjectAttribute>(); | ||
Check warning on line 110 in src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPlugin.cs GitHub Actions / build
|
||
if (zephyrProjectAttribute != null) | ||
{ | ||
return zephyrProjectAttribute.Id; | ||
} | ||
else | ||
{ | ||
return Settings.DefaultProjectKey != null ? Settings.DefaultProjectKey : string.Empty; | ||
} | ||
} | ||
|
||
private string GetTestStatus(TestOutcome testOutcome) | ||
{ | ||
switch(testOutcome) | ||
{ | ||
case TestOutcome.Failed: | ||
case TestOutcome.Aborted: | ||
case TestOutcome.Error: | ||
return "Fail"; | ||
case TestOutcome.Passed: | ||
return "Pass"; | ||
default: | ||
return "In Progress"; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPluginConfigure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// <copyright file="ZephyrPluginConfigure.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr; | ||
|
||
public static class ZephyrPluginConfigure | ||
{ | ||
public static void Add() | ||
{ | ||
ServicesCollection.Current.RegisterType<Plugin, ZephyrPlugin>(Guid.NewGuid().ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Bellatrix.Plugins.Jira.Zephyr; | ||
|
||
public class ZephyrSettings | ||
{ | ||
public bool IsEnabled { get; set; } | ||
public string? ApiUrl { get; set; } | ||
public string? Token { get; set; } | ||
public string? DefaultProjectKey { get; set; } | ||
public string TestCycleName { get; set; } = "BELLATRIX TEST RUN"; | ||
public string? CycleFinalStatus { get; set; } = "Done"; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Bellatrix.Plugins.Jira.Zephyr/attributes/ZephyrProjectAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// <copyright file="ZephyrProjectAttribute.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)] | ||
public sealed class ZephyrProjectAttribute : Attribute | ||
{ | ||
public string Id { get; } | ||
|
||
public ZephyrProjectAttribute(string id) | ||
{ | ||
Id = id; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Bellatrix.Plugins.Jira.Zephyr/attributes/ZephyrTestCaseAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// <copyright file="ZephyrTestCaseAttribute.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] | ||
public sealed class ZephyrTestCaseAttribute : Attribute | ||
{ | ||
public string Id { get; } | ||
|
||
public ZephyrTestCaseAttribute(string id) | ||
{ | ||
Id = id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// <copyright file="ZephyrTestCase.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr.Data; | ||
|
||
public class ZephyrTestCase | ||
{ | ||
public ZephyrTestCase(string projectId, string testCycleId, string testCaseId, string status) | ||
{ | ||
this.ProjectId = projectId; | ||
this.TestCycleId = testCycleId; | ||
this.TestCaseId = testCaseId; | ||
this.Status = status; | ||
} | ||
|
||
public string ProjectId { get; set; } | ||
public string TestCycleId { get; set; } | ||
public string TestCaseId { get; set; } | ||
public string Status { get; set; } | ||
public double Duration { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// <copyright file="ZephyrTestCycle.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr.Data; | ||
|
||
public class ZephyrTestCycle | ||
{ | ||
public ZephyrTestCycle(string projectKey, string name, string statusName) | ||
{ | ||
this.ProjectKey = projectKey; | ||
this.Name = name; | ||
this.StatusName = statusName; | ||
} | ||
|
||
public string ProjectKey { get; set; } | ||
public string Name { get; set; } | ||
public string StatusName { get; set; } | ||
public string? PlannedStartDate { get; set; } | ||
public string? PlannedEndDate { get; set; } | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Bellatrix.Plugins.Jira.Zephyr/data/ZephyrTestCycleResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// <copyright file="ZephyrTestCycleResponse.cs" company="Automate The Planet Ltd."> | ||
// Copyright 2024 Automate The Planet Ltd. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// <author>Miriam Kyoseva</author> | ||
// <site>https://bellatrix.solutions/</site> | ||
|
||
namespace Bellatrix.Plugins.Jira.Zephyr.Data; | ||
public struct ZephyrTestCycleResponse | ||
{ | ||
public string id; | ||
public string key; | ||
} |
Oops, something went wrong.