Skip to content

Commit

Permalink
fix: Compare commits from the latest release.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolce authored and christophwitzko committed Mar 9, 2021
1 parent cc23a5c commit ff03a15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions pkg/provider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ func (repo *GitHubRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo
SHA: toSha,
ListOptions: github.ListOptions{PerPage: 100},
}

done := false
for {
commits, resp, err := repo.client.Repositories.ListCommits(context.Background(), repo.owner, repo.repo, opts)
commits, resp, err := repo.client.Repositories.CompareCommits(context.Background(), repo.owner, repo.repo, fromSha, toSha)
if err != nil {
return nil, err
}
for _, commit := range commits {

for _, commit := range commits.Commits {
sha := commit.GetSHA()
if sha == fromSha {
done = true
Expand Down
10 changes: 7 additions & 3 deletions pkg/provider/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"

"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
Expand Down Expand Up @@ -100,16 +101,19 @@ func githubHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(GITHUB_REPO)
return
}
if r.Method == "GET" && r.URL.Path == "/repos/owner/test-repo/commits" {
toSha := r.URL.Query().Get("sha")
if r.Method == "GET" && strings.HasPrefix(r.URL.Path, "/repos/owner/test-repo/compare/") {

li := strings.LastIndex(r.URL.Path, "/")
arr := strings.Split(r.URL.Path[li+1:], "...")
toSha := arr[1]
skip := 0
for i, commit := range GITHUB_COMMITS {
if commit.GetSHA() == toSha {
skip = i
break
}
}
json.NewEncoder(w).Encode(GITHUB_COMMITS[skip:])
json.NewEncoder(w).Encode(github.CommitsComparison{Commits: GITHUB_COMMITS[skip:]})
return
}
if r.Method == "GET" && r.URL.Path == "/repos/owner/test-repo/git/matching-refs/tags" {
Expand Down

0 comments on commit ff03a15

Please sign in to comment.