Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordered pipelines to display result of last one #4

Merged
merged 8 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/GitHubHealth-Model-Importer-Tests/GHModelImporterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"
A GHModelImporterTest is a test class for testing the behavior of GHModelImporter
"
Class {
#name : #GHModelImporterTest,
#superclass : #TestCase,
#instVars : [
'importer'
],
#category : #'GitHubHealth-Model-Importer-Tests'
}

{ #category : #running }
GHModelImporterTest >> setUp [
super setUp.

importer := GHModelImporter new
]

{ #category : #test }
GHModelImporterTest >> testParsePipelinesResult [

| project |

project := importer parsePipelinesResult: '{
"total_count": 1,
"workflow_runs": [
{
"id": 7482814798,
"conclusion": "success",
"run_started_at": "2024-01-11T00:00:00"
}]}'.

self assert: project workflow_runs size equals: 1.

self assert: project workflow_runs anyOne status equals: 'success'.
self assert: project workflow_runs anyOne runDate equals: (DateAndTime year: 2024 month: 01 day: 11).

]
1 change: 1 addition & 0 deletions src/GitHubHealth-Model-Importer-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'GitHubHealth-Model-Importer-Tests' }
6 changes: 5 additions & 1 deletion src/GitHubHealth-Model-Importer/GHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ GHModelImporter >> parsePipelinesResult: pipelineOverview [
customMappting listOfElementSchema: GLHPipeline ].
reader
for: GLHPipeline
do: [ :mapping | mapping mapInstVar: #status to: #conclusion ].
do: [ :mapping |
mapping
mapInstVar: #status to: #conclusion ;
mapProperty: #run_started_at getter: [ :object | #ignore ] setter: [ :object : value | object runDate: (DateAndTime fromString: value) ]
].
^ reader nextAs: GHAPIPipelineOverview
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ GLHMetamodelGenerator >> defineProperties [
project property: #creator_id type: #Number.

"Pipelines properties"
pipeline property: #status type: #String.
(pipeline property: #status type: #String) comment: '#success or #failure'.
(pipeline property: #runDate type: #Object) comment: 'Date this pipeline was run'.

self userProperties.
self branchProperties.
self fileProperties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,46 @@ GLHGroupVisualization >> createLegend [
{ #category : #running }
GLHGroupVisualization >> createShapeFor: project [

| box |
| box inspect |

box := RSBox new
size: 5;
model: project;
yourself.
box color: (project pipelines
ifEmpty: [ self noPipelineColor ]
ifNotEmpty: [ :pipelines |
(pipelines last status = #success)
box color: (project lastPipeline
ifNil: [ self noPipelineColor ]
ifNotNil: [ :lastPipeline |
(lastPipeline status = #success)
ifTrue: [ Color green ]
ifFalse: [ Color red ]
]).

inspect := RSInspectableInteraction new.
inspect inspectShapeBlock: [ :proj |
proj inspect.
"block must return a Window :-("
SystemWindow new
].
box @ inspect.

box @ (RSPopup text: [ :proj |
String streamContents: [ :st |
st << proj name ; cr ; << 'on: '.
BasicDatePrinter default printYMD: proj lastPipelineDate withLeadingSpace: false on: st.
st space.
BasicDatePrinter default printHMS: proj lastPipelineDate separatedBy: $: on: st ] ]).

^ box
]

{ #category : #running }
GLHGroupVisualization >> createShapes: aGLHGroup [

^(aGLHGroup allToScope: GLHGroup) collect: [ :group || lbl projects composite |
projects := group projects
projects := (group projects sorted: [:a :b | a lastPipelineDate > b lastPipelineDate])
collect: [ :project | self createShapeFor: project ]
as: RSGroup.

projects @ (RSPopup text: #name).
RSGridLayout on: projects.
lbl := RSLabel new
text: group name;
Expand Down
31 changes: 31 additions & 0 deletions src/GitLabHealth-Model-Visualization/GLHProject.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Extension { #name : #GLHProject }

{ #category : #'*GitLabHealth-Model-Visualization' }
GLHProject >> lastPipeline [

^self
attributeAt: #lastPipeline
ifAbsentPut: [ pipelines
ifEmpty: [ nil ]
ifNotEmpty: [
(pipelines asOrderedCollection sort: [ :a :b | a runDate > b runDate])
first
]
]
]

{ #category : #'*GitLabHealth-Model-Visualization' }
GLHProject >> lastPipelineDate [

^self
attributeAt: #lastPipelineDate
ifAbsentPut: [
self lastPipeline
ifNil: [ DateAndTime now ]
ifNotNil: [ :lastPipeline |
lastPipeline runDate
ifNil: [ DateAndTime now ]
ifNotNil: [ :date | date ]
]
]
]
17 changes: 17 additions & 0 deletions src/GitLabHealth-Model/GLHPipeline.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Class {
#superclass : #GLHEntity,
#instVars : [
'#status => FMProperty',
'#runDate => FMProperty',
'#project => FMOne type: #GLHProject opposite: #pipelines'
],
#category : #'GitLabHealth-Model-Entities'
Expand Down Expand Up @@ -43,11 +44,27 @@ GLHPipeline >> projectGroup [
^ MooseSpecializedGroup with: self project
]

{ #category : #accessing }
GLHPipeline >> runDate [

<FMProperty: #runDate type: #Object>
<generated>
<FMComment: 'Date this pipeline was run'>
^ runDate
]

{ #category : #accessing }
GLHPipeline >> runDate: anObject [
<generated>
runDate := anObject
]

{ #category : #accessing }
GLHPipeline >> status [

<FMProperty: #status type: #String>
<generated>
<FMComment: '#success or #failure'>
^ status
]

Expand Down