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

Add commit comment when push to pull request branch #2548

Closed
wants to merge 14 commits into from

Conversation

lunny
Copy link
Member

@lunny lunny commented Sep 19, 2017

Fixes #2830

@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Sep 19, 2017
@lunny lunny added this to the 1.3.0 milestone Sep 19, 2017
@ethantkoenig
Copy link
Member

ethantkoenig commented Sep 19, 2017

Should these comments be removed on a force push (like in Github)?

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 19, 2017
@lunny
Copy link
Member Author

lunny commented Sep 19, 2017

@ethantkoenig yes, I think you are right. I will update this.

@lunny lunny added the pr/wip This PR is not ready for review label Sep 19, 2017
CommitSHA string `xorm:"VARCHAR(40)"`
CommitSHA string `xorm:"VARCHAR(40)"`
Link string `xorm:"VARCHAR(2048)"`
CommitStatus *CommitStatus `xorm:"-"`
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a migration for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

What's migration? We didn't change anything, the extra fields only for new comment type.

Copy link
Member

Choose a reason for hiding this comment

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

You added the Link column. Do we need a migration for syncing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently Link is only for the added comment type.

models/action.go Outdated
return fmt.Errorf("IssueList.LoadRepositories: %v", err)
}

for _, issue := range issues {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to store link to commit? I think we should generate it on the fly as it is internal url and will become invalid if user changes Gitea configuration

Copy link
Member Author

Choose a reason for hiding this comment

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

If we didn't save link before, then we have to read repo table to know the repo path for every comment. I don't think that's necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

The link is a relative link not an absolute link.

Copy link
Member

Choose a reason for hiding this comment

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

yes but it will include AppSubURL that can be changed in settings. Maybe save only issue.Repo.FullName() in link and create new method for comment type that depending on comment type would generate URL (in this case AppSubURL + "/" + comment.Link + "/commit/" + comment.Sha1).
Additional change needed is to update link column on user/org rename and repository rename

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

models/action.go Outdated
return fmt.Errorf("IssueList.LoadRepositories: %v", err)
}

for _, issue := range issues {
Copy link
Member

Choose a reason for hiding this comment

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

yes but it will include AppSubURL that can be changed in settings. Maybe save only issue.Repo.FullName() in link and create new method for comment type that depending on comment type would generate URL (in this case AppSubURL + "/" + comment.Link + "/commit/" + comment.Sha1).
Additional change needed is to update link column on user/org rename and repository rename

@lunny lunny changed the title Add commit comment when push to pull Add commit comment when push to pull request branch Sep 21, 2017
@lunny lunny force-pushed the lunny/add_commit_comment_pull branch 2 times, most recently from bace2ef to b543ab2 Compare September 22, 2017 06:16
@codecov-io
Copy link

codecov-io commented Sep 22, 2017

Codecov Report

Merging #2548 into master will decrease coverage by 0.22%.
The diff coverage is 1.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2548      +/-   ##
==========================================
- Coverage   26.85%   26.62%   -0.23%     
==========================================
  Files          89       89              
  Lines       17607    17774     +167     
==========================================
+ Hits         4728     4732       +4     
- Misses      12193    12354     +161     
- Partials      686      688       +2
Impacted Files Coverage Δ
models/pull.go 20.38% <ø> (ø) ⬆️
models/repo.go 13.03% <0%> (ø) ⬆️
models/status.go 3.4% <0%> (ø) ⬆️
models/issue_comment.go 23.35% <0%> (-7.25%) ⬇️
models/action.go 50.92% <8.82%> (-3.16%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cdc4600...ea4e6a0. Read the comment docs.

@lunny
Copy link
Member Author

lunny commented Sep 22, 2017

@ethantkoenig done.

@lunny lunny removed the pr/wip This PR is not ready for review label Sep 22, 2017
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
<img src="{{.Poster.RelAvatarLink}}">
</a>
<span class="text grey"><a href="{{AppSubUrl}}/{{.RepoFullName}}/commit/{{.CommitSHA}}">{{.Content | Str2html}}</a></span>
Copy link
Member

Choose a reason for hiding this comment

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

Please create method for Comment type to generate target URL and use it here and lower

models/action.go Outdated
var isForcePush = false
if !isNewBranch {
// detect force push
if git.EmptySHA != opts.Commits.Commits[0].Sha1 {
Copy link
Member

Choose a reason for hiding this comment

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

Can be simplified to if !isNewBranch && git.EmptySHA != opts.Commit.Commits[0].Sha1 {

@@ -683,6 +683,11 @@ func ViewIssue(ctx *context.Context) {
ctx.Handle(500, "LoadAssignees", err)
return
}
} else if comment.Type == models.CommentTypePullPushCommit {
Copy link
Member

Choose a reason for hiding this comment

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

Can we replace this if construct by a switch statement?

@@ -1,7 +1,7 @@
{{range .Issue.Comments}}
{{ $createdStr:= TimeSince .Created $.Lang }}

<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL -->
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL, 15 = CancelTracking, 16 = PullPushCommit -->
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep consistency either using camel case or upper case?

@@ -66,6 +66,7 @@ type PullRequest struct {
HeadBranch string
BaseBranch string
MergeBase string `xorm:"VARCHAR(40)"`
LastCommitID string `xorm:"VARCHAR(40)"`
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need LastCommitID? It is only used once in assignment.

Copy link
Member Author

Choose a reason for hiding this comment

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

@daviian #2519 will need it.

Copy link
Member Author

@lunny lunny Sep 23, 2017

Choose a reason for hiding this comment

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

It will help to show the pull's commit status. If we didn't cache it, we will spent many time to invoke git command on that PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ok thanks for clarification 👍

@lunny lunny force-pushed the lunny/add_commit_comment_pull branch from c646458 to 85b6cef Compare September 23, 2017 12:55
@lunny
Copy link
Member Author

lunny commented Sep 23, 2017

@daviian @lafriks done and rebased.

@lafriks
Copy link
Member

lafriks commented Sep 23, 2017

BTW what about updating full name when user/org is renamed or repository is renamed/transfered/deleted etc?

models/action.go Outdated
if err != nil {
return fmt.Errorf("rev-list: %v", err)
} else if len(output) > 0 {
isForcePush = true
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is right. Suppose I push 3 commits on top of a branch's current head (not a force push)

sha1 newest (my parent is sha2)
sha2 older (my parent is sha3)
sha3 even older (my parent is the previous head of the branch)

opts.Commits.Commits will contain sha1, sha2 and sha3, in that order. We will run git rev-list sha1 ^sha3, which will return sha1 and sha2, and this push will incorrectly be marked as a force push.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be this:
output, err := git.NewCommand("rev-list", opts.OldCommitID, "^"+opts.NewCommitID).RunInDir(repo.RepoPath())

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

models/action.go Outdated
}
}

for i := 0; i < len(opts.Commits.Commits); i++ {
Copy link
Member

Choose a reason for hiding this comment

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

nit: for _, c := range opts.Commits.Commits

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -571,6 +603,45 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
return err
}

// ClearPullPushComent clear all the push commit on issue since fore push
func ClearPullPushComent(issue *Issue) error {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this right. Suppose there are two commits that have previously been pushed to a PR:

sha1 newest (my parent is sha2)
sha2 older (my parent is something else)

Suppose sha1 is removed via a force push, but sha2 remains. sha2's comment should not be deleted. Even if we recreate it later, the new comment will have a different timestamp than the old deleted one, which affects the in order in which comments are listed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since it's a force push the old commit maybe changed also. We cannot detect that. And it seems github also always delete all previous commit comments.

Copy link
Member

@ethantkoenig ethantkoenig Oct 27, 2017

Choose a reason for hiding this comment

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

We can detect it. The commits whose comments need to be deleted are exactly the commits listed in the output from the git rev-list ... command.

Also, from what I can tell Github does not delete unaffected commit comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ethantkoenig could you give me some example pull request on github the commit comments are not deleted when force push?

Copy link
Member

@ethantkoenig ethantkoenig Oct 29, 2017

Choose a reason for hiding this comment

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

{{end}}
{{if eq .State "warning"}}
<a href="{{.TargetURL}}" target=_blank><i class="commit-status warning sign icon yellow"></i></a>
{{if .}}
Copy link
Member

@ethantkoenig ethantkoenig Sep 24, 2017

Choose a reason for hiding this comment

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

This file uses spaces

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@lafriks
Copy link
Member

lafriks commented Oct 25, 2017

@lunny can you resolve requested changes before 1.3?

@lunny
Copy link
Member Author

lunny commented Oct 25, 2017

@lafriks Yes, I will.

@lunny lunny force-pushed the lunny/add_commit_comment_pull branch from 85b6cef to cde7ed1 Compare October 26, 2017 07:30
@lunny lunny force-pushed the lunny/add_commit_comment_pull branch from 60f6e9e to d6655d2 Compare November 6, 2017 05:27
}
}
if startIdx > -1 {
commits = commits[:startIdx]
Copy link
Member

@ethantkoenig ethantkoenig Nov 7, 2017

Choose a reason for hiding this comment

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

From what I can tell, this is not right.

Suppose I have the following (where later-in-the-alphabet commits have a later timestamp; it appears this affects the order of opts.Commits, which is itself kind of concerning)

A---B(master, origin/master)
 \
  C(develop, origin/develop)

and I rebase develop onto master, resulting in

      C'(develop)
     /
A---B(master, origin/master)
 \
  C(origin/develop)

If I force push develop, the opts.Commits will contain [C', C, B], in that order. In this case (since BaseBranch is master), the start index will be 2, and both C' and C will be included in commits[:startIdx].

Copy link
Member

@ethantkoenig ethantkoenig Nov 7, 2017

Choose a reason for hiding this comment

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

Also, it is possible that the head commit of the base branch is not in commits at all.

Suppose I have

A(master, origin/master)
 \
  B(develop, origin/develop)

and I replace commit B with a new commit C locally

  C(develop)
 /
A(master, origin/master)
 \
  B(origin/develop)

If I force push develop, opts.Commits will contain [C, B], in that order. In this case, startIdx will still be -1 after the for loop, and commits will still contain both C and B, which is incorrect.

Copy link
Member Author

Choose a reason for hiding this comment

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

C will not in the commits list since it has been commit before. See https://github.com/go-gitea/gitea/blob/master/models/update.go#L257

Copy link
Member

@ethantkoenig ethantkoenig Nov 7, 2017

Choose a reason for hiding this comment

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

@lunny I have added print statements to the beginning of CommitRepoActions (which is run after line 257 of models/update.go), to print the contents of opts.Commits. In both of the cases described in my comments, I have gotten the results that match what my comments describe. If you are unable to reproduce these results, or if I am missing something, please let me know.

}
}
if startIdx > -1 {
commits = commits[:startIdx]
Copy link
Member

@ethantkoenig ethantkoenig Nov 7, 2017

Choose a reason for hiding this comment

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

Also, it is possible that the head commit of the base branch is not in commits at all.

Suppose I have

A(master, origin/master)
 \
  B(develop, origin/develop)

and I replace commit B with a new commit C locally

  C(develop)
 /
A(master, origin/master)
 \
  B(origin/develop)

If I force push develop, opts.Commits will contain [C, B], in that order. In this case, startIdx will still be -1 after the for loop, and commits will still contain both C and B, which is incorrect.

@lunny lunny modified the milestones: 1.3.0, 1.4.0 Nov 10, 2017
@lafriks lafriks modified the milestones: 1.4.0, 1.5.0 Jan 17, 2018
@techknowlogick techknowlogick modified the milestones: 1.5.0, 1.6.0 May 25, 2018
@techknowlogick techknowlogick modified the milestones: 1.6.0, 1.7.0 Aug 28, 2018
@techknowlogick
Copy link
Member

@lunny closing as outdated. Please re-open if needed.

@bkcsoft bkcsoft 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 Oct 29, 2018
@lafriks lafriks removed this from the 1.7.0 milestone Oct 30, 2018
@lunny lunny deleted the lunny/add_commit_comment_pull branch November 18, 2020 04:34
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 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. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show commits to a branch in PR
10 participants