Skip to content

initial support for gitea #148

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

Closed
wants to merge 2 commits into from
Closed

initial support for gitea #148

wants to merge 2 commits into from

Conversation

malarinv
Copy link
Contributor

@malarinv malarinv commented Mar 23, 2022

Signed-off-by: Malar Kannan [email protected]

Description

Enable support for gitea provider
fixes #147

Test results

TEST_PATTERN=./gitea make test
go mod tidy
go fmt ./...
go vet ./...
go test   -race -coverprofile=coverage.txt -covermode=atomic ./gitea
ok      github.com/fluxcd/go-git-providers/gitea        7.804s  coverage: 41.8% of statements

Signed-off-by: Malar Kannan <[email protected]>
return nil, fmt.Errorf("no files added")
}

// TODO: fix workaround
Copy link
Contributor Author

Choose a reason for hiding this comment

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

awaiting upstream fix go-gitea/gitea#14619

Copy link
Member

@souleb souleb left a comment

Choose a reason for hiding this comment

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

thanks @malarinv for this contribution 🙏 and sorry for the delay before starting the review. This will need several pass, and I understood that you still have to add the pagination code right?

return c.c
}

func (c *giteaClientImpl) GetOrg(ctx context.Context, orgName string) (*gitea.Organization, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add comments to exported objects.

@malarinv
Copy link
Contributor Author

malarinv commented Apr 5, 2022

thanks @malarinv for this contribution 🙏 and sorry for the delay before starting the review. This will need several pass, and I understood that you still have to add the pagination code right?

@souleb Thanks for the review. This is more of a learning exercise for me, so not in any hurry. Do note that this is my first time ever attempt at writing go code. so feel free to review it under a microscope 🙂. I will go over your review comments and revert with more changes, soon.

@malarinv
Copy link
Contributor Author

thanks @malarinv for this contribution pray and sorry for the delay before starting the review. This will need several pass, and I understood that you still have to add the pagination code right?

@souleb added pagination as well now.

2. underscored unused args
3. commented exported api
4. enabled custom domain auth_test cases
5. typo, unuse var fixes
6. pagination support and bugfixes

Signed-off-by: Malar Kannan <[email protected]>
// operating on the gitea structs. TODO: Verify pagination is implemented for all List* methods,
// all returned objects are validated, and HTTP errors are handled/wrapped using handleHTTPError.
// This interface is also fakeable, in order to unit-test the client.
type giteaClient interface {
Copy link
Member

@souleb souleb Apr 25, 2022

Choose a reason for hiding this comment

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

We are lucky no one rely on this interface yet. Normally I wouldn't advise for such a large interface, in GO you should try to keep interfaces small, and composable. I get it you want to keep existing code structure, nevertheless, please modify the functions structures as needed (e.g. some of them don't need context.Context parameters)

Comment on lines +148 to +163
teamFound := false
for _, team := range teams {
if team.Name != teamName {
continue
}
teamFound = true
users, _, err := c.c.ListTeamMembers(team.ID, gitea.ListTeamMembersOptions{})
if err != nil {
continue
}
apiObjs = append(apiObjs, users...)
}
if teamFound {
return apiObjs, nil
}
return nil, gitprovider.ErrNotFound
Copy link
Member

Choose a reason for hiding this comment

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

As we expect only one team with the same, we should exit early after retrieving the team. We could do something like:

for _, team := range teams {
  if team.Name == teamName {
    users, _, err := c.c.ListTeamMembers(team.ID, gitea.ListTeamMembersOptions{})
    if err != nil {
	return nil, fmt.Errorf("failed to list team %s members: %w", teamName, err)
    }
    return users, nil
}
return nil, gitprovider.ErrNotFound

// Client returns the underlying *gitea.Client
Client() *gitea.Client

// GetOrg is a wrapper for "GET /orgs/{org}".
Copy link
Member

Choose a reason for hiding this comment

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

The api endpoint is implementation specific in my opinion, so I would see this as a comment for the implementing function.

if err != nil {
return handleHTTPError(resp, err)
}
if resp == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why not check resp.NextPage?

if resp == nil {
return nil
}
opts.Page += 1
Copy link
Member

Choose a reason for hiding this comment

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

I would increment by resp.NextPage, because it is not guaranteed that each response contains only 1 page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean? there is no resp.NextPage in the gitea resp object.

return &apiObj.Permission, nil
}

func (c *giteaClientImpl) ListRepoTeams(ctx context.Context, orgName, repo string) ([]*gitea.Team, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we use GetRepoTeams() here?

@souleb souleb self-requested a review April 26, 2022 14:38
@makkes
Copy link
Member

makkes commented Oct 14, 2022

@malarinv Are you still interested in updating the PR to get it merged?

@malarinv
Copy link
Contributor Author

@malarinv Are you still interested in updating the PR to get it merged?

Hi @makkes , sure! I'll continue to be AFK for the next couple weeks. will revert back with changes then.

@souleb souleb mentioned this pull request Jun 5, 2023
@souleb souleb closed this Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gitea Support
3 participants