Skip to content

Commit

Permalink
Add Needs type for Job.needs, with job, pipeline, artifacts & optiona…
Browse files Browse the repository at this point in the history
…l fields
  • Loading branch information
draoncc committed Oct 13, 2022
1 parent 9ebca9b commit 50f8691
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
4 changes: 3 additions & 1 deletion GitLab/Job/Type.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ let When = ../When/Type.dhall

let Parallel = ../Parallel/Type.dhall

let Needs = ../Needs/Type.dhall

in { stage : Optional Text
, image : Optional Image
, variables : Prelude.Map.Type Text Text
, rules : Optional (List Rule)
, dependencies : Optional (List Text)
, needs : List Text
, needs : Optional (List Needs)
, allow_failure : Bool
, tags : Optional (List Text)
, before_script : Optional Script
Expand Down
2 changes: 1 addition & 1 deletion GitLab/Job/append.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let append
, variables = a.variables # b.variables
, rules = mergeOptionalList Rule.Type a.rules b.rules
, dependencies = mergeOptionalList Text a.dependencies b.dependencies
, needs = a.needs # b.needs
, needs = mergeOptionalList Needs.Type a.needs b.needs
, allow_failure = b.allow_failure
, tags = mergeOptionalList Text a.tags b.tags
, before_script = mergeOptionalList Text a.before_script b.before_script
Expand Down
4 changes: 3 additions & 1 deletion GitLab/Job/default.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ let When = ../When/Type.dhall

let Parallel = ../Parallel/Type.dhall

let Needs = ../Needs/Type.dhall

in { stage = None Text
, image = None Image
, variables = Prelude.Map.empty Text Text
, rules = None (List Rule)
, dependencies = None (List Text)
, needs = [] : List Text
, needs = None (List Needs)
, allow_failure = False
, tags = None (List Text)
, before_script = None Script
Expand Down
18 changes: 15 additions & 3 deletions GitLab/Job/toJSON.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ let When = ../When/package.dhall

let Parallel = ../Parallel/package.dhall

let Needs = ../Needs/package.dhall

let dropNones = ../utils/dropNones.dhall

let optionalList = ../utils/optionalList.dhall
Expand Down Expand Up @@ -77,9 +79,19 @@ in let Job/toJSON

in Some (stringsArrayJSON dependenciesList)
, needs =
if Prelude.List.null Text job.needs
then None JSON.Type
else Some (stringsArrayJSON job.needs)
let needsList = optionalList Needs.Type job.needs

in if Prelude.List.null Needs.Type needsList
then None JSON.Type
else Some
( JSON.array
( Prelude.List.map
Needs.Type
JSON.Type
Needs.toJson
needsList
)
)
, tags =
Optional/map
(List Text)
Expand Down
5 changes: 5 additions & 0 deletions GitLab/Needs/Type.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ job : Optional Text
, pipeline : Optional Text
, artifacts : Bool
, optional : Bool
}
2 changes: 2 additions & 0 deletions GitLab/Needs/default.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ job = None Text, pipeline = None Text, artifacts = True, optional = False }
: ./Type.dhall
1 change: 1 addition & 0 deletions GitLab/Needs/package.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Type = ./Type.dhall, default = ./default.dhall, toJSON = ./toJSON.dhall }
28 changes: 28 additions & 0 deletions GitLab/Needs/toJSON.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
let Prelude = ../Prelude.dhall

let Map = Prelude.Map

let JSON = Prelude.JSON

let Needs = ./Type.dhall

let dropNones = ../utils/dropNones.dhall

let Optional/map = Prelude.Optional.map

let Needs/toJSON
: Needs JSON.Type
= λ(needs : Needs)
let everything
: Map.Type Text (Optional JSON.Type)
= toMap
{ job = Optional/map Text JSON.Type JSON.string needs.pipeline
, pipeline =
Optional/map Text JSON.Type JSON.string needs.pipeline
, artifacts = Some (JSON.bool needs.artifacts)
, optional = Some (JSON.bool needs.optional)
}

in JSON.object (dropNones Text JSON.Type everything)

in Needs/toJSON

0 comments on commit 50f8691

Please sign in to comment.