gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Fix wrong display of recently pushed notification

Open yp05327 opened this issue 2 years ago • 39 comments

There's a bug in #25715: If user pushed a commit into another repo with same branch name, the no-related repo will display the recently pushed notification incorrectly. It is simple to fix this, we should match the repo id in the sql query.

image The latest commit is 2 weeks ago. image

The notification comes from another repo with same branch name: image

After: In forked repo: image New PR Link will redirect to the original repo: image In the original repo: image New PR Link: image

In the same repo: image New PR Link: image

08/15 Update: Follow #26257, added permission check and logic fix mentioned in https://github.com/go-gitea/gitea/pull/26257#discussion_r1294085203

2024/04/25 Update: Fix #30611

yp05327 avatar Jul 10 '23 08:07 yp05327

duplicated with #25795

lunny avatar Jul 10 '23 08:07 lunny

It does sound like it solves a different issue.

silverwind avatar Jul 10 '23 09:07 silverwind

Have no enough time to test this PR, I will test it later.

yp05327 avatar Jul 10 '23 09:07 yp05327

#25795 not looks good to me. It is not good to detect branch by name, as we may have same branch names in different repos. Instead, I used latest commit id, then you can also avoid display notification from both no-change branch in forked repo and the original repo.

Added some screenshots to the pr description.

yp05327 avatar Jul 11 '23 01:07 yp05327

We can add a test for this new feature later. Maybe not in this PR, it is not easy to do this, as we need to make many changes in db and git data.

yp05327 avatar Jul 11 '23 05:07 yp05327

This PR will not fix merged PR, as it will be fixed in #25810

yp05327 avatar Jul 11 '23 07:07 yp05327

There's a problem if we do not use branch id to link the head branch and the pull request. If we merged a PR, deleted the branch(ID:1) of that PR and created a new branch(ID:2) with the same name, we will never get the new PR notification, because when we search existing PR, the new created branch(ID:2) will be linked to the merged PR, and it will be excepted. 🤔

And the pull branch link in this PR will direct to the existing branch(ID:2) not the deleted branch(ID:1). 🤔 And the delete branch button will enable again image

yp05327 avatar Jul 13 '23 06:07 yp05327

Any tests possible?

silverwind avatar Jul 14 '23 09:07 silverwind

Any tests possible?

I think an unit test is possible.

yp05327 avatar Jul 20 '23 02:07 yp05327

I'm coding the test, and notice that maybe we need to check the repo access permission here, but not sure about this now. Maybe user can get new branches notification from no accessible repo, as the repoCond does not look good. So I change the PR status to draft now.

yp05327 avatar Jul 20 '23 08:07 yp05327

Ready for review.

yp05327 avatar Jul 31 '23 02:07 yp05327

Found a new problem: If user A fork a repo which have a recently commit pushed by user B, user A will see the notification immediately, as branch.pusher will be exchanged to user A, but actually it is committed by user B.

@lunny So what is the definition of branch.pusher?

yp05327 avatar Aug 15 '23 01:08 yp05327

Found a new problem: If user A fork a repo which have a recently commit pushed by user B, user A will see the notification immediately, as branch.pusher will be exchanged to user A, but actually it is committed by user B.

@lunny So what is the definition of branch.pusher?

Pusher is a user which have registered in this Gitea instance which is different from committer. Git Committer maybe not a user of this instance. i.e. I pushed git kernel to my Gitea instance. I'm the pusher, but I haven't committed any commit to this repository.

lunny avatar Aug 15 '23 02:08 lunny

Pusher is a user which have registered in this Gitea instance which is different from committer. Git Committer maybe not a user of this instance. i.e. I pushed git kernel to my Gitea instance. I'm the pusher, but I haven't committed any commit to this repository.

I see. I tried this in GitHub, and got the same result. So this is not a problem any more. 😄 But GitHub will only fork main branch by default, then user will not see the notification by default.

yp05327 avatar Aug 15 '23 05:08 yp05327

Is it ready?

silverwind avatar Aug 20 '23 15:08 silverwind

Is it ready?

Yes.

yp05327 avatar Aug 21 '23 04:08 yp05327

The question in my mind is: could the existing test fixtures be reused for testing?

I am not a fan of adding a lot of new fixtures for each new feature, otherwise, years later, there would be hundreds or thousands of git repositories for testing? Then would any one can tell their usage or is is possible to maintain them?

wxiaoguang avatar Aug 22 '23 09:08 wxiaoguang

Of course it is better to reuse the existing fixtures in some simple tests. At first, I did this. But I found that for a complex test, reusing them will break lots of tests and become a hard work. I cannot say that this will bring us more benefits in maintenance as we need to take much more time in the loop of fixing the broken tests (maybe more newly broken tests appear during the fixing).

If you really want to reuse them, I think removing test codes in this PR and do that in another one maybe better, as this work will take too much time in coding and reviewing. How about you.

yp05327 avatar Aug 23 '23 01:08 yp05327

But I found that for a complex test, reusing them will break lots of tests and become a hard work.

How does it break? Each test uses the original fixtures, everything is reset.

wxiaoguang avatar Aug 23 '23 01:08 wxiaoguang

For example: There's a repo A which seems that can be reused in your new test. And you decided to reuse it. You finished your new test, and it worked well. So you pushed the codes, but got lots of CI failures. Then you checked logs, and noticed that repo A can not be reused in your new test as there are several tests you didn't notice at the beginning are using repo A and your changes will cause conflicts in the end. For example, you can not change something related to repo A as the existing test A will check them, but you have to because you need these changes in your new test. Then you rewrite the codes and try to reuse repo B. But after taking several hours to finish your work, you notice that repo B can also not be reused for the same reason. Then this will bring you into a loop of deciding which one to reuse, finishing your codes, and resolving the conflicts.

yp05327 avatar Aug 23 '23 04:08 yp05327

CI failure seems related

    api_org_test.go:94: 
        	Error Trace:	/home/runner/work/gitea/gitea/tests/integration/api_org_test.go:94
        	            				/home/runner/work/gitea/gitea/tests/integration/git_helper_for_declarative_test.go:87
        	            				/home/runner/work/gitea/gitea/tests/integration/api_org_test.go:28
        	Error:      	"[%!s(*structs.User=&{1 user1 user1 User One [email protected] https://secure.gravatar.com/avatar/111d68d06e2d317b5a59c2c6c5bad808?d=identicon en-US true {0 63828797734 <nil>} {0 62135596800 <nil>} false true false    public 0 0 0}) %!s(*structs.User=&{12 user12 user12 User 12 [email protected] https://secure.gravatar.com/avatar/ef1debc1364806281c42eeedfdeb943b?d=identicon  false {0 62135596800 <nil>} {0 62135596800 <nil>} false true false    public 0 0 0})]" should have 1 item(s), but has 2
        	Test:       	TestAPIOrgCreate

wxiaoguang avatar Aug 28 '23 07:08 wxiaoguang

No CI failures now.

yp05327 avatar Aug 28 '23 08:08 yp05327

As this PR has changed a lot, I think it should be reviewed again.

yp05327 avatar Aug 28 '23 08:08 yp05327

Forgot this one. Need to fix the conflicts first. 😕 image

yp05327 avatar Nov 10 '23 02:11 yp05327

conflicts and test errors are all resolved.

yp05327 avatar Nov 17 '23 02:11 yp05327

Fixing conflicts is too terrible. Can someone help me to review this PR. 😭

yp05327 avatar Nov 24 '23 05:11 yp05327

Please resolve the conflicts.

lunny avatar Jan 24 '24 03:01 lunny

Please resolve the conflicts.

Done.

yp05327 avatar Jan 26 '24 06:01 yp05327

image image 😕

yp05327 avatar May 08 '24 06:05 yp05327

Which one is correct?

yp05327 avatar May 08 '24 06:05 yp05327