Skip to content

Commit d27b6eb

Browse files
committed
restore global package and create new package for errors
1 parent f0655fb commit d27b6eb

9 files changed

+35
-310
lines changed

constants/common_strings.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

constants/current_version.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

constants/default_dir_const.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

constants/errors.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package constants
2+
3+
type ApiError struct {
4+
error
5+
ErrorCode string
6+
ErrorString string
7+
}
8+
9+
var (
10+
BranchAddError = ApiError{ErrorCode: "BRANCH_ADD_FAILED", ErrorString: "Failed to add new branch"}
11+
BranchCheckoutError = ApiError{ErrorCode: "CHECKOUT_FAILED", ErrorString: "Failed to checkout branch"}
12+
BranchDeleteError = ApiError{ErrorCode: "BRANCH_DELETE_FAILED", ErrorString: "Failed to delete branch"}
13+
RemoteAddError = ApiError{ErrorCode: "REMOTE_ADD_FAILED", ErrorString: "Failed to delete add new remote"}
14+
RemoteDeleteError = ApiError{ErrorCode: "REMOTE_DELETE_FAILED", ErrorString: "Failed to delete add new remote"}
15+
RemoteEditError = ApiError{ErrorCode: "REMOTE_EDIT_FAILED", ErrorString: "Failed to delete add new remote"}
16+
FetchFromRemoteError = ApiError{ErrorCode: "FETCH_ERROR", ErrorString: "Failed to delete add new remote"}
17+
PullFromRemoteError = ApiError{ErrorCode: "PULL_ERROR", ErrorString: "Failed to delete add new remote"}
18+
StageItemError = ApiError{ErrorCode: "ADD_ITEM_FAILED", ErrorString: "Failed to delete add new remote"}
19+
StageAllItemsError = ApiError{ErrorCode: "ALL_STAGE_FAILED", ErrorString: "Failed to delete add new remote"}
20+
RemoveItemError = ApiError{ErrorCode: "STAGE_REMOVE_FAILED", ErrorString: "Failed to delete add new remote"}
21+
RemoveAllItemsError = ApiError{ErrorCode: "STAGE_ALL_REMOVE_FAILED", ErrorString: "Failed to delete add new remote"}
22+
CommitChangeError = ApiError{ErrorCode: "COMMIT_FAILED", ErrorString: "Failed to delete add new remote"}
23+
PushToRemoteError = ApiError{ErrorCode: "PUSH_FAILED", ErrorString: "Failed to delete add new remote"}
24+
PortUpdateError = ApiError{ErrorCode: "PORT_UPDATE_FAILED", ErrorString: "Failed to delete add new remote"}
25+
DataFileUpdateError = ApiError{ErrorCode: "DATAFILE_UPDATE_FAILED", ErrorString: "Failed to delete add new remote"}
26+
RepoDeleteError = ApiError{ErrorCode: "DELETE_FAILED", ErrorString: "Failed to delete add new remote"}
27+
CommitLogsError = ApiError{ErrorCode: "LIST_COMMIT_LOGS_FAILED", ErrorString: "Failed to delete add new remote"}
28+
)
29+
30+
func (e ApiError) Error() string {
31+
return e.ErrorString
32+
}

constants/global_logger.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

constants/status_strings.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

git/commit/git_total_commits.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ func (t totalCommits) Get() int {
2525
var total = 0
2626
repo := t.repo
2727

28-
logItr, itrErr := repo.Walk()
29-
if itrErr != nil {
30-
logger.Log(fmt.Sprintf("Repo has no logs -> %s", itrErr.Error()), global.StatusError)
31-
return total
32-
}
33-
34-
commits, err := t.allCommitLogs(logItr)
28+
allLogs := NewListAllLogs(repo)
29+
commits, err := allLogs.Get()
3530
if err != nil {
36-
logger.Log(fmt.Sprintf("Unable to obtain commits for the repo"), global.StatusError)
31+
logger.Log(fmt.Sprintf("Unable to obtain commits for the repo : %v", err.Error()), global.StatusError)
3732
return total
3833
}
3934

@@ -47,26 +42,6 @@ func (t totalCommits) Get() int {
4742
return total
4843
}
4944

50-
func (t totalCommits) allCommitLogs(logItr middleware.RevWalk) ([]git2go.Commit, error) {
51-
var c commitType
52-
_ = logItr.PushHead()
53-
54-
err := logItr.Iterate(revIterator(&c))
55-
56-
return c.commits, err
57-
}
58-
59-
func revIterator(c *commitType) git2go.RevWalkIterator {
60-
return func(commit *git2go.Commit) bool {
61-
if commit != nil {
62-
c.commits = append(c.commits, *commit)
63-
return true
64-
}
65-
66-
return false
67-
}
68-
}
69-
7045
func NewTotalCommits(repo middleware.Repository) Total {
7146
return totalCommits{repo: repo}
7247
}

git/git_commit_logs.go

Lines changed: 0 additions & 166 deletions
This file was deleted.

global/errors.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const (
55
BranchCheckoutError = "CHECKOUT_FAILED"
66
BranchDeleteError = "BRANCH_DELETE_FAILED"
77
RemoteAddError = "REMOTE_ADD_FAILED"
8-
RemoteDeleteError = "REMOTE_DELETE_FAILED"
9-
RemoteEditError = "REMOTE_EDIT_FAILED"
108
FetchFromRemoteError = "FETCH_ERROR"
119
PullFromRemoteError = "PULL_ERROR"
1210
StageItemError = "ADD_ITEM_FAILED"

0 commit comments

Comments
 (0)