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

Notify about recent pushes if a branch has no PR yet #14003

Closed
wants to merge 36 commits into from

Conversation

kolaente
Copy link
Member

@kolaente kolaente commented Dec 15, 2020

This PR adds a nice little message on the dashboard if the current user recently pushed to a branch which has no PR open yet, with a link to do so. If the user recently pushed to a fork, it will show a message as well, but the link will go to create a PR with the upstream repository instead.

This PR explicitly does not show a link to existing PRs after pushes to a branch to keep it simple.

Screenshots

image

image

image

image

image

TODO

  • Make sure it is working for both pushes to a new branch on the same repo and on a fork
  • Actually show the message on the dashboard
  • Hide pushes to the default branch since it does not make sense to create PRs for that unless the push was made to a forked repo
  • Include the time when the push happened in the message
  • Add a screenshot here

Resolves #311, resolves #13196, resolves #23743

@CirnoT
Copy link
Contributor

CirnoT commented Dec 17, 2020

I'm worried it might be too cluttered when more than few message are displayed (especially with rather long time limit). How about moving it to repo page similar to how GH does it?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 17, 2020
@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Dec 18, 2020
@lunny
Copy link
Member

lunny commented Dec 18, 2020

How about display it in the repository home page but not user's dashboard page. Once the user push to serval repositories, which one should we display?

@kolaente
Copy link
Member Author

I'm worried it might be too cluttered when more than few message are displayed (especially with rather long time limit). How about moving it to repo page similar to how GH does it?

@CirnoT I think this could be addressed with either a shorter time limit or limiting the max messages to 2 or 4 (or both)

I think github shows it on both the repo page and the dashboard. IIRC gitlab does that as well.

@lunny
Copy link
Member

lunny commented Mar 29, 2023

Fix #23743

@kolaente
Copy link
Member Author

Would there be interest in picking this PR up again?

@lunny
Copy link
Member

lunny commented Mar 29, 2023

Maybe it should be on top of the repository home page but not dashboard?

@delvh
Copy link
Member

delvh commented Mar 29, 2023

The interest is definitely there, but I wonder if it wouldn't make more sense to create a new branch, one to resolve all conflicts that happened in the mean time, and two to give it the attention boost of a new PR?

@kolaente
Copy link
Member Author

@delvh Probably. Should I do that or wants someone else pick it up?

Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

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

I think it makes sense if you publish the new PR as you're also the author of this one.

Below you find some more things I just noticed.

@@ -1381,6 +1381,8 @@ pulls.merge_instruction_hint = `You can also view <a class="show-instruction">co
pulls.merge_instruction_step1_desc = From your project repository, check out a new branch and test the changes.
pulls.merge_instruction_step2_desc = Merge the changes and update on Gitea.

pulls.recently_pushed_to_branches = You recently pushed to <strong>%[1]s/%[2]s</strong> on branch <strong>%[3]s</strong>
Copy link
Member

Choose a reason for hiding this comment

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

According to @lunny's suggestion above, this message should then be renamed.

models/action.go Outdated Show resolved Hide resolved
templates/user/recently_pushed_branches.tmpl Outdated Show resolved Hide resolved
models/action.go Outdated Show resolved Hide resolved
@silverwind
Copy link
Member

silverwind commented Apr 7, 2023

And that's why GitLab dropped other database support, only supports one database -- it's difficult to fine-tune a large dataset on different databases.

That is my impression as well. Single database allows many optimizations and features that just are not possible with multi-database. We might consider it if we can provide migrations, but I think that won't be so easy.

@CirnoT
Copy link
Contributor

CirnoT commented Apr 7, 2023

Also on unrelated note, that query returns for quite weird results:

gitea=# SELECT action.ref_name, action.repo_id, action.created_unix FROM "action" LEFT JOIN "pull_request" ON pull_request.head_branch = replace(action.ref_name, 'refs/heads/', '') LEFT JOIN "issue" ON pull_request.issue_id = issue.id LEFT JOIN "repository" ON action.repo_id = repository.id WHERE action.op_type=5 AND action.act_user_id=32 AND ((repository.default_branch != replace(action.ref_name, 'refs/heads/', '')) OR repository.is_fork=TRUE) AND (pull_request.id IS NULL OR (pull_request.has_merged=FALSE AND issue.is_closed=TRUE AND (action.created_unix > issue.closed_unix))) AND action.created_unix>=1680362902 GROUP BY action.ref_name, action.repo_id, action.created_unix ORDER BY "action"."created_unix" DESC;
               ref_name               | repo_id | created_unix 
--------------------------------------+---------+--------------
 refs/heads/renovate/phpstan-monorepo |       1 |   1680460273
 refs/heads/renovate/phpstan-monorepo |       1 |   1680460272
 refs/heads/renovate/phpstan-monorepo |      13 |   1680460072
 refs/heads/renovate/webpack-5.x      |       6 |   1680459707
 refs/heads/renovate/phpstan-monorepo |       1 |   1680456696
 refs/heads/renovate/phpstan-monorepo |      13 |   1680456540
 refs/heads/renovate/phpstan-monorepo |       9 |   1680456286
 refs/heads/renovate/phpstan-monorepo |       9 |   1680456285

These branches do not exist, Multiple PRs for them exists but they are either merged or closed (unmerged).

@lunny
Copy link
Member

lunny commented Apr 8, 2023

I think the performance problem could be partially resolved by this approach:

1. Only do a simple select query in action table (no JOIN). Since we only need the recent 2 hour activity record, and action table has indices, the performance should be good enough.

2. Then, use other queries to gather more details.

@lunny what do you think about this?

I think we could also do some optimization at the moment but those are temporary methods. As I said, once branches have been synced into databases, this PR could be implemented very easily. Assume we have a new table branch with an index repo_id and updated timestamp. We can easily get recently updated branch names of this repository or all the branches in this instance. No complex SQL, no Joins.

@silverwind
Copy link
Member

silverwind commented Apr 8, 2023

We could on branch push push all pushed branches into a per-user append-only data structure where values would automatically expire after the 2 hour time period (like redis EXPIRE command).

Then, when rendering, the operation is just a simple retrieval of that list with some filtering for cases where branch was deleted or has an associated PR. The only thing I'm not sure about if auto-expiring keys can be done with SQL, or if that would require a cache like redis.

@yardenshoham
Copy link
Member

I think GitHub keeps it out of the initial page render. Maybe it can be done in the background with an API call and render the suggestion only when ready?

@silverwind
Copy link
Member

silverwind commented Apr 8, 2023

Yeah, it is definitely async on GitHub which causes ugly JS pop-in. If we can find a performant synchronous solution it would be ideal.

@kolaente
Copy link
Member Author

Thanks everyone for your investigations and queries. My goal was to use existing data structures to avoid a higher overhead for such a simple feature. Well, looks like this is not as simple as I thought.

I think we could also do some optimization at the moment but those are temporary methods. As I said, once branches have been synced into databases, this PR could be implemented very easily. Assume we have a new table branch with an index repo_id and updated timestamp. We can easily get recently updated branch names of this repository or all the branches in this instance. No complex SQL, no Joins.

Should this PR be blocked and reworked when the other one got merged?

@yardenshoham
Copy link
Member

@yardenshoham yardenshoham added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Apr 10, 2023
@yardenshoham yardenshoham self-requested a review May 10, 2023 12:18
@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels May 10, 2023
@GiteaBot GiteaBot removed this from the 1.20.0 milestone May 23, 2023
@yardenshoham
Copy link
Member

@techknowlogick why?

@yardenshoham yardenshoham reopened this May 23, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 23, 2023
@techknowlogick
Copy link
Member

@yardenshoham caught up in a PR cleanup sweep, thanks for re-opening :)

@wxiaoguang
Copy link
Contributor

I think maybe this PR could be taken in 1.20 if no objection for "only querying recent N hours actions records by a single/simple SELECT" ?

  • If the query range is limited by time and the query is simple, it doesn't seem to cause server side load problem?

@silverwind
Copy link
Member

silverwind commented May 29, 2023

Yes, and ideally only show notification on the repo page. Not on the frontpage.

Oh, and it needs to filter out branches that have a associated PR, haven't checked if it already does that.

@lunny
Copy link
Member

lunny commented Jun 30, 2023

Since #22743 merged, I think this could be continued now.

@yardenshoham yardenshoham removed the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Jun 30, 2023
@silverwind
Copy link
Member

As already mentioned, I would like to see this changed to only show on the repo page as it would be too annoying on the frontpage.

@kolaente
Copy link
Member Author

kolaente commented Jul 5, 2023

I don't really have time to implement this in the next few weeks, so if anyone wants to pick it up, feel free. Otherwise I'll take a stab at it at the end of August / early September.

6543 pushed a commit that referenced this pull request Jul 8, 2023
This PR will display a pull request creation hint on the repository home
page when there are newly created branches with no pull request. Only
the recent 6 hours and 2 updated branches will be displayed.

Inspired by #14003 
Replace #14003 
Resolves #311
Resolves #13196
Resolves #23743

co-authored by @kolaente
@6543
Copy link
Member

6543 commented Jul 8, 2023

#25715

@6543 6543 closed this Jul 8, 2023
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Oct 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet