Skip to content
Open
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
79 changes: 64 additions & 15 deletions src/GitLabHealth-Model-Generator/GLHMetamodelGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Class {
'deletion',
'lineOfCode',
'note',
'notePosition',
'noteSuggestion',
'entity',
'release',
'tag',
Expand Down Expand Up @@ -176,6 +178,13 @@ GLHMetamodelGenerator >> defineClasses [
comment:
'a note (a diff) proposed in a Merge Request; can be accepted, modified or deleted'.

notePosition := builder
newClassNamed: #NotePosition
comment: 'indicate the position of a note'.

noteSuggestion := builder
newClassNamed: #NoteSuggestion
comment: 'suggestion of code made in a note'.

tag := builder
newClassNamed: #Tag
Expand All @@ -187,16 +196,16 @@ GLHMetamodelGenerator >> defineClasses [
newClassNamed: #Release
comment:
'a Release is typically associated with a tag and provide additional metadata and assets that can be distributed to users'.

issue := builder
newClassNamed: #Issue
comment:
'an Issues help collaboration within a team to plan, track, and deliver work'.

milestone := builder
newClassNamed: #Milestone
comment:
'a Milestone is use to track progress on groups of issues or pull requests in a repository'.
newClassNamed: #Milestone
comment:
'a Milestone is use to track progress on groups of issues or pull requests in a repository'
]

{ #category : #definition }
Expand All @@ -214,11 +223,13 @@ GLHMetamodelGenerator >> defineHierarchy [
diff --|> #TNamedEntity.
job --|> #TNamedEntity.
note --|> #TNamedEntity.

notePosition --|> #TNamedEntity.
noteSuggestion --|> #TNamedEntity.

tRef --|> #TNamedEntity.
tRef <|-- commit .
tRef <|-- branch .
tRef <|-- tag .
tRef <|-- commit.
tRef <|-- branch.
tRef <|-- tag.

change --|> #TNamedEntity.
change <|-- addition.
Expand All @@ -227,7 +238,7 @@ GLHMetamodelGenerator >> defineHierarchy [
mergeRequest --|> #TNamedEntity.

issue --|> #TNamedEntity.
milestone --|> #TNamedEntity.
milestone --|> #TNamedEntity
]

{ #category : #definition }
Expand All @@ -248,12 +259,14 @@ GLHMetamodelGenerator >> defineProperties [
self mergeRequestProperties.
self diffRangeProperties.
self noteProperties.
self notePositionProperties.
self noteSuggestionProperties.
self tagProperties.
self releaseProperties.
self issueProperties.
self milestoneProperties.
self tRefProperties.

self tRefProperties
]

{ #category : #definition }
Expand Down Expand Up @@ -289,7 +302,10 @@ GLHMetamodelGenerator >> defineRelations [
self issueRelations.
self mergeRequestsRelations.
self noteRelations.
self milestoneRelations.
self notePositionRelations.
self noteSuggestionRelations.
self milestoneRelations.
self notePositionRelations
]

{ #category : #definition }
Expand Down Expand Up @@ -504,6 +520,23 @@ GLHMetamodelGenerator >> milestoneRelations [
(milestone property: #mergeRequest) <>-* (mergeRequest property: #milestone).
]

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

notePosition property: #file_path type: #String.
notePosition property: #original_file_path type: #String.
notePosition property: #start_line type: #Number.
notePosition property: #start_line_type type: #String.
notePosition property: #end_line type: #Number.
notePosition property: #end_line_type type: #String.
]

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

(notePosition property: #note) - (note property: #position)
]

{ #category : #notes }
GLHMetamodelGenerator >> noteProperties [
note property: #id type: #Number.
Expand Down Expand Up @@ -534,10 +567,26 @@ GLHMetamodelGenerator >> noteProperties [

]

{ #category : #'merge requests' }
{ #category : #notes }
GLHMetamodelGenerator >> noteRelations [

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

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

noteSuggestion property: #from_line type: #Number.
noteSuggestion property: #to_line type: #Number.
noteSuggestion property: #from_content type: #String.
noteSuggestion property: #to_content type: #String.
]

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

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

{ #category : #pipelines }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ GitlabMergeRequestsMock >> getAllOfProject: anUndefinedObject [
]' }
]

{ #category : #api }
GitlabMergeRequestsMock >> getAllOfProject: project withParams: params [
^self getAllOfProject: project
]

{ #category : #api }
GitlabMergeRequestsMock >> getByPage: anInteger perPage: anInteger2 inProject: anUndefinedObject [
^ '[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,156 @@ 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 Expand Up @@ -497,7 +647,7 @@ GitlabModelImporterTest >> testParseNote [
"confidential": false,
"internal": false
}]'.
notesArray := importer parseNoteJson: jsonNote.
notesArray := importer parseNotesResult: jsonNote.
note := notesArray first.
self assert: notesArray size equals: 1.
self assert: note body equals: 'Comment for MR'
Expand Down
Loading