Skip to content

Commit

Permalink
Merge pull request #85 from hpi-swa-teaching/issue/76-smalltalk-ci-logs
Browse files Browse the repository at this point in the history
Simplify SmalltalkCI Log
  • Loading branch information
kolioOtSofia authored Jun 13, 2021
2 parents 402eb29 + 5f3174e commit 9f61e89
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
constants
ansiCodeDictonary

^ Dictionary newFrom: {
'[31m' -> (Dictionary newFrom: { 'prefix' -> 'FAIL'. 'color' -> (ATDDTestingEntity colorDictionary at: #error) }).
'[32m' -> (Dictionary newFrom: { 'prefix' -> 'PASS'. 'color' -> (ATDDTestingEntity colorDictionary at: #successful) })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
updating
isSmalltalkCILog: aString

^ aString includesSubstring: 'Run hpi-swa/setup-smalltalkCI'
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
updating
parseAnsiCodeOf: aString

| parsedLine prefixColorDictonary match |

"Set default values"
parsedLine := aString.
match := (parsedLine allRegexMatches: '#\w* \(\d*ms\)') at: 1 ifAbsent: [ nil ].

self class ansiCodeDictonary keysAndValuesDo: [ :aKey :aDictionary |
match ifNotNil: [
(parsedLine includesSubstring: aKey) ifTrue: [ prefixColorDictonary := aDictionary ]
]
].

"Remove all Ansi Codes"
parsedLine := parsedLine copyWithRegex: '\[\d+m' matchesReplacedWith: ''.
parsedLine := match ifNil: [ parsedLine ].

prefixColorDictonary ifNotNil: [
parsedLine :=
' [' asText,
((prefixColorDictonary at: 'prefix') asText addAttribute: (TextColor color: (prefixColorDictonary at: 'color'))),
'] ' asText,
parsedLine asText
]
ifNil: [ parsedLine := parsedLine asText ].

^ parsedLine
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
updating
parseSmalltalkCILog: aString

| log shouldIncludeLine parsedLine |

log := Text new.
shouldIncludeLine := false.
parsedLine := ''.

aString linesDo: [ :line |
"start of logging"
(line includesSubstring: 'Running suite "Squeak')
ifTrue: [ shouldIncludeLine := true ].

"Remove timestamp"
(line isEmpty)
ifTrue: [ parsedLine := line ]
ifFalse: [ parsedLine := line allButFirst: 28 ].

"Parse Ansi Codes + Add new line (CR)"
parsedLine := self parseAnsiCodeOf: parsedLine.
parsedLine := parsedLine, Character cr asText.

(shouldIncludeLine) ifTrue: [log append: parsedLine].

"end of logging"
(line matchesRegex: '.*Executed \d* Tests with \d* Failures and \d* Errors.*')
ifTrue: [shouldIncludeLine := false].
].

^ log
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ updateJobLogForId: aNumber
[ response := self data client getLogsForRepository: self data repository logId: aNumber ]
on: GHAAccessDeniedError
do: [ :error | response := 'Acces denied. Logs are only available when providing a token' ].

(self isSmalltalkCILog: response)
ifTrue: [response := self parseSmalltalkCILog: response].

self
log: response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"class" : {
"ansiCodeDictonary" : "BF 6/11/2021 20:40",
"isAbstract" : "ls 7/25/2019 08:44",
"parser" : "sw 5/21/2021 20:55",
"targetName" : "sw 5/21/2021 20:55" },
Expand All @@ -8,8 +9,11 @@
"colorForSelectedHistory" : "ClassTest 5/29/2021 19:12",
"history" : "ClassTest 5/29/2021 19:12",
"historyInfoForSelectedHistory" : "ng 5/23/2021 09:15",
"isSmalltalkCILog:" : "BF 6/11/2021 21:10",
"jobNames" : "ng 5/26/2021 14:18",
"jobNames:" : "ng 5/26/2021 14:18",
"parseAnsiCodeOf:" : "BF 6/11/2021 21:15",
"parseSmalltalkCILog:" : "BF 6/11/2021 19:48",
"selectedJob:" : "ng 5/26/2021 14:54",
"updateJobLogForId:" : "BF 5/28/2021 21:21",
"updateJobLogForId:" : "BF 6/11/2021 13:43",
"updateJobs" : "ClassTest 5/29/2021 19:12" } }

0 comments on commit 9f61e89

Please sign in to comment.