Skip to content

Commit 922db2a

Browse files
authored
Merge pull request #134 from neel1996/v2.0.2
A placeholder release v2.0.2 The actual release version will be tracked as v2.1.0, as the backend was modified to use libgit2 bindings which is a major change
2 parents a76093b + 8aa8eee commit 922db2a

File tree

131 files changed

+5675
-6815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+5675
-6815
lines changed

SECURITY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
>The back-end of the project was migrated from Node JS to Golang after release v2.0.0, so the versions before v2 will not be supported with bug fixes or security patches
6+
7+
| Version | Supported |
8+
| ------- | ------------------ |
9+
| >= 2.0.0 | :white_check_mark: |
10+
| < 2.0.0 | :x: |
11+
| 1.x.x | :x: |
12+
13+
## Reporting a Vulnerability
14+
15+
If you find any potential security issues, then please do report it [here](https://github.com/neel1996/gitconvex/issues/new?assignees=&labels=security-issue&template=bug_report.md&title=Security%20Issue&assignee=neel1996)

api/add_repo.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ import (
1515
"time"
1616
)
1717

18+
type AddRepoInterface interface {
19+
AddRepo() *model.AddRepoParams
20+
repoDataFileWriter(repoId string, repoAddStatus chan string)
21+
}
22+
23+
type AddRepoInputs struct {
24+
RepoName string
25+
RepoPath string
26+
CloneSwitch bool
27+
RepoURL *string
28+
InitSwitch bool
29+
AuthOption string
30+
UserName *string
31+
Password *string
32+
}
33+
1834
type RepoData struct {
1935
Id string `json:"id"`
2036
RepoName string `json:"repoName"`
@@ -71,13 +87,13 @@ func dataFileWriteHandler(dbFile string, repoDataArray []RepoData) error {
7187
}
7288

7389
// repoDataFileWriter writes the new repo details to the repo_datastore.json file
74-
func repoDataFileWriter(repoId string, repoName string, repoPath string, repoAddStatus chan string) {
90+
func (inputs AddRepoInputs) repoDataFileWriter(repoId string, repoAddStatus chan string) {
7591
rArray := make([]RepoData, 1)
7692

7793
rArray[0] = RepoData{
7894
Id: repoId,
79-
RepoName: repoName,
80-
RepoPath: repoPath,
95+
RepoName: inputs.RepoName,
96+
RepoPath: inputs.RepoPath,
8197
TimeStamp: time.Now().String(),
8298
}
8399

@@ -116,9 +132,7 @@ func repoDataFileWriter(repoId string, repoName string, repoPath string, repoAdd
116132
// AddRepo function gets the repository details and includes a record to the gitconvex repo datastore file
117133
// If initSwitch is 'true' then the git repo init function will be invoked to initialize a new repo
118134
// If cloneSwitch is 'true' then the repo will be cloned to the file system using the repoURL field
119-
func AddRepo(inputs model.NewRepoInputs) *model.AddRepoParams {
120-
var repoIdChannel = make(chan string)
121-
135+
func (inputs AddRepoInputs) AddRepo() *model.AddRepoParams {
122136
repoName := inputs.RepoName
123137
repoPath := inputs.RepoPath
124138
cloneSwitch := inputs.CloneSwitch
@@ -130,8 +144,18 @@ func AddRepo(inputs model.NewRepoInputs) *model.AddRepoParams {
130144

131145
if cloneSwitch && len(*repoURL) > 0 {
132146
repoPath = repoPath + "/" + repoName
147+
inputs.RepoPath = repoPath
148+
149+
var cloneObject git.CloneInterface
150+
cloneObject = git.CloneStruct{
151+
RepoPath: repoPath,
152+
RepoURL: *repoURL,
153+
AuthOption: authOption,
154+
UserName: userName,
155+
Password: password,
156+
}
133157

134-
_, err := git.CloneHandler(repoPath, *repoURL, authOption, userName, password)
158+
_, err := cloneObject.CloneHandler()
135159
if err != nil {
136160
localLogger(fmt.Sprintf("%v", err), global.StatusError)
137161
return &model.AddRepoParams{
@@ -165,11 +189,12 @@ func AddRepo(inputs model.NewRepoInputs) *model.AddRepoParams {
165189
}
166190
}
167191

192+
var repoIdChannel = make(chan string)
168193
go repoIdGenerator(repoIdChannel)
169194
repoId := <-repoIdChannel
170195

171196
var repoAddStatusChannel = make(chan string)
172-
go repoDataFileWriter(repoId, repoName, repoPath, repoAddStatusChannel)
197+
go inputs.repoDataFileWriter(repoId, repoAddStatusChannel)
173198
status := <-repoAddStatusChannel
174199

175200
close(repoIdChannel)

api/code_file_view.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ import (
88
"os"
99
)
1010

11+
type CodeViewInputs struct {
12+
RepoPath string
13+
FileName string
14+
}
15+
16+
type CodeViewInterface interface {
17+
CodeFileView() *model.CodeFileType
18+
}
19+
1120
// CodeFileView returns the lines from the target file and the latest commit corresponding to the file
12-
func CodeFileView(repoPath string, fileName string) *model.CodeFileType {
21+
func (c CodeViewInputs) CodeFileView() *model.CodeFileType {
1322
var codeLines []*string
1423

15-
targetFile := repoPath + "/" + fileName
24+
targetFile := c.RepoPath + "/" + c.FileName
1625
logger := global.Logger{}
1726
file, err := os.Open(targetFile)
1827

api/repo_status.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func RepoStatus(repoId string) *model.GitRepoStatusResults {
1919
commitChan := make(chan git.AllCommitData)
2020
trackedFileCountChan := make(chan int)
2121

22-
go git.Repo(repoId, repoChan)
22+
var repoObject git.RepoInterface
23+
repoObject = git.RepoStruct{RepoId: repoId}
24+
go repoObject.Repo(repoChan)
2325

2426
var repoName *string
2527
r := <-repoChan
@@ -42,7 +44,14 @@ func RepoStatus(repoId string) *model.GitRepoStatusResults {
4244
remote := ""
4345
var remoteURL *string
4446
remoteURL = &remote
45-
go git.RemoteData(repo, remoteChan)
47+
48+
var remoteDataObject git.RemoteDataInterface
49+
remoteDataObject = git.RemoteDataStruct{
50+
Repo: repo,
51+
RemoteURL: *remoteURL,
52+
}
53+
54+
go remoteDataObject.RemoteData(remoteChan)
4655
remoteData := <-remoteChan
4756
remotes := remoteData.RemoteURL
4857

@@ -71,21 +80,31 @@ func RepoStatus(repoId string) *model.GitRepoStatusResults {
7180
*remoteURL = *remotes[0]
7281
}
7382

74-
go git.GetBranchList(repo, branchChan)
83+
var branchListObject git.BranchListInterface
84+
branchListObject = git.BranchListInputs{Repo: repo}
85+
go branchListObject.GetBranchList(branchChan)
86+
7587
branchList := <-branchChan
7688
currentBranch := &branchList.CurrentBranch
7789
branches := branchList.BranchList
7890
allBranches := branchList.AllBranchList
7991

8092
var latestCommit *string
8193

82-
go git.AllCommits(repo, commitChan)
94+
var allCommitObject git.AllCommitInterface
95+
allCommitObject = git.AllCommitStruct{Repo: repo}
96+
go allCommitObject.AllCommits(commitChan)
8397
commitData := <-commitChan
8498
latestCommit = &commitData.LatestCommit
8599
totalCommits := commitData.TotalCommits
86100
totalCommitsPtr := &totalCommits
87101

88-
go git.TrackedFileCount(repo, trackedFileCountChan)
102+
var listFilesObject git.ListFilesInterface
103+
listFilesObject = git.ListFilesStruct{
104+
Repo: repo,
105+
}
106+
107+
go listFilesObject.TrackedFileCount(trackedFileCountChan)
89108
trackedFileCount := <-trackedFileCountChan
90109
trackedFilePtr := &trackedFileCount
91110

git/git_branch_add.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@ import (
77
"github.com/neel1996/gitconvex-server/global"
88
)
99

10+
type AddBranchInterface interface {
11+
AddBranch() string
12+
}
13+
14+
type AddBranchInput struct {
15+
Repo *git.Repository
16+
BranchName string
17+
}
18+
1019
// AddBranch adds a new branch to the target repo
11-
func AddBranch(repo *git.Repository, branchName string) string {
20+
func (input AddBranchInput) AddBranch() string {
1221
logger := global.Logger{}
22+
23+
repo := input.Repo
24+
branchName := input.BranchName
25+
1326
headRef, headErr := repo.Head()
1427

1528
logger.Log(fmt.Sprintf("Adding new branch -> %s", branchName), global.StatusInfo)

git/git_branch_checkout.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,58 @@ import (
88
"strings"
99
)
1010

11+
type BranchCheckoutInterface interface {
12+
intermediateFetch()
13+
CheckoutBranch() string
14+
}
15+
16+
type BranchCheckoutInputs struct {
17+
Repo *git.Repository
18+
BranchName string
19+
}
20+
1121
// intermediateFetch performs a remote fetch if the selected checkout branch is a remote branch
12-
func intermediateFetch(repo *git.Repository, branchName string) {
22+
func (inputs BranchCheckoutInputs) intermediateFetch() {
23+
repo := inputs.Repo
24+
branchName := inputs.BranchName
25+
1326
logger.Log("Fetching from remote for remote branch -> "+branchName, global.StatusInfo)
1427
remoteChan := make(chan RemoteDataModel)
15-
go RemoteData(repo, remoteChan)
28+
29+
var remoteDataObject RemoteDataInterface
30+
remoteDataObject = RemoteDataStruct{
31+
Repo: repo,
32+
}
33+
go remoteDataObject.RemoteData(remoteChan)
34+
1635
remoteData := <-remoteChan
1736
remoteURL := remoteData.RemoteURL
18-
FetchFromRemote(repo, *remoteURL[0], branchName)
37+
38+
remoteDataObject = RemoteDataStruct{
39+
Repo: repo,
40+
RemoteURL: *remoteURL[0],
41+
}
42+
43+
var fetchObject FetchInterface
44+
fetchObject = FetchStruct{
45+
Repo: repo,
46+
RemoteName: remoteDataObject.GetRemoteName(),
47+
RepoPath: "",
48+
RemoteURL: *remoteURL[0],
49+
RemoteBranch: branchName,
50+
}
51+
52+
fetchObject.FetchFromRemote()
1953
}
2054

2155
// CheckoutBranch checks out the branchName received as argument
22-
func CheckoutBranch(repo *git.Repository, branchName string) string {
56+
func (inputs BranchCheckoutInputs) CheckoutBranch() string {
2357
var isRemoteBranch bool
2458
var referenceBranchName string
2559

60+
repo := inputs.Repo
61+
branchName := inputs.BranchName
62+
2663
logger := global.Logger{}
2764
w, _ := repo.Worktree()
2865

@@ -38,7 +75,7 @@ func CheckoutBranch(repo *git.Repository, branchName string) string {
3875
// If the branch is a remote branch then a remote fetch will be performed and then the branch checkout will be initiated
3976
if isRemoteBranch {
4077
logger.Log(fmt.Sprintf("Branch - %s is a remote branch\nTrying with intermediate remote fetch!", branchName), global.StatusWarning)
41-
intermediateFetch(repo, branchName)
78+
inputs.intermediateFetch()
4279

4380
checkoutErr := w.Checkout(&git.CheckoutOptions{
4481
Branch: plumbing.ReferenceName(referenceBranchName),

git/git_branch_compare.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@ import (
1010
"strings"
1111
)
1212

13+
type BranchCompareInterface interface {
14+
CompareBranch() []*model.BranchCompareResults
15+
}
16+
17+
type BranchCompareInputs struct {
18+
Repo *git.Repository
19+
BaseBranch string
20+
DiffBranch string
21+
}
22+
1323
// CompareBranch compares two branches and returns the commits which are different from each other
1424
// The function uses the git client to fetch the results as go-git lacks this feature
15-
func CompareBranch(repo *git.Repository, baseBranch string, compareBranch string) []*model.BranchCompareResults {
25+
func (inputs BranchCompareInputs) CompareBranch() []*model.BranchCompareResults {
1626
var diffCommits []*model.BranchCompareResults
1727
var commits []model.GitCommits
28+
repo := inputs.Repo
29+
baseBranch := inputs.BaseBranch
30+
compareBranch := inputs.DiffBranch
31+
1832
w, _ := repo.Worktree()
1933

2034
if w == nil {

git/git_branch_delete.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@ import (
88
"github.com/neel1996/gitconvex-server/graph/model"
99
)
1010

11+
type DeleteBranchInterface interface {
12+
DeleteBranch() *model.BranchDeleteStatus
13+
}
14+
15+
type DeleteBranchInputs struct {
16+
Repo *git.Repository
17+
BranchName string
18+
ForceFlag bool
19+
}
20+
1121
// DeleteBranch deleted a branch from the repo
1222
// If forceFlag is true then it will forcefully delete a branch
1323
// If forceFlag is false, then the branch status will be checked for unmerged changes and then it will be removed from the repo
14-
func DeleteBranch(repo *git.Repository, branchName string, forceFlag bool) *model.BranchDeleteStatus {
24+
func (inputs DeleteBranchInputs) DeleteBranch() *model.BranchDeleteStatus {
1525
var branchErr error
1626
logger := global.Logger{}
1727

28+
repo := inputs.Repo
29+
branchName := inputs.BranchName
30+
forceFlag := inputs.ForceFlag
31+
1832
headRef, _ := repo.Head()
1933
ref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/%v", branchName)), headRef.Hash())
2034

git/git_branch_list.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import (
99
"strings"
1010
)
1111

12+
type BranchListInterface interface {
13+
GetBranchList(branchChan chan Branch)
14+
}
15+
16+
type BranchListInputs struct {
17+
Repo *git.Repository
18+
}
19+
1220
type Branch struct {
1321
CurrentBranch string
1422
BranchList []*string
@@ -39,13 +47,13 @@ func isBranchNameValid(branchName string) bool {
3947

4048
// GetBranchList fetches all the branches from the target repository
4149
// The result will be returned as a struct with the current branch and all the available branches
42-
func GetBranchList(repo *git.Repository, branchChan chan Branch) {
50+
func (inputs BranchListInputs) GetBranchList(branchChan chan Branch) {
4351
var (
4452
branches []*string
4553
allBranchList []*string
4654
)
4755
var currentBranch string
48-
56+
repo := inputs.Repo
4957
logger := global.Logger{}
5058

5159
if repo != nil {

0 commit comments

Comments
 (0)