diff --git a/src/GitLabHealth-Model-Extension/GLHNote.extension.st b/src/GitLabHealth-Model-Extension/GLHNote.extension.st new file mode 100644 index 00000000..85916bd6 --- /dev/null +++ b/src/GitLabHealth-Model-Extension/GLHNote.extension.st @@ -0,0 +1,10 @@ +Extension { #name : #GLHNote } + +{ #category : #'*GitLabHealth-Model-Extension' } +GLHNote >> name [ + + + + + ^'[' , id asString , '] ' , body +] diff --git a/src/GitLabHealth-Model-Extension/GLHNotePosition.extension.st b/src/GitLabHealth-Model-Extension/GLHNotePosition.extension.st new file mode 100644 index 00000000..1ff45451 --- /dev/null +++ b/src/GitLabHealth-Model-Extension/GLHNotePosition.extension.st @@ -0,0 +1,7 @@ +Extension { #name : #GLHNotePosition } + +{ #category : #'*GitLabHealth-Model-Extension' } +GLHNotePosition >> mooseNameOn: aStream [ + + aStream nextPutAll: file_path +] diff --git a/src/GitLabHealth-Model-Extension/GLHNoteSuggestion.extension.st b/src/GitLabHealth-Model-Extension/GLHNoteSuggestion.extension.st new file mode 100644 index 00000000..bdef403d --- /dev/null +++ b/src/GitLabHealth-Model-Extension/GLHNoteSuggestion.extension.st @@ -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. +] diff --git a/src/GitLabHealth-Model-Generator/GLHMetamodelGenerator.class.st b/src/GitLabHealth-Model-Generator/GLHMetamodelGenerator.class.st index 479ecc31..81d0290c 100644 --- a/src/GitLabHealth-Model-Generator/GLHMetamodelGenerator.class.st +++ b/src/GitLabHealth-Model-Generator/GLHMetamodelGenerator.class.st @@ -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 } diff --git a/src/GitLabHealth-Model-Importer-Tests/GitlabModelImporterTest.class.st b/src/GitLabHealth-Model-Importer-Tests/GitlabModelImporterTest.class.st index 3bd54796..b5229297 100644 --- a/src/GitLabHealth-Model-Importer-Tests/GitlabModelImporterTest.class.st +++ b/src/GitLabHealth-Model-Importer-Tests/GitlabModelImporterTest.class.st @@ -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 [ diff --git a/src/GitLabHealth-Model-Importer/GitlabModelImporter.class.st b/src/GitLabHealth-Model-Importer/GitlabModelImporter.class.st index cf78cb76..08c59238 100644 --- a/src/GitLabHealth-Model-Importer/GitlabModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GitlabModelImporter.class.st @@ -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' } @@ -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 [ @@ -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 ] @@ -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 | @@ -2066,7 +2022,6 @@ GitlabModelImporter >> parseNotesResult: results [ | reader | "Créer un lecteur JSON" - reader := generalReader on: results readStream. "Corriger la conversion des dates" @@ -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 [ diff --git a/src/GitLabHealth-Model/GLHIssue.class.st b/src/GitLabHealth-Model/GLHIssue.class.st index 80320c00..2d6fc7bb 100644 --- a/src/GitLabHealth-Model/GLHIssue.class.st +++ b/src/GitLabHealth-Model/GLHIssue.class.st @@ -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 | | diff --git a/src/GitLabHealth-Model/GLHJob.class.st b/src/GitLabHealth-Model/GLHJob.class.st index bed62ed5..b50f9f3d 100644 --- a/src/GitLabHealth-Model/GLHJob.class.st +++ b/src/GitLabHealth-Model/GLHJob.class.st @@ -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 | | diff --git a/src/GitLabHealth-Model/GLHNote.class.st b/src/GitLabHealth-Model/GLHNote.class.st index 89c1a2bf..8d3f3339 100644 --- a/src/GitLabHealth-Model/GLHNote.class.st +++ b/src/GitLabHealth-Model/GLHNote.class.st @@ -4,13 +4,17 @@ a note (a diff) proposed in a Merge Request; can be accepted, modified or delete ## Relations ====================== +### Children +| Relation | Origin | Opposite | Type | Comment | +|---| +| `position` | `GLHNote` | `note` | `GLHNotePosition` | | + ### Other | Relation | Origin | Opposite | Type | Comment | |---| | `mergeRequest` | `GLHNote` | `note` | `GLHMergeRequest` | | | `position` | `GLHNote` | `note` | `GLHNotePosition` | | | `position` | `GLHNote` | `note` | `GLHNotePosition` | | -| `position` | `GLHNote` | `note` | `GLHNotePosition` | | | `suggestions` | `GLHNote` | `note` | `GLHNoteSuggestion` | | @@ -223,6 +227,12 @@ GLHNote >> mergeRequest: anObject [ mergeRequest := anObject ] +{ #category : #printing } +GLHNote >> mooseNameOn: stream [ + + stream nextPutAll: '[', id asString, ']', body +] + { #category : #accessing } GLHNote >> noteable_id [ @@ -280,6 +290,13 @@ GLHNote >> position: anObject [ position := anObject ] +{ #category : #navigation } +GLHNote >> positionGroup [ + + + ^ MooseSpecializedGroup with: self position +] + { #category : #accessing } GLHNote >> project_id [ diff --git a/src/GitLabHealth-Model/GLHNotePosition.class.st b/src/GitLabHealth-Model/GLHNotePosition.class.st index ee76ee38..9492fded 100644 --- a/src/GitLabHealth-Model/GLHNotePosition.class.st +++ b/src/GitLabHealth-Model/GLHNotePosition.class.st @@ -4,10 +4,14 @@ indicate the position of a note ## Relations ====================== -### Other +### Parents | Relation | Origin | Opposite | Type | Comment | |---| | `note` | `GLHNotePosition` | `position` | `GLHNote` | | + +### Other +| Relation | Origin | Opposite | Type | Comment | +|---| | `note` | `GLHNotePosition` | `position` | `GLHNote` | | | `note` | `GLHNotePosition` | `position` | `GLHNote` | | @@ -94,11 +98,20 @@ GLHNotePosition >> file_path: anObject [ file_path := anObject ] +{ #category : #printing } +GLHNotePosition >> mooseNameOn: stream + +mooseNameOn: aStream [ + + aStream nextPutAll: 'test' +] + { #category : #accessing } GLHNotePosition >> note [ "Relation named: #note type: #GLHNote opposite: #position" + ^ note ] @@ -110,6 +123,13 @@ GLHNotePosition >> note: anObject [ note := anObject ] +{ #category : #navigation } +GLHNotePosition >> noteGroup [ + + + ^ MooseSpecializedGroup with: self note +] + { #category : #accessing } GLHNotePosition >> original_file_path [ diff --git a/src/GitLabHealth-Model/GLHNoteSuggestion.class.st b/src/GitLabHealth-Model/GLHNoteSuggestion.class.st index 5f6edc58..0bbdf662 100644 --- a/src/GitLabHealth-Model/GLHNoteSuggestion.class.st +++ b/src/GitLabHealth-Model/GLHNoteSuggestion.class.st @@ -15,8 +15,11 @@ suggestion of code made in a note | Name | Type | Default value | Comment | |---| +| `appliable` | `Boolean` | nil | | +| `applied` | `Boolean` | nil | | | `from_content` | `String` | nil | | | `from_line` | `Number` | nil | | +| `id` | `Number` | nil | | | `name` | `String` | nil | Basic name of the entity, not full reference.| | `to_content` | `String` | nil | | | `to_line` | `Number` | nil | | @@ -28,10 +31,13 @@ Class { #traits : 'FamixTNamedEntity', #classTraits : 'FamixTNamedEntity classTrait', #instVars : [ + '#id => FMProperty', '#from_line => FMProperty', '#to_line => FMProperty', '#from_content => FMProperty', '#to_content => FMProperty', + '#applied => FMProperty', + '#appliable => FMProperty', '#note => FMOne type: #GLHNote opposite: #suggestions' ], #category : #'GitLabHealth-Model-Entities' @@ -46,6 +52,34 @@ GLHNoteSuggestion class >> annotation [ ^ self ] +{ #category : #accessing } +GLHNoteSuggestion >> appliable [ + + + + ^ appliable +] + +{ #category : #accessing } +GLHNoteSuggestion >> appliable: anObject [ + + appliable := anObject +] + +{ #category : #accessing } +GLHNoteSuggestion >> applied [ + + + + ^ applied +] + +{ #category : #accessing } +GLHNoteSuggestion >> applied: anObject [ + + applied := anObject +] + { #category : #accessing } GLHNoteSuggestion >> from_content [ @@ -74,6 +108,20 @@ GLHNoteSuggestion >> from_line: anObject [ from_line := anObject ] +{ #category : #accessing } +GLHNoteSuggestion >> id [ + + + + ^ id +] + +{ #category : #accessing } +GLHNoteSuggestion >> id: anObject [ + + id := anObject +] + { #category : #accessing } GLHNoteSuggestion >> note [ "Relation named: #note type: #GLHNote opposite: #suggestions" diff --git a/src/GitProjectHealth-Model-Importer/GitModelImporter.class.st b/src/GitProjectHealth-Model-Importer/GitModelImporter.class.st index e0e2bfaf..a11a03fd 100644 --- a/src/GitProjectHealth-Model-Importer/GitModelImporter.class.st +++ b/src/GitProjectHealth-Model-Importer/GitModelImporter.class.st @@ -332,6 +332,17 @@ GitModelImporter >> configureReaderForNotePosition: reader [ customMapping listOfElementSchema: GLHNotePosition ] ] +{ #category : #'private - configure reader' } +GitModelImporter >> configureReaderForNoteSuggestion: reader [ + + reader mapInstVarsFor: GLHNoteSuggestion. + + reader + for: #ArrayOfNoteSuggestion + customDo: [ :customMapping | + customMapping listOfElementSchema: GLHNoteSuggestion ] +] + { #category : #'private - configure reader' } GitModelImporter >> configureReaderForPipeline: reader [