Skip to content
10 changes: 10 additions & 0 deletions src/GitLabHealth-Model-Extension/GLHNote.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : #GLHNote }

{ #category : #'*GitLabHealth-Model-Extension' }
GLHNote >> name [

<FMProperty: #name type: #String>
<generated>
<FMComment: 'Basic name of the entity, not full reference.'>
^'[' , id asString , '] ' , body
]
7 changes: 7 additions & 0 deletions src/GitLabHealth-Model-Extension/GLHNotePosition.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : #GLHNotePosition }

{ #category : #'*GitLabHealth-Model-Extension' }
GLHNotePosition >> mooseNameOn: aStream [

aStream nextPutAll: file_path
]
12 changes: 12 additions & 0 deletions src/GitLabHealth-Model-Extension/GLHNoteSuggestion.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Extension { #name : #GLHNoteSuggestion }

{ #category : #'*GitLabHealth-Model-Extension' }
GLHNoteSuggestion >> mooseNameOn: aStream [

aStream nextPutAll: '[from:';
nextPutAll: from_line asString;
nextPutAll: ' to:';
nextPutAll: to_line asString;
nextPutAll: '] ';
nextPutAll: to_content.
]
12 changes: 8 additions & 4 deletions src/GitLabHealth-Model-Generator/GLHMetamodelGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -571,22 +571,26 @@ GLHMetamodelGenerator >> noteProperties [
GLHMetamodelGenerator >> noteRelations [

(note property: #mergeRequest) *- (mergeRequest property: #note).
(note property: #position) - (notePosition property: #note)
(note property: #position) <>- (notePosition property: #note)
]

{ #category : #notes }
GLHMetamodelGenerator >> noteSuggestionProperties [


noteSuggestion property: #id type: #Number .
noteSuggestion property: #from_line type: #Number.
noteSuggestion property: #to_line type: #Number.
noteSuggestion property: #from_content type: #String.
noteSuggestion property: #to_content type: #String.
noteSuggestion property: #to_content type: #String .
noteSuggestion property: #applied type: #Boolean.
noteSuggestion property: #appliable type: #Boolean
]

{ #category : #notes }
GLHMetamodelGenerator >> noteSuggestionRelations [

(noteSuggestion property: #note) *- (note property: #suggestions)


]

{ #category : #pipelines }
Expand Down
150 changes: 0 additions & 150 deletions src/GitLabHealth-Model-Importer-Tests/GitlabModelImporterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -386,156 +386,6 @@ GitlabModelImporterTest >> testImportProjects [
self assert: element repository isNil.
]

{ #category : #tests }
GitlabModelImporterTest >> testImportSuggestionsFromNote [

| body position glhNote result suggestion |
body := '
test
```suggestion:-0+5
content
```'.

position := GLHNotePosition new
start_line: 2;
end_line: 2.
glhNote := GLHNote new
body: body;
position: position.


result := importer importSuggestionsFromNote: glhNote.

self assert: result size equals: 1.

suggestion := result first.
self assert: suggestion from_line equals: 2.
self assert: suggestion to_line equals: 7.
self assert: suggestion to_content trim equals: 'content'
]

{ #category : #tests }
GitlabModelImporterTest >> testImportSuggestionsFromNoteWithDifferentStartAndEndLine [

| body position glhNote result suggestion |
body := '
test
```suggestion:-2+5
content
```'.

position := GLHNotePosition new
start_line: 2;
end_line: 5.
glhNote := GLHNote new
body: body;
position: position.


result := importer importSuggestionsFromNote: glhNote.

self assert: result size equals: 1.

suggestion := result first.
self assert: suggestion from_line equals: 3.
self assert: suggestion to_line equals: 10.
self assert: suggestion to_content trim equals: 'content'
]

{ #category : #tests }
GitlabModelImporterTest >> testImportSuggestionsFromNoteWithMultipleSuggestions [

| body position glhNote result suggestion suggestion2 |
body := '
test
```suggestion:-2+5
content
```

```suggestion:-0+0
```'.

position := GLHNotePosition new
start_line: 2;
end_line: 5.
glhNote := GLHNote new
body: body;
position: position.


result := importer importSuggestionsFromNote: glhNote.

self assert: result size equals: 2.

suggestion := result first.
self assert: suggestion from_line equals: 3.
self assert: suggestion to_line equals: 10.
self assert: suggestion to_content trim equals: 'content'.

suggestion2 := result at: 2.
self assert: suggestion2 from_line equals: 5.
self assert: suggestion2 to_line equals: 5.
self assert: suggestion2 to_content trim equals: ''
]

{ #category : #tests }
GitlabModelImporterTest >> testImportSuggestionsInfoFromString [

| string result suggestion |
string := '
some content
```suggestion:-0+2
test
```'.

result := importer importSuggestionsInfoFromString: string.

self assert: result size equals: 1.
suggestion := result first.
self assert: (suggestion at: #minus) equals: 0.
self assert: (suggestion at: #plus) equals: 2.
self assert: (suggestion at: #content) trim equals: 'test'
]

{ #category : #tests }
GitlabModelImporterTest >> testImportSuggestionsInfoFromStringWithMultipleSuggestion [

| string result suggestion suggestion2 |
string := '```suggestion:-0+2
test
```

```suggestion:-2+4

oui

```'.

result := importer importSuggestionsInfoFromString: string.

self assert: result size equals: 2.
suggestion := result first.
self assert: (suggestion at: #minus) equals: 0.
self assert: (suggestion at: #plus) equals: 2.
self assert: (suggestion at: #content) trim equals: 'test'.

suggestion2 := result at: 2.
self assert: (suggestion2 at: #minus) equals: 2.
self assert: (suggestion2 at: #plus) equals: 4.
self assert: (suggestion2 at: #content) trim equals: 'oui'
]

{ #category : #tests }
GitlabModelImporterTest >> testImportSuggestionsInfoFromStringWithNoSuggestions [

| string result |
string := 'a normal comment'.

result := importer importSuggestionsInfoFromString: string.

self assert: result size equals: 0.
]

{ #category : #'tests - tags' }
GitlabModelImporterTest >> testImportTagsForProject [

Expand Down
103 changes: 34 additions & 69 deletions src/GitLabHealth-Model-Importer/GitlabModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,24 @@ GitlabModelImporter >> configureReaderForNote: reader [
super configureReaderForNote: reader.

reader for: GLHNote do: [ :mapping |

mapping
mapProperty: #author
getter: [ ]
setter: [ :note :rawUser |
note cacheAt: #userID put: (rawUser at: #id) ].
mapProperty: #author
getter: [ ]
setter: [ :note :rawUser |
note cacheAt: #userID put: (rawUser at: #id) ].

(mapping mapInstVar: #created_at) valueSchema: DateAndTime.
(mapping mapInstVar: #updated_at) valueSchema: DateAndTime.

(mapping mapInstVar: #position) valueSchema: GLHNotePosition ]
(mapping mapInstVar: #position) valueSchema: GLHNotePosition.

mapping
mapProperty: #suggestions
getter: [ ]
setter: [ :note :rawSuggestions |
| stringSuggestions |
stringSuggestions := NeoJSONWriter toString: rawSuggestions.
note cacheAt: #stringSuggestions put: stringSuggestions ] ]
]

{ #category : #'private - configure reader' }
Expand Down Expand Up @@ -425,6 +432,13 @@ GitlabModelImporter >> configureReaderForNotePosition: reader [
notePosition end_line: endLine ] ] ]
]

{ #category : #'private - configure reader' }
GitlabModelImporter >> configureReaderForNoteSuggestion: reader [
super configureReaderForNoteSuggestion: reader.


]

{ #category : #'private - configure reader' }
GitlabModelImporter >> configureReaderForPipeline: reader [

Expand Down Expand Up @@ -1491,7 +1505,9 @@ GitlabModelImporter >> importNotesOfMergeRequest: mergeRequest [
ifPresent: [ :id | note author: (self importUser: id) ].
note name: note id asString.

note suggestions: (self importSuggestionsFromNote: note) ].
note cacheAt: #stringSuggestions ifPresent: [ :stringSuggestions |
note suggestions:
(self parseNotesSuggestionResult: stringSuggestions) ] ].

^ notes
]
Expand Down Expand Up @@ -1697,66 +1713,6 @@ GitlabModelImporter >> importSZZFromCommit: aCommit [
^ szzCommits
]

{ #category : #'import - notes' }
GitlabModelImporter >> importSuggestionsFromNote: glhNote [

| suggestions suggestion fromLine toLine suggestionsInfo |
glhNote position ifNil: [ ^ { } ].
suggestions := MooseGroup new.


suggestionsInfo := self importSuggestionsInfoFromString: glhNote body.

suggestions := suggestionsInfo collect: [ :suggestionInfo |
suggestion := GLHNoteSuggestion new.
fromLine := glhNote position end_line
- (suggestionInfo at: #minus).
toLine := glhNote position end_line
+ (suggestionInfo at: #plus).
suggestion from_line: fromLine.
suggestion to_line: toLine.
suggestion to_content: (suggestionInfo at: #content).
suggestion ].

^ suggestions
]

{ #category : #'import - notes' }
GitlabModelImporter >> importSuggestionsInfoFromString: string [

| suggestionsInfo regex result regex2 suggestionInfo |
suggestionsInfo := OrderedCollection new.
regex := '```suggestion' asRegex.
result := regex matchesIn: string.

result isEmpty ifTrue: [ ^ suggestionsInfo ].

result size > 1 ifTrue: [
| start end firstPart secondPart |
start := string findString: '```suggestion'.
end := (string findString: '```' startingAt: start + 2) + 2.

firstPart := string copyFrom: 1 to: end.
secondPart := string copyFrom: end to: string size.

suggestionsInfo addAll:
(self importSuggestionsInfoFromString: firstPart).
suggestionsInfo addAll:
(self importSuggestionsInfoFromString: secondPart).
^ suggestionsInfo ].

regex2 := '```suggestion\:-(\d+)\+(\d+)(.*)```' asRegex.
regex2 search: string.

suggestionInfo := {
(#minus -> (regex2 subexpression: 2) asNumber).
(#plus -> (regex2 subexpression: 3) asNumber).
(#content -> (regex2 subexpression: 4)) }
asDictionary.

^ { suggestionInfo }
]

{ #category : #'import - tags' }
GitlabModelImporter >> importTagsForProject: aProject [
|results tags |
Expand Down Expand Up @@ -2066,7 +2022,6 @@ GitlabModelImporter >> parseNotesResult: results [

| reader |
"Créer un lecteur JSON"

reader := generalReader on: results readStream.

"Corriger la conversion des dates"
Expand All @@ -2078,6 +2033,16 @@ GitlabModelImporter >> parseNotesResult: results [
^ reader nextAs: #ArrayOfNote
]

{ #category : #'private - parsing' }
GitlabModelImporter >> parseNotesSuggestionResult: results [

| reader |
"Créer un lecteur JSON"
reader := generalReader on: results readStream.

^ reader nextAs: #ArrayOfNoteSuggestion
]

{ #category : #'private - parsing' }
GitlabModelImporter >> parsePipelineResult: result [

Expand Down
2 changes: 1 addition & 1 deletion src/GitLabHealth-Model/GLHIssue.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ an Issues help collaboration within a team to plan, track, and deliver work
| `description` | `String` | nil | |
| `due_date` | `Object` | nil | |
| `id` | `Number` | nil | |
| `name` | `String` | nil | |
| `name` | `String` | nil | Basic name of the entity, not full reference.|
| `name` | `String` | nil | |
| `state` | `String` | nil | |
| `updated_at` | `Object` | nil | |

Expand Down
2 changes: 1 addition & 1 deletion src/GitLabHealth-Model/GLHJob.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ A CI Job
| `allow_failure` | `Boolean` | nil | |
| `duration` | `Object` | nil | |
| `id` | `Number` | nil | |
| `name` | `String` | nil | Basic name of the entity, not full reference.|
| `name` | `String` | nil | |
| `name` | `String` | nil | Basic name of the entity, not full reference.|
| `ref` | `String` | nil | |
| `web_url` | `String` | nil | |

Expand Down
Loading
Loading