Skip to content

Commit 3d2648a

Browse files
committed
replace hard coded string values with global strings
1 parent 6e3e0a5 commit 3d2648a

17 files changed

+62
-35
lines changed

api/fetch_repo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func FetchRepo() *model.FetchRepoParams {
1919
timeStamp []*string
2020
)
2121

22+
const defaultDateFormat = "2006-01-02 15:04:05"
23+
2224
repoData := utils.DataStoreFileReader()
2325

2426
for _, repo := range repoData {
@@ -27,7 +29,7 @@ func FetchRepo() *model.FetchRepoParams {
2729
repoPathStr := repo.RepoPath
2830
timeStampStr := repo.TimeStamp
2931

30-
convTimeStamp, _ := time.Parse("2006-01-02 15:04:05", timeStampStr[:19])
32+
convTimeStamp, _ := time.Parse(defaultDateFormat, timeStampStr[:19])
3133
timeStampStr = convTimeStamp.String()
3234

3335
repoId = append(repoId, &repoIdStr)

api/settings_api.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ func UpdatePortNumber(newPort string) string {
3737
newEnvData.DataBaseFile = envData.DataBaseFile
3838

3939
cwd, _ := os.Getwd()
40-
fileString := cwd + "/env_config.json"
40+
fileString := cwd + "/" + global.EnvFileName
4141
envContent, _ := json.MarshalIndent(&newEnvData, "", " ")
4242
writeErr := ioutil.WriteFile(fileString, envContent, 0755)
4343

4444
if writeErr != nil {
4545
logger.Log(writeErr.Error(), global.StatusError)
4646
return global.PortUpdateError
4747
} else {
48-
return "PORT_UPDATED"
48+
return global.PortUpdateSuccess
4949
}
5050
} else {
5151
return global.PortUpdateError
@@ -62,15 +62,15 @@ func UpdateDBFilePath(newFilePath string) string {
6262
newEnvData.DataBaseFile = newFilePath
6363

6464
cwd, _ := os.Getwd()
65-
fileString := cwd + "/env_config.json"
65+
fileString := cwd + "/" + global.EnvFileName
6666
envContent, _ := json.MarshalIndent(&newEnvData, "", " ")
6767
writeErr := ioutil.WriteFile(fileString, envContent, 0755)
6868

6969
if writeErr != nil {
7070
logger.Log(writeErr.Error(), global.StatusError)
7171
return global.DataFileUpdateError
7272
} else {
73-
return "DATAFILE_UPDATE_SUCCESS"
73+
return global.DataFileUpdateSuccess
7474
}
7575
} else {
7676
return global.DataFileUpdateError
@@ -122,7 +122,7 @@ func DeleteRepo(repoId string) *model.DeleteStatus {
122122
return reportError(repoId, "Failed to update DB file", err.Error())
123123
}
124124
return &model.DeleteStatus{
125-
Status: "DELETE_SUCCESS",
125+
Status: global.RepoDeleteSuccess,
126126
RepoID: repoId,
127127
}
128128
} else {

git/git_branch_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ func AddBranch(repo *git.Repository, branchName string) string {
2626
}
2727

2828
logger.Log(fmt.Sprintf("Added new branch - %s to the repo", branchName), global.StatusInfo)
29-
return "BRANCH_CREATION_SUCCESS"
29+
return global.BranchAddSuccess
3030
}
3131
}

git/git_branch_delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ func DeleteBranch(repo *git.Repository, branchName string, forceFlag bool) *mode
3838
}
3939

4040
return &model.BranchDeleteStatus{
41-
Status: "BRANCH_DELETE_SUCCESS",
41+
Status: global.BranchDeleteSuccess,
4242
}
4343
}

git/git_commit_changes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func windowsCommit(repoPath string, msg string) string {
2525
return global.CommitChangeError
2626
} else {
2727
logger.Log(fmt.Sprintf("Changes committed to the repo -> %s", cmdStr), global.StatusInfo)
28-
return "COMMIT_DONE"
28+
return global.CommitChangeSuccess
2929
}
3030
}
3131

@@ -122,7 +122,7 @@ func CommitChanges(repo *git.Repository, commitMessage string) string {
122122
return global.CommitChangeError
123123
} else {
124124
logger.Log(fmt.Sprintf("Staged changes have been comitted - %s", hash.String()), global.StatusInfo)
125-
return "COMMIT_DONE"
125+
return global.CommitChangeSuccess
126126
}
127127
}
128128
}

git/git_fetch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func FetchFromRemote(repo *git.Repository, remoteURL string, remoteBranch string
100100
if fetchErr.Error() == "already up-to-date" {
101101
logger.Log(fetchErr.Error(), global.StatusWarning)
102102
return &model.FetchResult{
103-
Status: "NEW CHANGES ABSENT",
103+
Status: global.FetchNoNewChanges,
104104
FetchedItems: nil,
105105
}
106106
} else {
@@ -121,7 +121,7 @@ func FetchFromRemote(repo *git.Repository, remoteURL string, remoteBranch string
121121

122122
msg := fmt.Sprintf("Changes fetched from remote %v", remoteName)
123123
return &model.FetchResult{
124-
Status: "CHANGES FETCHED FROM REMOTE",
124+
Status: global.FetchFromRemoteSuccess,
125125
FetchedItems: []*string{&msg},
126126
}
127127
}

git/git_pull.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ func windowsPull(repoPath string, remoteName string, branch string) *model.PullR
3535

3636
msg := "No changes to pull from " + remoteName
3737
return &model.PullResult{
38-
Status: "NEW CHANGES ABSENT",
38+
Status: global.PullNoNewChanges,
3939
PulledItems: []*string{&msg},
4040
}
4141
}
4242
msg := "New Items Pulled from remote " + remoteName
4343
logger.Log(fmt.Sprintf("Changes pulled from remote -> %s", cmdStr), global.StatusInfo)
4444
return &model.PullResult{
45-
Status: "PULL SUCCESS",
45+
Status: global.PullFromRemoteSuccess,
4646
PulledItems: []*string{&msg},
4747
}
4848
}
@@ -105,7 +105,7 @@ func PullFromRemote(repo *git.Repository, remoteURL string, remoteBranch string)
105105
logger.Log("Pull failed with error : "+pullErr.Error(), global.StatusWarning)
106106
msg := "No changes to pull from " + remoteName
107107
return &model.PullResult{
108-
Status: "NEW CHANGES ABSENT",
108+
Status: global.PullNoNewChanges,
109109
PulledItems: []*string{&msg},
110110
}
111111
} else {
@@ -123,7 +123,7 @@ func PullFromRemote(repo *git.Repository, remoteURL string, remoteBranch string)
123123
logger.Log("New items pulled from remote", global.StatusInfo)
124124
msg := "New Items Pulled from remote " + remoteName
125125
return &model.PullResult{
126-
Status: "PULL SUCCESS",
126+
Status: global.PullFromRemoteSuccess,
127127
PulledItems: []*string{&msg},
128128
}
129129
}

git/git_push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func windowsPush(repoPath string, remoteName string, branch string) string {
2525
return global.PushToRemoteError
2626
} else {
2727
logger.Log(fmt.Sprintf("Changes pushed to remote -> %s", cmdStr), global.StatusInfo)
28-
return "PUSH_SUCCESS"
28+
return global.PushToRemoteSuccess
2929
}
3030
}
3131

@@ -73,6 +73,6 @@ func PushToRemote(repo *git.Repository, remoteName string, remoteBranch string)
7373
return global.PushToRemoteError
7474
} else {
7575
logger.Log(fmt.Sprintf("commits pushed to remote -> %s : %s\n%v", remoteName, targetRefPsec, b.String()), global.StatusInfo)
76-
return "PUSH_SUCCESS"
76+
return global.PushToRemoteSuccess
7777
}
7878
}

git/git_remote_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func AddRemote(repo *git.Repository, remoteName string, remoteURL string) string
1616

1717
if err == nil {
1818
logger.Log("Remoted addition completed for"+remote.String(), global.StatusInfo)
19-
return "REMOTE_ADD_SUCCESS"
19+
return global.RemoteAddSuccess
2020
} else {
2121
logger.Log("Remote addition Failed!", global.StatusError)
2222
return global.RemoteAddError

git/git_reset_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func RemoveItem(repoPath string, fileItem string) string {
2727
return removeErr(fileItem, err.Error())
2828
} else {
2929
logger.Log(fmt.Sprintf("Staged item -> %s removed from the staging area\n%s", fileItem, string(removeMsg)), global.StatusInfo)
30-
return "STAGE_REMOVE_SUCCESS"
30+
return global.RemoveItemSuccess
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)