Skip to content

Commit

Permalink
Merge pull request #1845 from puskunalis/puskunalis/add-unidiff
Browse files Browse the repository at this point in the history
feat(options): Add unidiff option
  • Loading branch information
svanharmelen committed Dec 9, 2023
2 parents 0cb04be + 2ad1dc1 commit d3e39bd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ func (d Diff) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-the-diff-of-a-commit
type GetCommitDiffOptions ListOptions
type GetCommitDiffOptions struct {
ListOptions
Unidiff *bool `url:"unidiff,omitempty" json:"unidiff,omitempty"`
}

// GetCommitDiff gets the diff of a commit in a project..
//
Expand Down
19 changes: 16 additions & 3 deletions merge_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func (s *MergeRequestsService) GetMergeRequestCommits(pid interface{}, mergeRequ
// https://docs.gitlab.com/ee/api/merge_requests.html#get-single-merge-request-changes
type GetMergeRequestChangesOptions struct {
AccessRawDiffs *bool `url:"access_raw_diffs,omitempty" json:"access_raw_diffs,omitempty"`
Unidiff *bool `url:"unidiff,omitempty" json:"unidiff,omitempty"`
}

// GetMergeRequestChanges shows information about the merge request including
Expand Down Expand Up @@ -501,7 +502,10 @@ func (s *MergeRequestsService) GetMergeRequestChanges(pid interface{}, mergeRequ
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_requests.html#list-merge-request-diffs
type ListMergeRequestDiffsOptions ListOptions
type ListMergeRequestDiffsOptions struct {
ListOptions
Unidiff *bool `url:"unidiff,omitempty" json:"unidiff,omitempty"`
}

// ListMergeRequestDiffs List diffs of the files changed in a merge request
//
Expand Down Expand Up @@ -908,18 +912,27 @@ func (s *MergeRequestsService) GetMergeRequestDiffVersions(pid interface{}, merg
return v, resp, nil
}

// GetSingleMergeRequestDiffVersionOptions represents the available
// GetSingleMergeRequestDiffVersion() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-merge-request-diff-version
type GetSingleMergeRequestDiffVersionOptions struct {
Unidiff *bool `url:"unidiff,omitempty" json:"unidiff,omitempty"`
}

// GetSingleMergeRequestDiffVersion get a single MR diff version
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-merge-request-diff-version
func (s *MergeRequestsService) GetSingleMergeRequestDiffVersion(pid interface{}, mergeRequest, version int, options ...RequestOptionFunc) (*MergeRequestDiffVersion, *Response, error) {
func (s *MergeRequestsService) GetSingleMergeRequestDiffVersion(pid interface{}, mergeRequest, version int, opt *GetSingleMergeRequestDiffVersionOptions, options ...RequestOptionFunc) (*MergeRequestDiffVersion, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/versions/%d", PathEscape(project), mergeRequest, version)

req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions merge_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ func TestListMergeRequestDiffs(t *testing.T) {
})

opts := &ListMergeRequestDiffsOptions{
Page: 1,
PerPage: 2,
ListOptions: ListOptions{Page: 1, PerPage: 2},
}

diffs, _, err := client.MergeRequests.ListMergeRequestDiffs(1, 1, opts)
Expand Down
1 change: 1 addition & 0 deletions repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ type CompareOptions struct {
From *string `url:"from,omitempty" json:"from,omitempty"`
To *string `url:"to,omitempty" json:"to,omitempty"`
Straight *bool `url:"straight,omitempty" json:"straight,omitempty"`
Unidiff *bool `url:"unidiff,omitempty" json:"unidiff,omitempty"`
}

// Compare compares branches, tags or commits.
Expand Down

0 comments on commit d3e39bd

Please sign in to comment.