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

migrations: remove dead code in gitea uploader #18725

Merged
merged 8 commits into from
Feb 21, 2022

Conversation

singuliere
Copy link
Contributor

When migrating, g.issues is a map with all issues created during the
migration. If an issue is not found in g.issues when inserting a
comment or a review, it cannot exist in the database and trying to get
it via GetIssueByIndex() will always fail and return an error.

@singuliere singuliere added type/refactoring Existing code has been cleaned up. There should be no new functionality. topic/repo-migration Migrate repos from other platforms to Gitea, or from Gitea to them labels Feb 11, 2022
@singuliere singuliere added this to the 1.17.0 milestone Feb 11, 2022
@singuliere singuliere force-pushed the wip-gitea-uploader branch 2 times, most recently from 05a9c35 to 1d7c447 Compare February 11, 2022 15:48
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 11, 2022

I think g.issues is used as a cache. If we want to support incremental migration, then we need these code.

Personally I prefer to leave it as it was

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 11, 2022
@singuliere
Copy link
Contributor Author

It is dead code because there is no codepath that leads to it. There is no test that exist or could be written that would lead to these lines. If incremental migrations do not require modifying the migrateRepository functions, issues are handled first and the cache is populated in full. If incremental migrations use a logic different from migrateRepository the Gitea uploader will need to be refactored entirely. Or something else implemented from scratch. I can't imagine a single scenario where this dead code comes back to life. Can you?

When migrating, g.issues is a map with all issues created during the
migration. If an issue is not found in g.issues when inserting a
comment or a review, it cannot exist in the database and trying to get
it via GetIssueByIndex() will always fail and return an error.

Signed-off-by: singuliere <singuliere@autistici.org>
Copy link
Member

@lunny lunny left a comment

Choose a reason for hiding this comment

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

This is totally wrong. CreateIssues and CreateComments maybe invoked

@GiteaBot GiteaBot 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 Feb 11, 2022
@zeripath
Copy link
Contributor

It may be helpful to add a warning to the top of the functions involved stating that all of the issues need to be created before this is called occurs.

The code paths here are somewhat convoluted and complex (likely necessarily so) but we need to be clearer in the comments about what each function is expecting to have already happened.

I can easily imagine some new API coming out whereby people get the issue and all of its comments in one go - the refs would then probably break

@singuliere
Copy link
Contributor Author

This is totally wrong. CreateIssues and CreateComments maybe invoked

I'm confused about what is wrong. Could you please explain? Is the proposed change wrong? Or am I wrong in thinking that the gitea uploader CreateComments function is only called from the migrateRepository function?

@singuliere
Copy link
Contributor Author

It may be helpful to add a warning to the top of the functions involved stating that all of the issues need to be created before this is called occurs.

The code paths here are somewhat convoluted and complex (likely necessarily so) but we need to be clearer in the comments about what each function is expecting to have already happened.

I can easily imagine some new API coming out whereby people get the issue and all of its comments in one go - the refs would then probably break

The only thing I was able to come up with is the following:

//
// The migrateRepository function determines the context in which this method is invoked.
// It relies on other methods being called first, to populate caches, update the git
// repository, etc. If it was to be called independently, care must be taken to fulfill
// its expectations.
//
// CreateReviews create pull request reviews
func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {

This is very vague and not useful, I'm afraid. I can't figure out how to be more specific without being so specific that the comment will likely become obsolete as soon as the slightest change is introduced in the logic. For instance at the moment it relies on CreatePullRequests updating the git repository to create references to pull requests and, if there is a fork, fetching the commits from the fork into the repository.

Do you have a suggestion?

@Gusted
Copy link
Contributor

Gusted commented Feb 12, 2022

Do you have a suggestion?

- // CreateReviews create pull request reviews
+ // CreateReviews create pull request reviews of currently migrated issues

The CreateIssues is already called before hand which already inserts the issues into g.issues, so something along the lines of currently imported issues or currently known issues, no need to go big, otherwise the code should be self-explanatory.

@singuliere
Copy link
Contributor Author

Do you have a suggestion?

- // CreateReviews create pull request reviews
+ // CreateReviews create pull request reviews of currently migrated issues

The CreateIssues is already called before hand which already inserts the issues into g.issues, so something along the lines of currently imported issues or currently known issues, no need to go big, otherwise the code should be self-explanatory.

That makes perfect sense, thanks for the advice. I added a commit with your suggestion 👍

@GiteaBot GiteaBot 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 Feb 15, 2022
@singuliere
Copy link
Contributor Author

The CI is stuck with:

Initialized empty Git repository in /drone/src/.git/

+ git fetch origin +refs/heads/main:

@6543 6543 merged commit 54dd0fc into go-gitea:main Feb 21, 2022
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 22, 2022
* giteaofficial/main:
  Fix bug for get user by email (go-gitea#18833)
  migrations: remove dead code in gitea uploader (go-gitea#18725)
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
When migrating, g.issues is a map with all issues created during the
migration. If an issue is not found in g.issues when inserting a
comment or a review, it cannot exist in the database and trying to get
it via GetIssueByIndex() will always fail and return an error.

Signed-off-by: singuliere <singuliere@autistici.org>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
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. topic/repo-migration Migrate repos from other platforms to Gitea, or from Gitea to them type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants