feat: implement commit comparison feature in Gitea client (#659)
See the API: https://github.com/go-gitea/gitea/pull/30349 - Add a new file `repo_compare.go` with package `gitea` and `Compare` struct - Implement `CompareCommits` method in `Client` struct in `repo_compare.go` - Add `version1_22_0` constant in `version.go` Signed-off-by: appleboy <appleboy.tw@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/659 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: appleboy <appleboy.tw@gmail.com> Co-committed-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
parent
54cf14f67a
commit
e9585a460d
2 changed files with 39 additions and 1 deletions
37
forgejo/repo_compare.go
Normal file
37
forgejo/repo_compare.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package forgejo
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Compare represents a comparison between two commits.
|
||||
type Compare struct {
|
||||
TotalCommits int `json:"total_commits"` // Total number of commits in the comparison.
|
||||
Commits []*Commit `json:"commits"` // List of commits in the comparison.
|
||||
}
|
||||
|
||||
// CompareCommits compares two commits in a repository.
|
||||
func (c *Client) CompareCommits(user, repo, prev, current string) (*Compare, *Response, error) {
|
||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_22_0); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := escapeValidatePathSegments(&user, &repo, &prev, ¤t); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
basehead := fmt.Sprintf("%s...%s", prev, current)
|
||||
|
||||
apiResp := new(Compare)
|
||||
resp, err := c.getParsedResponse(
|
||||
"GET",
|
||||
fmt.Sprintf("/repos/%s/%s/compare/%s", user, repo, basehead),
|
||||
nil, nil, apiResp,
|
||||
)
|
||||
return apiResp, resp, err
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2024 The Forgjo Authors. All rights reserved.
|
||||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
|
@ -73,6 +73,7 @@ var (
|
|||
version1_15_0 = version.Must(version.NewVersion("1.15.0"))
|
||||
version1_16_0 = version.Must(version.NewVersion("1.16.0"))
|
||||
version1_17_0 = version.Must(version.NewVersion("1.17.0"))
|
||||
version1_22_0 = version.Must(version.NewVersion("1.22.0"))
|
||||
)
|
||||
|
||||
// ErrUnknownVersion is an unknown version from the API
|
||||
|
|
Loading…
Reference in a new issue