Skip to content

Commit 7467e09

Browse files
authored
Added more go git libs (#26)
1 parent 098fc48 commit 7467e09

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

go-libs/git/checkout.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ func (l *Checkout) cmd(ctx context.Context, args ...string) (string, error) {
3636
return strings.TrimSpace(out), nil
3737
}
3838

39+
func (l *Checkout) OrgAndRepo() (string, string, bool) {
40+
tmp := strings.TrimSuffix(l.fetchRemote, ".git")
41+
tmp = strings.TrimPrefix(tmp, "https://github.com/")
42+
tmp = strings.TrimPrefix(tmp, "git@github.com:")
43+
return strings.Cut(tmp, "/")
44+
}
45+
3946
func (l *Checkout) remotes(ctx context.Context) (map[string]string, error) {
4047
remotes := map[string]string{
4148
"fetch": "origin",

go-libs/github/commits.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package github
2+
3+
import "time"
4+
5+
type CommitAuthor struct {
6+
Date time.Time `json:"date,omitempty"`
7+
Name string `json:"name,omitempty"`
8+
Email string `json:"email,omitempty"`
9+
}
10+
11+
type User struct {
12+
Login string `json:"login,omitempty"`
13+
Name string `json:"name,omitempty"`
14+
Company string `json:"company,omitempty"`
15+
Email string `json:"email,omitempty"`
16+
}
17+
18+
type SignatureVerification struct {
19+
Verified bool `json:"verified,omitempty"`
20+
Reason string `json:"reason,omitempty"`
21+
Signature string `json:"signature,omitempty"`
22+
Payload string `json:"payload,omitempty"`
23+
}
24+
25+
type Commit struct {
26+
SHA string `json:"sha,omitempty"`
27+
Author CommitAuthor `json:"author,omitempty"`
28+
Committer CommitAuthor `json:"committer,omitempty"`
29+
Message string `json:"message,omitempty"`
30+
Parents []Commit `json:"parents,omitempty"`
31+
Verification SignatureVerification `json:"verification,omitempty"`
32+
}
33+
34+
type RepositoryCommit struct {
35+
SHA string `json:"sha,omitempty"`
36+
Commit Commit `json:"commit,omitempty"`
37+
Author User `json:"author,omitempty"`
38+
Committer User `json:"committer,omitempty"`
39+
Parents []Commit `json:"parents,omitempty"`
40+
HTMLURL string `json:"html_url,omitempty"`
41+
URL string `json:"url,omitempty"`
42+
CommentsURL string `json:"comments_url,omitempty"`
43+
}

go-libs/github/github.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
)
1111

1212
const gitHubAPI = "https://api.github.com"
13-
const gitHubUserContent = "https://raw.githubusercontent.com"
1413

1514
type GitHubClient struct {
1615
api *httpclient.ApiClient
@@ -83,3 +82,12 @@ func (c *GitHubClient) ListRuns(ctx context.Context, org, repo, workflow string)
8382
err := c.api.Do(ctx, "GET", path, httpclient.WithResponseUnmarshal(&response))
8483
return response.WorkflowRuns, err
8584
}
85+
86+
func (c *GitHubClient) CompareCommits(ctx context.Context, org, repo, base, head string) ([]RepositoryCommit, error) {
87+
path := fmt.Sprintf("/repos/%v/%v/compare/%v...%v", org, repo, base, head)
88+
var response struct {
89+
Commits []RepositoryCommit `json:"commits,omitempty"`
90+
}
91+
err := c.api.Do(ctx, "GET", path, httpclient.WithResponseUnmarshal(&response))
92+
return response.Commits, err
93+
}

0 commit comments

Comments
 (0)