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

Adds Parent property to the repo API #1687

Merged

Conversation

guyzmo
Copy link
Contributor

@guyzmo guyzmo commented May 5, 2017

hop! 👍

cf gogs/go-gogs-client#64

@lafriks
Copy link
Member

lafriks commented May 5, 2017

@guyzmo you need to create PR to https://github.com/go-gitea/go-sdk to add required field

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 5, 2017
@guyzmo
Copy link
Contributor Author

guyzmo commented May 5, 2017

done

@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch from 93beb0f to 9d5ce90 Compare May 5, 2017 21:19
@guyzmo guyzmo changed the title Adds ForkID property to the repo API Adds Parent property to the repo API May 5, 2017
@guyzmo
Copy link
Contributor Author

guyzmo commented May 5, 2017

I just changed the content, to expose Repository* BaseRepo as 'parent' property, instead of an id. because that's more restful.

@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch from 9d5ce90 to e879a31 Compare May 5, 2017 21:45
@guyzmo
Copy link
Contributor Author

guyzmo commented May 5, 2017

cf github API, the parent is a full object. The only difference is that the parent does not contain its own parent in the project's tree (to avoid blowing up the connection). Also there's a source attribute, that contain the upmost parent project of the tree.

I guess that we can start iteratively, and give the parent property as it is currently implemented, at the risk of blowing the connection in case the project tree's branch is huge. Then in a second stage, hack the parent property so that it does not contain itself another parent property, or at least is set to null (and thus fork=true + parent=null means that there's more).

@lafriks
Copy link
Member

lafriks commented May 5, 2017

This code will panic when BaseRepo is nil. Also I'm not quite sure if BaseRepo will be have value at all before GetBaseRepo is called

@lunny lunny added this to the 1.2.0 milestone May 6, 2017
@lunny lunny added modifies/api This PR adds API routes or modifies them type/enhancement An improvement of existing functionality labels May 6, 2017
@guyzmo
Copy link
Contributor Author

guyzmo commented May 6, 2017

👌, so we need the code to keep calm when BaseRepo is nil. How?
And also we need to make sure that BaseRepo is valued when the API needs it. How?

I don't know the code base enough to tell how to hack that, so any pointers are welcomed ☺

@lunny
Copy link
Member

lunny commented May 6, 2017

@guyzmo first at all, you should use govendor update code.gitea.io/sdk to update the dependency.

@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch 3 times, most recently from 2541322 to 683316b Compare May 6, 2017 16:19
@lafriks
Copy link
Member

lafriks commented May 7, 2017

Now that dependency is set correctly you can see that unit tests is failing where BaseRepo is nil

@guyzmo
Copy link
Contributor Author

guyzmo commented May 7, 2017

So what can be done, how can we make sure it's 👌 when the pointer is nil and also that a tentative is made to resolve the parent when not?

@lafriks
Copy link
Member

lafriks commented May 7, 2017

you need to move out assignment up something like:

var parent *api.Repository
if repo.BaseRepo != nil {
    parent = repo.BaseRepo.APIFormat(AccessModeNone)
}

@guyzmo
Copy link
Contributor Author

guyzmo commented May 7, 2017

and to make sure the repo.BaseRepo contains something?

@lafriks
Copy link
Member

lafriks commented May 8, 2017

Then just assign Parent: parent,

@lafriks
Copy link
Member

lafriks commented May 8, 2017

If you meant to actually load BaseRepo than it should be done outside APIFormat in function from where APIFormat is called

@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch from 683316b to 7565d77 Compare May 8, 2017 15:49
@guyzmo
Copy link
Contributor Author

guyzmo commented May 8, 2017

ok, I've tried something to force load the BaseRepo. The build is failing, but it doesn't look like related to that code I wrote, but I might be wrong.

@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch from 7565d77 to fb60313 Compare May 8, 2017 20:15
models/repo.go Outdated
log.Error(4, "GetRepositoryByID[%d]: %v", id, err)
}
if repo.BaseRepo != nil {
parent := repo.BaseRepo.APIFormat(AccessModeNone)
Copy link
Member

Choose a reason for hiding this comment

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

it must be parent = repo.BaseRepo...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and I guess parent := nil as well. My bad! 👍

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 9, 2017
@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch 7 times, most recently from 4cf7027 to 5567d85 Compare May 9, 2017 20:52
models/repo.go Outdated
cloneLink := repo.CloneLink()
permission := &api.Permission{
Admin: mode >= AccessModeAdmin,
Push: mode >= AccessModeWrite,
Pull: mode >= AccessModeRead,
}
err := repo.GetBaseRepo()
Copy link
Member

@lafriks lafriks May 10, 2017

Choose a reason for hiding this comment

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

if isParent is true no need to try to call GetBaseRepo as it's result will not be used anyway

Copy link
Member

Choose a reason for hiding this comment

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

True :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌

models/repo.go Outdated
cloneLink := repo.CloneLink()
permission := &api.Permission{
Admin: mode >= AccessModeAdmin,
Push: mode >= AccessModeWrite,
Pull: mode >= AccessModeRead,
}
err := repo.GetBaseRepo()
if err != nil {
log.Error(4, "APIFormat issue: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

just "APIFormat: %v", err ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌

@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch 2 times, most recently from 25875cf to 7f67717 Compare May 10, 2017 12:15
@bkcsoft
Copy link
Member

bkcsoft commented May 10, 2017

now it's LGTM 🎉

@lafriks
Copy link
Member

lafriks commented May 10, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 10, 2017
models/repo.go Outdated
@@ -272,12 +272,26 @@ func (repo *Repository) APIURL() string {

// APIFormat converts a Repository to api.Repository
func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
return repo.innerAPIFormat(mode, false)
}
func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repository {
Copy link
Member

Choose a reason for hiding this comment

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

blank line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 👌

Signed-off-by: Guyzmo <guyzmo+github+pub@m0g.net>
@guyzmo guyzmo force-pushed the feature/api_exposes_forkid_property branch from 7f67717 to a541d73 Compare May 11, 2017 07:40
@lunny
Copy link
Member

lunny commented May 12, 2017

let L-G-T-M work

@appleboy appleboy merged commit 397474e into go-gitea:master May 12, 2017
sapk added a commit to sapk-fork/gitea that referenced this pull request May 14, 2017
@sapk sapk mentioned this pull request May 14, 2017
appleboy pushed a commit that referenced this pull request May 14, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants