Browse Source

Lint models/repo_branch.go

Bwko 3 years ago
parent
commit
ce8c9ef580
1 changed files with 12 additions and 7 deletions
  1. 12 7
      models/repo_branch.go

+ 12 - 7
models/repo_branch.go

@@ -8,11 +8,13 @@ import (
8 8
 	"code.gitea.io/git"
9 9
 )
10 10
 
11
+// Branch holds the branch information
11 12
 type Branch struct {
12 13
 	Path string
13 14
 	Name string
14 15
 }
15 16
 
17
+// GetBranchesByPath returns a branch by it's path
16 18
 func GetBranchesByPath(path string) ([]*Branch, error) {
17 19
 	gitRepo, err := git.OpenRepository(path)
18 20
 	if err != nil {
@@ -34,24 +36,27 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
34 36
 	return branches, nil
35 37
 }
36 38
 
37
-func (repo *Repository) GetBranch(br string) (*Branch, error) {
38
-	if !git.IsBranchExist(repo.RepoPath(), br) {
39
-		return nil, &ErrBranchNotExist{br}
39
+// GetBranch returns a branch by it's name
40
+func (repo *Repository) GetBranch(branch string) (*Branch, error) {
41
+	if !git.IsBranchExist(repo.RepoPath(), branch) {
42
+		return nil, &ErrBranchNotExist{branch}
40 43
 	}
41 44
 	return &Branch{
42 45
 		Path: repo.RepoPath(),
43
-		Name: br,
46
+		Name: branch,
44 47
 	}, nil
45 48
 }
46 49
 
50
+// GetBranches returns all the branches of a repository
47 51
 func (repo *Repository) GetBranches() ([]*Branch, error) {
48 52
 	return GetBranchesByPath(repo.RepoPath())
49 53
 }
50 54
 
51
-func (br *Branch) GetCommit() (*git.Commit, error) {
52
-	gitRepo, err := git.OpenRepository(br.Path)
55
+// GetCommit returns all the commits of a branch
56
+func (branch *Branch) GetCommit() (*git.Commit, error) {
57
+	gitRepo, err := git.OpenRepository(branch.Path)
53 58
 	if err != nil {
54 59
 		return nil, err
55 60
 	}
56
-	return gitRepo.GetBranchCommit(br.Name)
61
+	return gitRepo.GetBranchCommit(branch.Name)
57 62
 }