Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

changelog is generating incorrect order of commits/Issues #23

Closed
joychugh opened this issue Apr 5, 2016 · 18 comments
Closed

changelog is generating incorrect order of commits/Issues #23

joychugh opened this issue Apr 5, 2016 · 18 comments
Labels

Comments

@joychugh
Copy link

joychugh commented Apr 5, 2016

Here is the scenario:
in Develop I add commit a
Create Release Branch v1.0
add commit b in release Branch
add commit c in Develop Branch (for v1.2)
add commit d in release Brach
Finish Release tag with v.10
merge to master & develop

When I generate the gitChangelog in develop branch
it puts commit b,c,d in v1.0 Whereas commit c has not yet released.

When I do a release 1.2 ( which has commit c and no other commit)
it doesn't even show up in the changlog

The only way commit c can be seen in correct place is if i do
fromRef=1.0
toRef=1.2
i will see c listed under 1.2. Not otherwise

task gitChangelogTask(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
    filePath = "CHANGELOG.md";
    templateContent = new File('changelog.mustache').getText('UTF-8');
    customIssues = [
            [ "Added", "(?i)(added)\\s*(?i)(JIRA-\\d{1,6})(.*)", "https://mycompanyjira.com/browse/\${PATTERN_GROUP_2}", "\${PATTERN_GROUP_3}"],
            [ "Fixed", "(?i)(fixed)\\s*(?i)(JIRA-\\d{1,6})(.*)", "https://mycompanyjira.com/browse/\${PATTERN_GROUP_2}", "\${PATTERN_GROUP_3}"],
    ]
    jiraIssuePattern = '(?!)' // to skip jira issues for now.
    untaggedName = "Next Release";
    ignoreCommitsWithoutIssue = true;
}
@joychugh
Copy link
Author

joychugh commented Apr 6, 2016

The bug seems to be here
https://github.com/tomasbjerre/git-changelog-lib/blob/master/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java#L101

If there are commits in order like

commit a
tag 1.0
commit b
commit c (not in tag 1.0)

It will go through a add it to the commits for the untagged tag
set currentTagName to 1.0
and then add b and c
where as c is not part of the tag 1.0

I looked around and found this
https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ListTags.java

or if you can add commits by
sort tags
get a list of commits between each tag
and then add them it should produce a good result. the starting can be from
HEAD to latest_tag .. and so on
what do you think?

@tomasbjerre
Copy link
Owner

I will look at this later today. Can you also supply content of your changelog.mustache?

@tomasbjerre tomasbjerre added the bug label Apr 6, 2016
@tomasbjerre
Copy link
Owner

* a (tag2)
* b (tag1)
* c

I suspcect git.log().add(tag2).call() returns a, b and c.
I suspcect git.log().addRange(tag1, tag2).call() returns b and a (reverse order).

Should be an easy fix around here. Expect a release later today.

@tomasbjerre
Copy link
Owner

Is this what your repo looks like?

* c (dev, tag:1.2)
|   * d (rel, tag: 1.0)
|   * b
| /
* a

@joychugh
Copy link
Author

joychugh commented Apr 6, 2016

* Merge rel back to master & dev
|  \
|  (rel, tag: 1.2)
| /
*  c 
|   * d (rel, tag: 1.0)
|   * b 
| /
* a

@tomasbjerre
Copy link
Owner

Not sure I understand exactly what your repo looks like. What is the output of this?

git log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cgreen%d %Creset %s %C(bold)(%an)%Creset"

Looks like you create tags in the release-branch, not in master.

I am use to tagging master and I believe that is the correct way of doing it in GIT Flow.

Sorry, this was a bit more complex then I thought earlier today =)

tomasbjerre added a commit that referenced this issue Apr 6, 2016
 * Also testing tag in feature branch #23
tomasbjerre added a commit that referenced this issue Apr 6, 2016
 * Also testing tag in feature branch #23
tomasbjerre added a commit that referenced this issue Apr 6, 2016
 * Also testing tag in feature branch #23
tomasbjerre added a commit that referenced this issue Apr 6, 2016
 * Also testing tag in feature branch #23
tomasbjerre added a commit that referenced this issue Apr 6, 2016
 * Also testing tag in feature branch #23
@joychugh
Copy link
Author

joychugh commented Apr 7, 2016

Let me try to run some tests with the gitflow of making tags on master and ill get back to you with results,

@joychugh
Copy link
Author

joychugh commented Apr 7, 2016

jchugh:changelog jchugh$ git log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cgreen%d %Creset %s %C(bold)(%an)%Creset"
*       6102f44 2016-04-07 (HEAD -> develop)  Merge branch 'release/1.0' into develop (Joy Chugh)
|\  
* |     f9e20c4 2016-04-07  ADDED DATASVC-1234 Commit C in DEV (Joy Chugh)
| | *           d83168f 2016-04-07 (tag: 1.0, master)  Merge branch 'release/1.0' (Joy Chugh)
| | |\  
| | |/  
| |/|   
| * |   115f0d7 2016-04-07  Fixed DATASVC-1234 Commit D in 1.0 (Joy Chugh)
| * |   aa3733e 2016-04-07  ADDED DATASVC-1234 Commit B in REL 1.0 (Joy Chugh)
|/ /  
* |     5061917 2016-04-07  ADDED DATASVC-1234 Commit A (Joy Chugh)
|/  
*       80e3d57 2016-04-07  ADDED DATASVC-1234 initial commit (Joy Chugh)

@joychugh
Copy link
Author

joychugh commented Apr 7, 2016

After I do the above and use the following settings

task gitChangelogTask(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
    filePath = "CHANGELOG.md";
    templateContent = new File('changelog.mustache').getText('UTF-8');
    customIssues = [
            [ "Added", "(?i)(added)\\s*(?i)(DATASVC-\\d{1,6})(.*)", "https://jira.ops.aol.com/browse/\${PATTERN_GROUP_2}", "\${PATTERN_GROUP_3}"],
            [ "Fixed", "(?i)(fixed)\\s*(?i)(DATASVC-\\d{1,6})(.*)", "https://jira.ops.aol.com/browse/\${PATTERN_GROUP_2}", "\${PATTERN_GROUP_3}"],
    ]
    jiraIssuePattern = '(?!)'
    untaggedName = "Next Release";
    ignoreCommitsWithoutIssue = true;
    toRef='develop'
}

Using the following template

{{#tags}}
## {{name}}
{{#issueTypes}}
### {{name}}
 {{#issues}}
  {{#hasIssue}}
   {{#hasLink}}
* [{{title}}]({{link}})
   {{/hasLink}}
   {{^hasLink}}
* {{title}}
   {{/hasLink}}
  {{/hasIssue}}
  {{^hasIssue}}
  {{/hasIssue}}
 {{/issues}}
{{/issueTypes}}
{{/tags}}

I run the task on develop branch i get this


## Next Release
### Added
* [ Commit A](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ Commit B in REL 1.0](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ Commit C in DEV](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ initial commit](https://jira.ops.aol.com/browse/DATASVC-1234)
### Fixed
* [ Commit D in 1.0](https://jira.ops.aol.com/browse/DATASVC-1234)

Running On Master

## 1.0
### Added
* [ Commit A](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ Commit B in REL 1.0](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ initial commit](https://jira.ops.aol.com/browse/DATASVC-1234)
### Fixed
* [ Commit D in 1.0](https://jira.ops.aol.com/browse/DATASVC-1234)

@joychugh
Copy link
Author

joychugh commented Apr 7, 2016

jchugh:changelog jchugh$ git log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cgreen%d %Creset %s %C(bold)(%an)%Creset"
*       7037f3e 2016-04-07 (HEAD -> master, tag: 1.1)  Merge branch 'release/1.1' (Joy Chugh)
|\  
| *     7f301be 2016-04-07 (develop)  Fixed DATASVC-1234 Commit E in DEV (Joy Chugh)
| *     6102f44 2016-04-07  Merge branch 'release/1.0' into develop (Joy Chugh)
| |\  
| * |   f9e20c4 2016-04-07  ADDED DATASVC-1234 Commit C in DEV (Joy Chugh)
* | |           d83168f 2016-04-07 (tag: 1.0)  Merge branch 'release/1.0' (Joy Chugh)
|\ \ \  
| | |/  
| |/|   
| * |   115f0d7 2016-04-07  Fixed DATASVC-1234 Commit D in 1.0 (Joy Chugh)
| * |   aa3733e 2016-04-07  ADDED DATASVC-1234 Commit B in REL 1.0 (Joy Chugh)
| |/  
| *     5061917 2016-04-07  ADDED DATASVC-1234 Commit A (Joy Chugh)
|/  
*       80e3d57 2016-04-07  ADDED DATASVC-1234 initial commit (Joy Chugh)

Running on master

## 1.1
### Fixed
* [ Commit E in DEV](https://jira.ops.aol.com/browse/DATASVC-1234)
## 1.0
### Added
* [ Commit A](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ Commit B in REL 1.0](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ Commit C in DEV](https://jira.ops.aol.com/browse/DATASVC-1234)
* [ initial commit](https://jira.ops.aol.com/browse/DATASVC-1234)
### Fixed
* [ Commit D in 1.0](https://jira.ops.aol.com/browse/DATASVC-1234)

Setting

task gitChangelogTask(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
    filePath = "CHANGELOG.md";
    templateContent = new File('changelog.mustache').getText('UTF-8');
    customIssues = [
            [ "Added", "(?i)(added)\\s*(?i)(DATASVC-\\d{1,6})(.*)", "https://jira.ops.aol.com/browse/\${PATTERN_GROUP_2}", "\${PATTERN_GROUP_3}"],
            [ "Fixed", "(?i)(fixed)\\s*(?i)(DATASVC-\\d{1,6})(.*)", "https://jira.ops.aol.com/browse/\${PATTERN_GROUP_2}", "\${PATTERN_GROUP_3}"],
    ]
    jiraIssuePattern = '(?!)'
    untaggedName = "Next Release";
    ignoreCommitsWithoutIssue = true;
}

As you can see Commit C should be in 1.1 not 1.0 since it was done on the develop branch after the release 1.0 was branched from it. (B and D were done on 1.0 as you can see from previous example)

@joychugh
Copy link
Author

joychugh commented Apr 7, 2016

Since you already have code which does toRef and fromRef
if you get do gitTags b/w each tag falling between the fromRef and toRef and then flatten all those List lists, it should give you a better output since if i do fromRef 1.0 to 1.1 it gives me a perfect changelog


## 1.1
### Added
* [ Commit C in DEV](https://jira.ops.aol.com/browse/DATASVC-1234)
### Fixed
* [ Commit E in DEV](https://jira.ops.aol.com/browse/DATASVC-1234)


@tomasbjerre
Copy link
Owner

Perhaps it is that easy =) The tags would have to be sorted first, by the commit time of the commits they refer to...
I added a test case for now, will look at this as soon as I find the time.

@joychugh
Copy link
Author

joychugh commented Apr 8, 2016

I think if you sort it by time it can give the same issue since that is what is causing the issue in the first place. if people tag using some fixed convention you can sort them lexicographically and then do the diff b/w each one starting from the bottom since usually people tag using a certain convention. If they don't then they can't use the plugin. It should solve the issue for most of the people who follow conventions.

tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
@tomasbjerre
Copy link
Owner

I may have a fix ready in PR #25. Only problem I can see is that it is about 4 times slower then before.

tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
 * To find all commits in all tags.
tomasbjerre added a commit that referenced this issue Apr 9, 2016
…ll-tags

Traversing commit tree by parents #23
@tomasbjerre
Copy link
Owner

I made a release with this fix.

tomasbjerre added a commit that referenced this issue Apr 10, 2016
 * To avoid random behaviour.
@tomasbjerre
Copy link
Owner

Open issue again if not fixed =)

@joychugh
Copy link
Author

Thanks! I did not have time to test it yet, when do you plan to release this version to gradle plugins repository I would like to use it at my work

@tomasbjerre
Copy link
Owner

tomasbjerre added a commit that referenced this issue Jul 16, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants