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

Closing issues through commits #302

Closed
nussjustin opened this issue Jul 23, 2014 · 22 comments
Closed

Closing issues through commits #302

nussjustin opened this issue Jul 23, 2014 · 22 comments
Labels
🎯 feature Categorizes as related to a new feature

Comments

@nussjustin
Copy link
Contributor

Reference: https://trello.com/c/xGlRil52/241-git-push-commit

Being bored I looked into this feature request and created a first working version (currently in my fork nuss-justin/gogs@469cbc881340dd).
This also fixes a little bug I introduced, where the completeness of a milestone wouldn't get updated if an issue gets closed/reopened.

The next thing I wanted to do is adding a closing comment to issues, closed through commits.
Now I stumbled across the comments Table which has a commit_id field, but it seems like commits aren't implemented yet. At least I wasn't able to find out what the commit_id references.

Now my little question:
What's the state of commits in the database?

@unknwon
Copy link
Member

unknwon commented Jul 23, 2014

Aha, thanks all your previous PRs!

What's the state of commits in the database?

Commits are not saved in database, the only time you can reach if the commit message contains somethings like fix #xx the in https://github.com/gogits/gogs/blob/dev/models/action.go#L82

@nussjustin
Copy link
Contributor Author

My thought was, that there is a CommitId field on the Commit struct, but it always gets 0. How is it intended to be used? I though I could create a comment with CommitId referencing the commit that contains the fix #xx message, but it doesn't have an identifier (except the commit hash, but the database column is of type bigint)

Update: My idea is to change the CommitId of the Comment struct to a String and then save a commit hash in it. This way we could link to the commit.

If pull requests get implemented, the field can then act as either a reference to a commit in the pull request or as closing commit. (This could depend on the Type of the comment)

@unknwon
Copy link
Member

unknwon commented Jul 23, 2014

CommitId is prepared for comments on the diff/commit page like https://github.com/nuss-justin/gogs/commit/469cbc881340dd , so for issue it's always 0...

@nussjustin
Copy link
Contributor Author

It was just an thought :-)
I wanted to add the commit (of the commit that closes the issue) to the comment, in the IT_CLOSE case, so it can be shown in the issue.

I could use the Content of the comment, for the commit message, but I would also need to store the commit hash somehow.It was just an thought :-)
I wanted to add the commit (of the commit that closes the issue) to the comment, in the IT_CLOSE case, so it can be shown in the issue.

I could use the Content of the comment, for the commit message, but I would still also need to store the commit hash somewhere.

@unknwon
Copy link
Member

unknwon commented Jul 23, 2014

I think we might just need more types for two following usage:

snip20140723_2

@nussjustin
Copy link
Contributor Author

Yeah, that should be easy (just adding two new consts) for the types.
But for the 2. one it should also be able to reference a commit directly like this:

unbenannt

It should either be another new type or something else to distinguish between references from other issues and commits.

@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

It should either be another new type or something else to distinguish between references from other issues and commits.

type ReferenceType int

const (
 PULL ReferenceType = iota + 1
 ISSUE
 COMMENT
)

Add a refType field to distinguish?

@nussjustin
Copy link
Contributor Author

I see two ways to solve this:

Solution 1: We could use your suggestion and add a ReferenceType type, which could look like this:

type ReferenceType int

const (
 // Reference from some pull request
 PULL ReferenceType = iota + 1

 // Reference from another issue
 ISSUE

 // Plain old comment
 COMMENT

 // Reference from some commit (not part of a pull request)
 COMMIT
)

Solution 2: We could just combine the ReferenceType with the existing IT_* types (used as Comment.Type values) like this (see comments):

type CommentType int

const (
 // We use iota and the order COMMENT, REOPEN, CLOSE to maintain
 // backwards compatibility with existing comments, without updating them

 // Plain old comment, can be associated with a commit (CommitId > 0) and a line (Line > 0)
 COMMENT CommentType = iota

 // Reopen action
 REOPEN

 // Close action
 CLOSE

 // Reference from another issue
 // Maybe with some prefix/suffix to show that it's a reference,
 // like ISSUEREF or something similar
 ISSUE 

 // Reference from some commit (not part of a pull request)
 COMMIT

 // Reference from some pull request
 PULL
)

Personally I like the 2. one more, because it only needs one type, and maintains backwards compatibility, without having to update anything. (Except I'm missing something)

One thing I'm still not sure how to implement is the case when a normal commit references (closes) an issue. In this case we need 1. the commit message (to be shown on the issue page) and it's hash (so that we can link to it). The message can be saved inside the normal Comment.Content field, which is otherwise only used by normal comments.

Now the hash has to be saved somewhere too. It could be put in the Comment.Content field too, but I would rather have it stored in another column or table.

@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

One thing I'm still not sure how to implement is the case when a normal commit references (closes) an issue. In this case we need 1. the commit message (to be shown on the issue page) and it's hash (so that we can link to it). The message can be saved inside the normal Comment.Content field, which is otherwise only used by normal comments.

Just make a ISSUE_COMMENT in CommentType should be fine?

@nussjustin
Copy link
Contributor Author

My problem is not the type.
The Comment would just look like:

Comment {
    // ...
    Type: <ISSUE, COMMIT or PULL>
    Content: <COMMIT MESSAGE>
    // ...
}

but the commit hash must be stored too

I thought about putting it directly into the message (<a href="<URL>/<HASH>"><MESSAGE></a>), but I don't know if this is really what we want.

@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

If we don't need access that commit hash anywhere else, then store in message is fine.

@nussjustin
Copy link
Contributor Author

I've made a pull request to test/review my changes: #305

unknwon added a commit that referenced this issue Jul 24, 2014
@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

Sorry, how does code work?

@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

I tried to push commit with message fix #1 but seems like nothing happened? Did u forgot to add new comment when detected?

@nussjustin
Copy link
Contributor Author

I just tested it with my local branch (the one merged) and the current gogits/gogs dev branch.

This is what I did in both cases (not exactly the same thing):
shell

And this is what i got on the current dev branch:

issue-dev

I get the same with my local branch. It searches for the same words as Github. (https://help.github.com/articles/closing-issues-via-commit-messages) followed by the issue as either #XXX or user/repo#XXX (it doesn't search for only user#XXX at this time)

@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

qq20140724-1

Really? I did same thing but nothing happens?

@nussjustin
Copy link
Contributor Author

I just created a fresh gogs server on a linux vServer and everything worked as expected (except a little counter bug, which I'm now gonne to pull-request in :-))

Update: Image

simple

@unknwon
Copy link
Member

unknwon commented Jul 24, 2014

so wried ...

@nussjustin
Copy link
Contributor Author

Hey, have you tested it again?
I'd like to know if this now works as expected, so that this issue can be closed.

@unknwon
Copy link
Member

unknwon commented Jul 28, 2014

I'll test again later and look at the code.

@unknwon
Copy link
Member

unknwon commented Jul 30, 2014

Sorry for late, it's working!

@unknwon unknwon closed this as completed Jul 30, 2014
@nussjustin
Copy link
Contributor Author

No problem :-)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🎯 feature Categorizes as related to a new feature
Projects
None yet
Development

No branches or pull requests

2 participants