forked from orbitalci/orbital
/
paths.go
48 lines (39 loc) · 1.28 KB
/
paths.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package github
import (
"strings"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/google/go-github/v19/github"
"github.com/shankj3/ocelot/models/pb"
)
var (
REPOS = "repos"
FILE = REPOS + "/%s/contents/%s"
)
// url replacements for githubVCS, see below for urls returned and what to replace
var (
//"contents_url": "https://api.github.com/repos/shankj3/legis_data/contents/{+path}",
CONTENTS_URL_REPLACE = "{+path}"
)
func getUrlForFileFromContentsUrl(contentsUrl string, relativeFilepath string) string {
return strings.Replace(contentsUrl, CONTENTS_URL_REPLACE, relativeFilepath, 1)
}
func translateToBranchHistory(branch *github.Branch) *pb.BranchHistory {
return &pb.BranchHistory{
Branch: branch.GetName(),
Hash: branch.Commit.GetSHA(),
LastCommitTime: ×tamp.Timestamp{Seconds: branch.GetCommit().GetCommit().GetAuthor().GetDate().Unix()},
}
}
func splitAcctRepo(acctRepo string) (account, repo string) {
acctRepoList := strings.SplitN(acctRepo, "/", 2)
account = acctRepoList[0]
repo = acctRepoList[1]
return
}
func translateToCommit(commit *github.RepositoryCommit) *pb.Commit {
return &pb.Commit{
Hash: commit.GetSHA(),
Message: commit.GetCommit().GetMessage(),
Date: ×tamp.Timestamp{Seconds: commit.GetCommit().GetAuthor().GetDate().Unix()},
}
}