public async Task ValidateStatus() { int workflowId = default; string workflowStatus = default; try { workflowId = await _githubApiService.GetWorkflowId(); _githubActionService.LogDebug($"Workflow Id: {workflowId}"); } catch (Exception) { _githubActionService.LogFatal($"Unable to find workflow with the name {_settings.Workflow}"); } try { workflowStatus = await _githubApiService.GetWorkflowStatus(workflowId); _githubActionService.LogDebug($"Workflow Status: {workflowStatus}"); } catch (Exception) { _githubActionService.LogFatal($"Unable to find last workflow run for {_settings.Workflow}"); } if (!string.Equals(workflowStatus, _settings.Status, StringComparison.InvariantCultureIgnoreCase)) { _githubActionService.LogFatal($"Latest workflow run returned a status of {workflowStatus} rather than expected {_settings.Status}"); } _githubActionService.LogDebug($"Latest workflow run returned a status of {workflowStatus}; expected {_settings.Status}"); }
public void CanLogDebug() { // test _githubActionService.LogDebug("My Test"); _githubActionService.LogDebug("this should be logged."); // assertions _writeLine.Verify(x => x(It.Is <string>(m => m == "::debug::My Test")), Times.Once); _writeLine.Verify(x => x(It.Is <string>(m => m == "::debug::this should be logged.")), Times.Once); }
public async Task <int> GetWorkflowId() { var response = await $"https://api.github.com/repos/{_settings.Project}/actions/workflows" .WithHeader("Authorization", $"token {_settings.Token}") .WithHeader("User-Agent", "Flurl") .GetJsonAsync <WorkflowResponse>(); _githubActionService.LogDebug($"Workflows Found: {response?.TotalCount}"); return(response.Workflows .First(w => string.Equals(w.Name, _settings.Workflow, StringComparison.InvariantCultureIgnoreCase)) .Id); }