From 156755bc9657ad8d07a75ee8c80cc2e7fa09e20f Mon Sep 17 00:00:00 2001 From: davidvader Date: Tue, 7 Jan 2025 10:56:44 -0600 Subject: [PATCH] fix: address feedback --- src/elm/Pages/Org_/Repo_/Build_/Pipeline.elm | 5 +-- src/elm/Utils/Warnings.elm | 32 ++++++++++++++++++++ src/elm/Vela.elm | 23 ++++---------- 3 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 src/elm/Utils/Warnings.elm diff --git a/src/elm/Pages/Org_/Repo_/Build_/Pipeline.elm b/src/elm/Pages/Org_/Repo_/Build_/Pipeline.elm index b070bcb6e..d6358ceff 100644 --- a/src/elm/Pages/Org_/Repo_/Build_/Pipeline.elm +++ b/src/elm/Pages/Org_/Repo_/Build_/Pipeline.elm @@ -29,6 +29,7 @@ import Utils.Ansi import Utils.Errors as Errors import Utils.Focus as Focus import Utils.Helpers as Util +import Utils.Warnings as Warnings import Vela import View exposing (View) @@ -783,8 +784,8 @@ viewLine expand shiftKeyDown lineNumber line warnings focus = viewWarningAsLogLine : Model -> Shared.Model -> String -> Html Msg viewWarningAsLogLine model shared warning = let - ( maybeLineNumber, content ) = - Vela.lineNumberWarningfromWarningString warning + { maybeLineNumber, content } = + Warnings.fromString warning in tr [ class "warning" ] [ td [ class "annotation", class "-show" ] diff --git a/src/elm/Utils/Warnings.elm b/src/elm/Utils/Warnings.elm new file mode 100644 index 000000000..8a23e366b --- /dev/null +++ b/src/elm/Utils/Warnings.elm @@ -0,0 +1,32 @@ +{-- +SPDX-License-Identifier: Apache-2.0 +--} + + +module Utils.Warnings exposing (Warning, fromString) + +{-| Warning : an object that represents a point of focus. +-} + + +type alias Warning = + { maybeLineNumber : Maybe Int + , content : String + } + + +{-| fromString : parses a warning string into a line number and a message. +-} +fromString : String -> Warning +fromString warning = + case String.split ":" warning of + prefix :: content -> + case String.toInt prefix of + Just lineNumber -> + { maybeLineNumber = Just lineNumber, content = String.concat content } + + Nothing -> + { maybeLineNumber = Nothing, content = warning } + + _ -> + { maybeLineNumber = Nothing, content = warning } diff --git a/src/elm/Vela.elm b/src/elm/Vela.elm index 83c28e794..32deb92eb 100644 --- a/src/elm/Vela.elm +++ b/src/elm/Vela.elm @@ -104,7 +104,6 @@ module Vela exposing , encodeSettingsPayload , encodeUpdateUser , getAllowEventField - , lineNumberWarningfromWarningString , platformSettingsFieldUpdateToResponseConfig , repoFieldUpdateToResponseConfig , secretToKey @@ -120,6 +119,7 @@ import Json.Decode.Extra exposing (dict2) import Json.Decode.Pipeline exposing (hardcoded, optional, required) import Json.Encode import RemoteData exposing (WebData) +import Utils.Warnings as Warnings @@ -1149,21 +1149,6 @@ type alias Templates = Dict String Template -lineNumberWarningfromWarningString : String -> ( Maybe Int, String ) -lineNumberWarningfromWarningString warning = - case String.split ":" warning of - prefix :: content -> - case String.toInt prefix of - Just lineNumber -> - ( Just lineNumber, String.join "" content ) - - Nothing -> - ( Nothing, warning ) - - _ -> - ( Nothing, warning ) - - decodePipelineConfig : Json.Decode.Decoder PipelineConfig decodePipelineConfig = Json.Decode.succeed @@ -1196,7 +1181,11 @@ decodeAndCollapsePipelineWarnings warnings = Json.Decode.succeed (List.foldl (\warning dict -> - case lineNumberWarningfromWarningString warning of + let + { maybeLineNumber, content } = + Warnings.fromString warning + in + case ( maybeLineNumber, content ) of ( Just line, w ) -> Dict.update line (\maybeWarnings ->