Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to list custom roles for organizations #2327

Closed
btsteve opened this issue Apr 7, 2022 · 14 comments · Fixed by #2336
Closed

Need a way to list custom roles for organizations #2327

btsteve opened this issue Apr 7, 2022 · 14 comments · Fixed by #2336

Comments

@btsteve
Copy link

btsteve commented Apr 7, 2022

It would be great to have a way to list custom roles create in an organization.

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 7, 2022

Can the GitHub v3 API do that?
If so, this repo (which is a Go client for the GitHub v3 API) should be able to.

Are you talking about this?
https://docs.github.com/en/rest/reference/orgs#custom-repository-roles

If so, yes. Would you like to submit a PR, or would you like me to open this issue up to any of our contributors to work on?

@btsteve
Copy link
Author

btsteve commented Apr 7, 2022

Yes that is what i am talking about. I don't think i know enough go to add it.

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 7, 2022

Yes that is what i am talking about. I don't think i know enough go to add it.

No problem, thank you, @btsteve , for the report.

This would be a great PR for any new contributor to this repo or a new Go developer.
All contributions are greatly appreciated!

Feel free to volunteer for any issue and the issue can be assigned to you so that others don't attempt to duplicate the work.

Please check out our CONTRIBUTING.md guide to get started. (In particular, please remember to go generate ./... and don't use force-push to your PRs.)

Thank you!

@tamboliasir1
Copy link
Contributor

Hi @gmlewis I'm new contributor. Can you give me little bit of insights like from where can I start and what should I know to get it right. Thanks.

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 8, 2022

Hi @gmlewis I'm new contributor. Can you give me little bit of insights like from where can I start and what should I know to get it right. Thanks.

Hi @tamboliasir1 , and welcome to this repo. 😄

We try as much as possible to make this repo welcoming to new contributors, and as such, we have attempted to document valuable information in our CONTRIBUTING.md guide... if you feel there are any omissions or corrections needed, PRs are welcome. 😄

As for this specific issue, and whenever implementing new endpoints, it is a great idea to browse around, both in the code, and also in past (successfully closed) PRs, to see how new features like this have been added, and base your solution on well-known and working past solutions.

If you still have questions after that, please try to be as specific as possible, and I will attempt to help out.
Best wishes to you, and thank you in advance for your contributions!

@tamboliasir1
Copy link
Contributor

tamboliasir1 commented Apr 8, 2022

Got it.. Thank you @gmlewis I would love to give it a try.. Can you please assign it to me?

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 8, 2022

Got it.. Thank you @gmlewis I would love to give it a try.. Can you please assign it to me?

Awesome, @tamboliasir1 ! It is yours. 😄

@tamboliasir1
Copy link
Contributor

Hi @gmlewis Please correct me if my proposed solution is wrong

  1. I need to create new file org_custom_role.go
  2. Create new endpoint ListCustomRole
  3. Send request to /organizations/{organization_id}/custom_roles
  4. Return roles

@btsteve
Copy link
Author

btsteve commented Apr 10, 2022

For those of us following along at home does this look remotely close to the correct answer?
I am not sure how to test this locally.

package github

import (
	"context"
	"fmt"
)

type OrginizationCustomeRoles struct {
	TotalCount  int `json:"total_count"`
	CustomRoles []struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	} `json:"custom_roles"`
}

type CustomRolesListOptions struct {
	ListOptions
}

// List Custome Roles in Org
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#custom-repository-roles
func (s *OrganizationsService) ListCustomRole(ctx context.Context, org string, opts *CustomRolesListOptions) (*OrginizationCustomeRoles, *Response, error) {
	u := fmt.Sprintf("organizations/%v/custom_roles", org)
	u, err := addOptions(u, opts)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	// TODO: remove custom Accept header when this API fully launches.
	req.Header.Set("Accept", mediaTypeProjectsPreview)

	var custome_roles *OrginizationCustomeRoles
	resp, err := s.client.Do(ctx, req, &custome_roles)
	if err != nil {
		return nil, resp, err
	}

	return custome_roles, resp, nil
}

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 11, 2022

Hi @gmlewis Please correct me if my proposed solution is wrong

  1. I need to create new file org_custom_role.go
  2. Create new endpoint ListCustomRole
  3. Send request to /organizations/{organization_id}/custom_roles
  4. Return roles

That seems like a good plan, @tamboliasir1 - the only things I would change at this point, probably, are to make the "role" plural ("roles") both in step 1 and step 2 above.

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 11, 2022

For those of us following along at home does this look remotely close to the correct answer?

Thanks, @btsteve - that is a good start, but does have some minor issues. Let's allow @tamboliasir1 to put together a PR, and then we will do an actual code review on the PR, which is much easier than a code review on a discussion thread. 😄

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 11, 2022

That seems like a good plan, @tamboliasir1 - the only things I would change at this point, probably, are to make the "role" plural ("roles") both in step 1 and step 2 above.

@tamboliasir1 - note that I meant to mention that unit tests need to be added for every new endpoint, following the current pattern found in the repo.

@tamboliasir1
Copy link
Contributor

Sure @gmlewis Thanks for guidance. Will raise a PR soon.

@tamboliasir1
Copy link
Contributor

Hi @gmlewis I have raised a PR for the same. Can you please review the code. Thank you for this opportunity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants