-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added XRay project * Added client * Added section service * Added attachment and testcases services * Some fixes * Added tests * Added config * Fixed project * Fixed project * Added readme --------- Co-authored-by: Dmitry.Gridnev <[email protected]>
- Loading branch information
Showing
34 changed files
with
2,121 additions
and
1 deletion.
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
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
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
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,25 @@ | ||
using Microsoft.Extensions.Logging; | ||
using XRayExporter.Services; | ||
|
||
namespace XRayExporter; | ||
|
||
public class App | ||
{ | ||
private readonly ILogger<App> _logger; | ||
private readonly IExportService _exportService; | ||
|
||
public App(ILogger<App> logger, IExportService exportService) | ||
{ | ||
_logger = logger; | ||
_exportService = exportService; | ||
} | ||
|
||
public void Run(string[] args) | ||
{ | ||
_logger.LogInformation("Starting application"); | ||
|
||
_exportService.ExportProject().Wait(); | ||
|
||
_logger.LogInformation("Ending application"); | ||
} | ||
} |
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,161 @@ | ||
using System.Net.Http.Headers; | ||
using System.Text.Json; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using XRayExporter.Models; | ||
|
||
namespace XRayExporter.Client; | ||
|
||
public class Client : IClient | ||
{ | ||
private readonly ILogger<Client> _logger; | ||
private readonly HttpClient _httpClient; | ||
private readonly string _projectKey; | ||
|
||
public Client(ILogger<Client> logger, IConfiguration configuration) | ||
{ | ||
_logger = logger; | ||
|
||
var section = configuration.GetSection("xray"); | ||
var url = section["url"]; | ||
if (string.IsNullOrEmpty(url)) | ||
{ | ||
throw new ArgumentException("Url is not specified"); | ||
} | ||
|
||
var token = section["token"]; | ||
if (string.IsNullOrEmpty(token)) | ||
{ | ||
throw new ArgumentException("Token is not specified"); | ||
} | ||
|
||
var projectKey = section["projectKey"]; | ||
if (string.IsNullOrEmpty(projectKey)) | ||
{ | ||
throw new ArgumentException("Project key is not specified"); | ||
} | ||
|
||
_projectKey = projectKey; | ||
_httpClient = new HttpClient(); | ||
_httpClient.BaseAddress = new Uri(url); | ||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
} | ||
|
||
public async Task<JiraProject> GetProject() | ||
{ | ||
_logger.LogInformation("Getting project {ProjectKey}", _projectKey); | ||
|
||
var response = await _httpClient.GetAsync("rest/api/2/project"); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
_logger.LogError("Failed to get project. Status code: {StatusCode}. Response: {Response}", | ||
response.StatusCode, await response.Content.ReadAsStringAsync()); | ||
|
||
throw new Exception($"Failed to get project. Status code: {response.StatusCode}"); | ||
} | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
var projects = JsonSerializer.Deserialize<List<JiraProject>>(content); | ||
var project = projects!.FirstOrDefault(p => | ||
string.Equals(p.Key, _projectKey, StringComparison.InvariantCultureIgnoreCase)); | ||
|
||
if (project != null) return project; | ||
|
||
_logger.LogError("Project not found"); | ||
|
||
throw new Exception("Project not found"); | ||
} | ||
|
||
public async Task<List<XrayFolder>> GetFolders() | ||
{ | ||
_logger.LogInformation("Getting folders for project {ProjectKey}", _projectKey); | ||
|
||
var response = | ||
await _httpClient.GetAsync($"rest/raven/1.0/api/testrepository/{_projectKey.ToUpper()}/folders"); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
_logger.LogError("Failed to get folders. Status code: {StatusCode}. Response: {Response}", | ||
response.StatusCode, await response.Content.ReadAsStringAsync()); | ||
|
||
throw new Exception($"Failed to get folders. Status code: {response.StatusCode}"); | ||
} | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
var folders = JsonSerializer.Deserialize<XRayFolders>(content); | ||
|
||
return folders!.Folders; | ||
} | ||
|
||
public async Task<List<XRayTest>> GetTestFromFolder(int folderId) | ||
{ | ||
_logger.LogInformation("Getting test from folder {FolderId}", folderId); | ||
|
||
var response = | ||
await _httpClient.GetAsync( | ||
$"rest/raven/1.0/api/testrepository/{_projectKey.ToUpper()}/folders/{folderId}/tests"); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
_logger.LogError( | ||
"Failed to get test from folder {FolderId}. Status code: {StatusCode}. Response: {Response}", | ||
folderId, response.StatusCode, await response.Content.ReadAsStringAsync()); | ||
|
||
throw new Exception($"Failed to get test from folder {folderId}. Status code: {response.StatusCode}"); | ||
} | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
var tests = JsonSerializer.Deserialize<XRayTests>(content); | ||
|
||
return tests!.Tests; | ||
} | ||
|
||
public async Task<XRayTestFull> GetTest(string testKey) | ||
{ | ||
_logger.LogInformation("Getting test {TestKey}", testKey); | ||
|
||
var response = | ||
await _httpClient.GetAsync( | ||
$"rest/raven/1.0/api/test?keys={testKey}"); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
_logger.LogError( | ||
"Failed to get test {TestKey}. Status code: {StatusCode}. Response: {Response}", | ||
testKey, response.StatusCode, await response.Content.ReadAsStringAsync()); | ||
|
||
throw new Exception($"Failed to get test {testKey}. Status code: {response.StatusCode}"); | ||
} | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
var tests = JsonSerializer.Deserialize<List<XRayTestFull>>(content); | ||
|
||
return tests!.First(); | ||
} | ||
|
||
public async Task<JiraItem> GetItem(string link) | ||
{ | ||
_logger.LogInformation("Getting item {Link}", link); | ||
|
||
var response = | ||
await _httpClient.GetAsync(link.Split(_httpClient.BaseAddress.ToString())[1]); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
_logger.LogError( | ||
"Failed to get item {Link}. Status code: {StatusCode}. Response: {Response}", | ||
link, response.StatusCode, await response.Content.ReadAsStringAsync()); | ||
|
||
throw new Exception($"Failed to get item {link}. Status code: {response.StatusCode}"); | ||
} | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
var item = JsonSerializer.Deserialize<JiraItem>(content); | ||
|
||
return item; | ||
} | ||
|
||
public async Task<byte[]> DownloadAttachment(string link) | ||
{ | ||
_logger.LogInformation("Downloading attachment {Link}", link); | ||
|
||
return | ||
await _httpClient.GetByteArrayAsync(link.Split(_httpClient.BaseAddress.ToString())[1]); | ||
} | ||
} |
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,13 @@ | ||
using XRayExporter.Models; | ||
|
||
namespace XRayExporter.Client; | ||
|
||
public interface IClient | ||
{ | ||
Task<JiraProject> GetProject(); | ||
Task<List<XrayFolder>> GetFolders(); | ||
Task<List<XRayTest>> GetTestFromFolder(int folderId); | ||
Task<XRayTestFull> GetTest(string testKey); | ||
Task<JiraItem> GetItem(string link); | ||
Task<byte[]> DownloadAttachment(string link); | ||
} |
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,9 @@ | ||
namespace XRayExporter.Models; | ||
|
||
public static class Constants | ||
{ | ||
public const string XrayReporter = "Xray Reporter"; | ||
public const string XrayType = "Xray Type"; | ||
public const string XrayStatus = "Xray Status"; | ||
public const string XrayArchived = "Xray Archived"; | ||
} |
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,36 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace XRayExporter.Models; | ||
|
||
public class JiraItem | ||
{ | ||
[JsonPropertyName("fields")] | ||
public Fields Fields { get; set; } | ||
} | ||
|
||
public class Fields | ||
{ | ||
[JsonPropertyName("description")] | ||
public string Description { get; set; } | ||
|
||
[JsonPropertyName("attachment")] | ||
public List<Attachment> Attachments { get; set; } | ||
|
||
[JsonPropertyName("summary")] | ||
public string Summary { get; set; } | ||
|
||
[JsonPropertyName("labels")] | ||
public List<string> Labels { get; set; } | ||
|
||
[JsonPropertyName("issuelinks")] | ||
public List<JiraLink> IssueLinks { get; set; } | ||
} | ||
|
||
public class Attachment | ||
{ | ||
[JsonPropertyName("filename")] | ||
public string FileName { get; set; } | ||
|
||
[JsonPropertyName("content")] | ||
public string Content { 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,34 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace XRayExporter.Models; | ||
|
||
public class JiraLink | ||
{ | ||
[JsonPropertyName("type")] | ||
public Type Type { get; set; } | ||
|
||
[JsonPropertyName("inwardIssue")] | ||
public Issue? InwardIssue { get; set; } | ||
|
||
[JsonPropertyName("outwardIssue")] | ||
public Issue? OutwardIssue { get; set; } | ||
} | ||
|
||
public class Type | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("inward")] | ||
public string Inward { get; set; } | ||
} | ||
|
||
public class Issue | ||
{ | ||
[JsonPropertyName("key")] | ||
public string Key { get; set; } | ||
|
||
[JsonPropertyName("self")] | ||
public string Self { get; set; } | ||
} | ||
|
Oops, something went wrong.