Skip to content

Commit fe56827

Browse files
committed
fix issues with folder structure
1 parent dc8e3b3 commit fe56827

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

code2cypher.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ import (
77
"os"
88
"log"
99
"strings"
10-
"strconv"
1110
)
1211

1312
type fileInfo struct {
1413
Name string
14+
Path string
1515
Url string
1616
Size int64
1717
Level int
1818
IsDir bool
1919
Id string
2020
Extension string
2121
ModTime int64
22-
ParentName string
23-
ParentId string
22+
ParentPath string
2423
Contributions []fileContribution
2524
CommitCount int
2625
}
@@ -42,12 +41,6 @@ func initFlags() {
4241
flag.Parse()
4342
}
4443

45-
// getUniqueNameString creates a unique string for a file based on its nested depth in the folder and its name
46-
// TODO: instead of depth, modified timestamp might be a better value to create unique variable names with
47-
func getUniqueNameString(index int, element string) string {
48-
return strconv.Itoa(index) + "-" + element
49-
}
50-
5144
// getFileExtension returns the extension for a given file's full name
5245
func getFileExtension (info os.FileInfo) string {
5346
if (info.IsDir() == false) {
@@ -85,9 +78,10 @@ func main() {
8578
fileDepth := len(pathSegments) - 1
8679
fileName := info.Name()
8780
verboseLog("fileName: " + fileName)
88-
uniqueNameString := getUniqueNameString(fileDepth, fileName)
8981

90-
if (processedFiles[uniqueNameString] != true) {
82+
if (processedFiles[path] != true) {
83+
parentPath := strings.Join(pathSegments[:len(pathSegments)-1], "/")
84+
verboseLog("parentPath: " + parentPath)
9185
parentDepth := fileDepth - 1
9286
if (parentDepth < 0) {
9387
parentDepth = 0
@@ -97,19 +91,19 @@ func main() {
9791

9892
nodes = append(nodes, fileInfo{
9993
Name: fileName,
94+
Path: path,
10095
Url: buildGitHubUrl(gitRepoUrl, path, info.IsDir()),
10196
Size: info.Size(),
10297
Level: fileDepth,
10398
Extension: getFileExtension(info),
104-
Id: createCypherFriendlyVarName(fileName, fileDepth),
99+
Id: createCypherFriendlyVarName(path, fileDepth),
105100
IsDir: info.IsDir(),
106101
ModTime: info.ModTime().Unix(),
107-
ParentName: pathSegments[parentDepth],
108-
ParentId : createCypherFriendlyVarName(pathSegments[parentDepth], parentDepth),
102+
ParentPath: parentPath,
109103
Contributions: contributions,
110104
CommitCount: len(contributions),
111105
})
112-
processedFiles[uniqueNameString] = true
106+
processedFiles[path] = true
113107
}
114108
}
115109

@@ -126,9 +120,9 @@ func main() {
126120
fmt.Println(":BEGIN")
127121
label := getLabelForFileNode(currentFile)
128122

129-
if (!processedNodes[currentFile.Id]) {
123+
if (!processedNodes[currentFile.Path]) {
130124
fmt.Println(fileInfoToCypher(currentFile, label))
131-
processedNodes[currentFile.Id] = true
125+
processedNodes[currentFile.Path] = true
132126
}
133127

134128
if (label == "file") {
@@ -157,7 +151,7 @@ func main() {
157151
fmt.Println(";")
158152
fmt.Println(":COMMIT")
159153

160-
if (currentFile.Id != currentFile.ParentId) {
154+
if (len(currentFile.ParentPath) > 0) {
161155
fmt.Println(":BEGIN")
162156
fmt.Println(folderStructureToCypher(currentFile))
163157
fmt.Println(";")

cypherGenerator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func getLabelForFileNode(currentFile fileInfo) string {
2828
// fileInfoToCypher returns a cypher statement to create a node for a given file
2929
func fileInfoToCypher(currentFile fileInfo, label string) string {
3030
properties := ("{ name: '" + currentFile.Name +
31+
"', path: '" + currentFile.Path +
3132
"', url: '" + currentFile.Url +
3233
"', _tempId: '" + currentFile.Id + "'")
3334

@@ -73,7 +74,7 @@ func contributionToCypherUpdate(contributionId string, commitCount int) string {
7374

7475
// folderStructureToCypher returns to cypher statement to create a relationship between a file and its parent folder
7576
func folderStructureToCypher(currentFile fileInfo) string {
76-
return "Match (a:directory { _tempId: '" + currentFile.ParentId +"' }) Match (b { _tempId: '" + currentFile.Id +"' }) CREATE (b)-[:IN_FOLDER]->(a)"
77+
return "Match (a:directory { path: '" + currentFile.ParentPath +"' }) Match (b { path: '" + currentFile.Path +"' }) CREATE (b)-[:IN_FOLDER]->(a)"
7778
}
7879

7980
// returns a cypher statement that removes a given property from all nodes

0 commit comments

Comments
 (0)