Skip to content

Commit dc8e3b3

Browse files
committed
bring back folder structure
1 parent 6ec7d7d commit dc8e3b3

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

code2cypher.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,6 @@ func main() {
131131
processedNodes[currentFile.Id] = true
132132
}
133133

134-
/*
135-
// TODO: fix
136-
if (currentFile.Id != currentFile.ParentId) {
137-
fmt.Println(folderStructureToCypher(currentFile))
138-
}
139-
*/
140-
141134
if (label == "file") {
142135
for _, contribution := range currentFile.Contributions {
143136
contributerId := createCypherFriendlyVarName(contribution.Name, 0)
@@ -163,6 +156,13 @@ func main() {
163156

164157
fmt.Println(";")
165158
fmt.Println(":COMMIT")
159+
160+
if (currentFile.Id != currentFile.ParentId) {
161+
fmt.Println(":BEGIN")
162+
fmt.Println(folderStructureToCypher(currentFile))
163+
fmt.Println(";")
164+
fmt.Println(":COMMIT")
165+
}
166166
}
167167

168168
for contributerId, contributionCount := range processedContributersSum {
@@ -177,6 +177,10 @@ func main() {
177177
fmt.Println(";")
178178
fmt.Println(":COMMIT")
179179
}
180+
fmt.Println(":BEGIN")
181+
fmt.Println(removeProperty("_tempId"))
182+
fmt.Println(";")
183+
fmt.Println(":COMMIT")
180184

181185

182186
if err != nil {

cypherGenerator.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func getLabelForFileNode(currentFile fileInfo) string {
2727

2828
// fileInfoToCypher returns a cypher statement to create a node for a given file
2929
func fileInfoToCypher(currentFile fileInfo, label string) string {
30-
properties := ("{ name: '" + currentFile.Name + "', url: '" + currentFile.Url + "'")
30+
properties := ("{ name: '" + currentFile.Name +
31+
"', url: '" + currentFile.Url +
32+
"', _tempId: '" + currentFile.Id + "'")
3133

3234
if (!currentFile.IsDir) {
3335
properties += (", " + "size: " + strconv.FormatInt(currentFile.Size, 10) + ", " +
@@ -66,11 +68,15 @@ func commitToCypher(fileId, contributerId string, contribution fileContribution)
6668
// contributionToCypherUpdate returns a cypher statement to update a given contribution's commitCount
6769
func contributionToCypherUpdate(contributionId string, commitCount int) string {
6870
return "MATCH (c:person)-[e:EDITED { _tempId: '" + contributionId + "' }]->(f:file) " +
69-
"SET e.commitCount = " + strconv.Itoa(commitCount) + " " +
70-
"REMOVE e._tempId"
71+
"SET e.commitCount = " + strconv.Itoa(commitCount)
7172
}
7273

7374
// folderStructureToCypher returns to cypher statement to create a relationship between a file and its parent folder
7475
func folderStructureToCypher(currentFile fileInfo) string {
75-
return "CREATE (" + currentFile.Id + ")-[:IN_FOLDER]->(" + currentFile.ParentId + ")"
76+
return "Match (a:directory { _tempId: '" + currentFile.ParentId +"' }) Match (b { _tempId: '" + currentFile.Id +"' }) CREATE (b)-[:IN_FOLDER]->(a)"
77+
}
78+
79+
// returns a cypher statement that removes a given property from all nodes
80+
func removeProperty(propertyName string) string {
81+
return "MATCH (a) REMOVE a." + propertyName
7682
}

0 commit comments

Comments
 (0)