Skip to content

Commit d2b32a6

Browse files
author
TP Honey
authored
Merge pull request #149 from tphoney/commit_add_path
(feat) add path support for list commits on github and gitlab
2 parents dafaf7e + 62e8881 commit d2b32a6

File tree

5 files changed

+72
-52
lines changed

5 files changed

+72
-52
lines changed

README.md

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Doc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](http://godoc.org/github.com/drone/go-scm/scm)
44

5-
Package scm provides a unified interface to multiple source code management systems including GitHub, GitHub Enterprise, Bitbucket, Bitbucket Server, Gitea and Gogs.
5+
Package scm provides a unified interface to multiple source code management systems including GitHub, GitHub Enterprise, Bitbucket, Bitbucket Server, Gitee, Gitea and Gogs.
66

77
## Getting Started
88

@@ -12,21 +12,21 @@ Create a GitHub client:
1212
package main
1313

1414
import (
15-
"github.com/drone/go-scm/scm"
16-
"github.com/drone/go-scm/scm/driver/github"
15+
"github.com/drone/go-scm/scm"
16+
"github.com/drone/go-scm/scm/driver/github"
1717
)
1818

1919
func main() {
20-
client := github.NewDefault()
20+
client := github.NewDefault()
2121
}
2222
```
2323

2424
Create a GitHub Enterprise client:
2525

2626
```Go
2727
import (
28-
"github.com/drone/go-scm/scm"
29-
"github.com/drone/go-scm/scm/driver/github"
28+
"github.com/drone/go-scm/scm"
29+
"github.com/drone/go-scm/scm/driver/github"
3030
)
3131

3232
func main() {
@@ -38,8 +38,8 @@ Create a Bitbucket client:
3838

3939
```Go
4040
import (
41-
"github.com/drone/go-scm/scm"
42-
"github.com/drone/go-scm/scm/driver/bitbucket"
41+
"github.com/drone/go-scm/scm"
42+
"github.com/drone/go-scm/scm/driver/bitbucket"
4343
)
4444

4545
func main() {
@@ -51,8 +51,8 @@ Create a Bitbucket Server (Stash) client:
5151

5252
```Go
5353
import (
54-
"github.com/drone/go-scm/scm"
55-
"github.com/drone/go-scm/scm/driver/stash"
54+
"github.com/drone/go-scm/scm"
55+
"github.com/drone/go-scm/scm/driver/stash"
5656
)
5757

5858
func main() {
@@ -64,25 +64,25 @@ Create a Gitea client:
6464

6565
```Go
6666
import (
67-
"github.com/drone/go-scm/scm"
68-
"github.com/drone/go-scm/scm/driver/gitea"
67+
"github.com/drone/go-scm/scm"
68+
"github.com/drone/go-scm/scm/driver/gitea"
6969
)
7070

7171
func main() {
72-
client, err := gitea.New("https://gitea.company.com")
72+
client, err := gitea.New("https://gitea.company.com")
7373
}
7474
```
7575

7676
Create a Gitee client:
7777

7878
```Go
7979
import (
80-
"github.com/drone/go-scm/scm"
81-
"github.com/drone/go-scm/scm/driver/gitee"
80+
"github.com/drone/go-scm/scm"
81+
"github.com/drone/go-scm/scm/driver/gitee"
8282
)
8383

8484
func main() {
85-
client, err := gitee.New("https://gitee.com/api/v5")
85+
client, err := gitee.New("https://gitee.com/api/v5")
8686
}
8787
```
8888

@@ -94,35 +94,35 @@ The scm client does not directly handle authentication. Instead, when creating a
9494
package main
9595

9696
import (
97-
"github.com/drone/go-scm/scm"
98-
"github.com/drone/go-scm/scm/driver/github"
99-
"github.com/drone/go-scm/scm/transport"
100-
"github.com/drone/go-scm/scm/transport/oauth2"
97+
"github.com/drone/go-scm/scm"
98+
"github.com/drone/go-scm/scm/driver/github"
99+
"github.com/drone/go-scm/scm/transport"
100+
"github.com/drone/go-scm/scm/transport/oauth2"
101101
)
102102

103103
func main() {
104-
client := github.NewDefault()
105-
106-
// provide a custom http.Client with a transport
107-
// that injects the oauth2 token.
108-
client.Client = &http.Client{
109-
Transport: &oauth2.Transport{
110-
Source: oauth2.StaticTokenSource(
111-
&scm.Token{
112-
Token: "ecf4c1f9869f59758e679ab54b4",
113-
},
114-
),
115-
},
116-
}
117-
118-
// provide a custom http.Client with a transport
119-
// that injects the private GitLab token through
120-
// the PRIVATE_TOKEN header variable.
121-
client.Client = &http.Client{
122-
Transport: &transport.PrivateToken{
123-
Token: "ecf4c1f9869f59758e679ab54b4",
124-
},
125-
}
104+
client := github.NewDefault()
105+
106+
// provide a custom http.Client with a transport
107+
// that injects the oauth2 token.
108+
client.Client = &http.Client{
109+
Transport: &oauth2.Transport{
110+
Source: oauth2.StaticTokenSource(
111+
&scm.Token{
112+
Token: "ecf4c1f9869f59758e679ab54b4",
113+
},
114+
),
115+
},
116+
}
117+
118+
// provide a custom http.Client with a transport
119+
// that injects the private GitLab token through
120+
// the PRIVATE_TOKEN header variable.
121+
client.Client = &http.Client{
122+
Transport: &transport.PrivateToken{
123+
Token: "ecf4c1f9869f59758e679ab54b4",
124+
},
125+
}
126126
}
127127
```
128128

@@ -136,14 +136,14 @@ Example code to get an issue:
136136
issue, _, err := client.Issues.Find(ctx, "octocat/Hello-World", 1)
137137
```
138138

139-
Example code to get a list of issues:
139+
Example code to get a list of issues:
140140

141141
```Go
142142
opts := scm.IssueListOptions{
143-
Page: 1,
144-
Size: 30,
145-
Open: true,
146-
Closed: false,
143+
Page: 1,
144+
Size: 30,
145+
Open: true,
146+
Closed: false,
147147
}
148148

149149
issues, _, err := client.Issues.List(ctx, "octocat/Hello-World", opts)
@@ -153,12 +153,24 @@ Example code to create an issue comment:
153153

154154
```Go
155155
in := &scm.CommentInput{
156-
Body: "Found a bug",
156+
Body: "Found a bug",
157157
}
158158

159159
comment, _, err := client.Issues.CreateComment(ctx, "octocat/Hello-World", 1, in)
160160
```
161161

162+
## Useful links
163+
164+
Here are some useful links to providers API documentation:
165+
166+
Bitbucket cloud API: `https://developer.atlassian.com/cloud/bitbucket/rest/intro/`
167+
Bitbucket server/Stash API: `https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html`
168+
Gitea API: `https://gitea.com/api/swagger/#/`
169+
Gitee API: `https://gitee.com/api/swagger/#/`
170+
Github API: `https://docs.github.com/en/rest/reference`
171+
Gitlab API: `https://docs.gitlab.com/ee/api/api_resources.html`
172+
Gogs API: `https://github.com/gogs/docs-api`
173+
162174
## Release procedure
163175

164176
Run the changelog generator.

scm/driver/github/util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func encodeCommitListOptions(opts scm.CommitListOptions) string {
3333
if opts.Ref != "" {
3434
params.Set("ref", opts.Ref)
3535
}
36+
if opts.Path != "" {
37+
params.Set("path", opts.Path)
38+
}
3639
return params.Encode()
3740
}
3841

@@ -98,4 +101,4 @@ func encodeReleaseListOptions(opts scm.ReleaseListOptions) string {
98101
params.Set("state", "closed")
99102
}
100103
return params.Encode()
101-
}
104+
}

scm/driver/github/util_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ func Test_encodeCommitListOptions(t *testing.T) {
2727
Page: 10,
2828
Size: 30,
2929
Ref: "master",
30+
Path: "readme.md",
3031
}
31-
want := "page=10&per_page=30&ref=master"
32+
want := "page=10&path=readme.md&per_page=30&ref=master"
3233
got := encodeCommitListOptions(opts)
3334
if got != want {
3435
t.Errorf("Want encoded commit list options %q, got %q", want, got)

scm/driver/gitlab/util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func encodeCommitListOptions(opts scm.CommitListOptions) string {
5858
if opts.Ref != "" {
5959
params.Set("ref_name", opts.Ref)
6060
}
61+
if opts.Path != "" {
62+
params.Set("path", opts.Path)
63+
}
6164
return params.Encode()
6265
}
6366

@@ -111,4 +114,4 @@ func encodeMilestoneListOptions(opts scm.MilestoneListOptions) string {
111114
params.Set("state", "closed")
112115
}
113116
return params.Encode()
114-
}
117+
}

scm/driver/gitlab/util_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ func Test_encodeCommitListOptions(t *testing.T) {
3939
Page: 10,
4040
Size: 30,
4141
Ref: "master",
42+
Path: "Readme.md",
4243
}
43-
want := "page=10&per_page=30&ref_name=master"
44+
want := "page=10&path=Readme.md&per_page=30&ref_name=master"
4445
got := encodeCommitListOptions(opts)
4546
if got != want {
4647
t.Errorf("Want encoded commit list options %q, got %q", want, got)

0 commit comments

Comments
 (0)