-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
973 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package config | ||
|
||
import "os" | ||
|
||
const FF_REPO_VIEW = "FF_REPO_VIEW" | ||
|
||
func IsFeatureEnabled(name string) bool { | ||
_, ok := os.LookupEnv(name) | ||
return ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package git | ||
|
||
import ( | ||
"sort" | ||
"time" | ||
|
||
gitm "github.com/aymanbagabas/git-module" | ||
) | ||
|
||
// Extends git.Repository | ||
type Repo struct { | ||
Origin string | ||
Remotes []string | ||
Branches []Branch | ||
} | ||
|
||
type Branch struct { | ||
Name string | ||
LastUpdatedAt *time.Time | ||
} | ||
|
||
func GetRepo(dir string) (*Repo, error) { | ||
repo, err := gitm.Open(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bNames, err := repo.Branches() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
branches := make([]Branch, len(bNames)) | ||
for i, b := range bNames { | ||
var updatedAt *time.Time | ||
commits, err := gitm.Log(dir, b, gitm.LogOptions{MaxCount: 1}) | ||
if err == nil && len(commits) > 0 { | ||
updatedAt = &commits[0].Committer.When | ||
} | ||
branches[i] = Branch{Name: b, LastUpdatedAt: updatedAt} | ||
} | ||
sort.Slice(branches, func(i, j int) bool { | ||
if branches[j].LastUpdatedAt == nil || branches[i].LastUpdatedAt == nil { | ||
return false | ||
} | ||
return branches[i].LastUpdatedAt.After(*branches[j].LastUpdatedAt) | ||
}) | ||
|
||
remotes, err := repo.Remotes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
origin, err := gitm.RemoteGetURL(dir, "origin", gitm.RemoteGetURLOptions{All: true}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Repo{Origin: origin[0], Remotes: remotes, Branches: branches}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.