-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
Should these comments be removed on a force push (like in Github)? |
@ethantkoenig yes, I think you are right. I will update this. |
models/issue_comment.go
Outdated
CommitSHA string `xorm:"VARCHAR(40)"` | ||
CommitSHA string `xorm:"VARCHAR(40)"` | ||
Link string `xorm:"VARCHAR(2048)"` | ||
CommitStatus *CommitStatus `xorm:"-"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
bace2ef
to
b543ab2
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@ethantkoenig done. |
<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> |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 {
routers/repo/issue.go
Outdated
@@ -683,6 +683,11 @@ func ViewIssue(ctx *context.Context) { | |||
ctx.Handle(500, "LoadAssignees", err) | |||
return | |||
} | |||
} else if comment.Type == models.CommentTypePullPushCommit { |
There was a problem hiding this comment.
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 --> |
There was a problem hiding this comment.
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)"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks for clarification 👍
c646458
to
85b6cef
Compare
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())
There was a problem hiding this comment.
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++ { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
models/issue_comment.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 .}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file uses spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@lunny can you resolve requested changes before 1.3? |
@lafriks Yes, I will. |
85b6cef
to
cde7ed1
Compare
60f6e9e
to
d6655d2
Compare
} | ||
} | ||
if startIdx > -1 { | ||
commits = commits[:startIdx] |
There was a problem hiding this comment.
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]
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 closing as outdated. Please re-open if needed. |
Fixes #2830