Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Add endpoint to lists invited groups of a project #2000

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,35 @@ func (s *ProjectsService) DeleteProject(pid interface{}, options ...RequestOptio
return s.client.Do(req, nil)
}

// ListProjectInvidedGroupOptions represents the available ListProjectsInvitedGroups() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#list-a-projects-invited-groups
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep comments below 80 chars:

Suggested change
// ListProjectInvidedGroupOptions represents the available ListProjectsInvitedGroups() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#list-a-projects-invited-groups
// ListProjectInvidedGroupOptions represents the available
// ListProjectsInvitedGroups() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/projects.html#list-a-projects-invited-groups

type ListProjectInvidedGroupOptions struct {
ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"`
SharedMinAccessLevel *AccessLevelValue `url:"shared_min_access_level,omitempty" json:"shared_min_access_level,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs this should be MinAccessLevel (min_access_level).

Relation []string `url:"relation,omitempty" json:"relation,omitempty"`
WithCustomAttributes bool `url:"with_custom_attributes,omitempty" json:"with_custom_attributes,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to be pointers and it seems this code is not formatted properly:

Suggested change
Relation []string `url:"relation,omitempty" json:"relation,omitempty"`
WithCustomAttributes bool `url:"with_custom_attributes,omitempty" json:"with_custom_attributes,omitempty"`
Relation *[]string `url:"relation,omitempty" json:"relation,omitempty"`
WithCustomAttributes *bool `url:"with_custom_attributes,omitempty" json:"with_custom_attributes,omitempty"`

}

// ListProjectsInvitedGroups lists invited groups of a project
//
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#list-a-projects-invited-groups
func (s *ProjectsService) ListProjectsInvitedGroups(pid interface{}, opt *ListProjectInvidedGroupOptions, options ...RequestOptionFunc) (*Response, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should also return a *ProjectGroup instead of only the raw response.

project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/invited_groups", PathEscape(project))

req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, err
}

return s.client.Do(req, nil)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the ordering in the docs, this method should be placed between Star and Unstar.


// ShareWithGroupOptions represents options to share project with groups
//
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#share-project-with-group
Expand Down
15 changes: 15 additions & 0 deletions projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ func TestListProjectForks(t *testing.T) {
}
}

func TestListProjectsInvitedGroups(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test like this doesn't actually test anything, so probably best to remove it.

mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/invited_groups", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
})

opt := &ListProjectInvidedGroupOptions{}

_, err := client.Projects.ListProjectsInvitedGroups(1, opt)
if err != nil {
t.Errorf("Projects.ListProjectsInvitedGroups returned error: %v", err)
}
}

func TestShareProjectWithGroup(t *testing.T) {
mux, client := setup(t)

Expand Down