Skip to content

Commit ff03a15

Browse files
jdolcechristophwitzko
authored andcommitted
fix: Compare commits from the latest release.
1 parent cc23a5c commit ff03a15

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/provider/github.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ func (repo *GitHubRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo
8181
SHA: toSha,
8282
ListOptions: github.ListOptions{PerPage: 100},
8383
}
84+
8485
done := false
8586
for {
86-
commits, resp, err := repo.client.Repositories.ListCommits(context.Background(), repo.owner, repo.repo, opts)
87+
commits, resp, err := repo.client.Repositories.CompareCommits(context.Background(), repo.owner, repo.repo, fromSha, toSha)
8788
if err != nil {
8889
return nil, err
8990
}
90-
for _, commit := range commits {
91+
92+
for _, commit := range commits.Commits {
9193
sha := commit.GetSHA()
9294
if sha == fromSha {
9395
done = true

pkg/provider/github_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/http/httptest"
88
"net/url"
9+
"strings"
910
"testing"
1011

1112
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
@@ -100,16 +101,19 @@ func githubHandler(w http.ResponseWriter, r *http.Request) {
100101
json.NewEncoder(w).Encode(GITHUB_REPO)
101102
return
102103
}
103-
if r.Method == "GET" && r.URL.Path == "/repos/owner/test-repo/commits" {
104-
toSha := r.URL.Query().Get("sha")
104+
if r.Method == "GET" && strings.HasPrefix(r.URL.Path, "/repos/owner/test-repo/compare/") {
105+
106+
li := strings.LastIndex(r.URL.Path, "/")
107+
arr := strings.Split(r.URL.Path[li+1:], "...")
108+
toSha := arr[1]
105109
skip := 0
106110
for i, commit := range GITHUB_COMMITS {
107111
if commit.GetSHA() == toSha {
108112
skip = i
109113
break
110114
}
111115
}
112-
json.NewEncoder(w).Encode(GITHUB_COMMITS[skip:])
116+
json.NewEncoder(w).Encode(github.CommitsComparison{Commits: GITHUB_COMMITS[skip:]})
113117
return
114118
}
115119
if r.Method == "GET" && r.URL.Path == "/repos/owner/test-repo/git/matching-refs/tags" {

0 commit comments

Comments
 (0)