github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/gits/commits_integration_test.go (about)

     1  // +build integration
     2  
     3  package gits_test
     4  
     5  import (
     6  	"testing"
     7  
     8  	v1 "github.com/jenkins-x/jx-api/pkg/apis/jenkins.io/v1"
     9  	"github.com/olli-ai/jx/v2/pkg/gits"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestChangelogMarkdown(t *testing.T) {
    14  	releaseSpec := &v1.ReleaseSpec{
    15  		Commits: []v1.CommitSummary{
    16  			{
    17  				Message: "some commit 1\nfixes #123",
    18  				SHA:     "123",
    19  				Author: &v1.UserDetails{
    20  					Name:  "James Strachan",
    21  					Login: "jstrachan",
    22  				},
    23  			},
    24  			{
    25  				Message: "some commit 2\nfixes #345",
    26  				SHA:     "456",
    27  				Author: &v1.UserDetails{
    28  					Name:  "James Rawlings",
    29  					Login: "rawlingsj",
    30  				},
    31  			},
    32  		},
    33  	}
    34  	gitInfo := &gits.GitRepository{
    35  		Host:         "github.com",
    36  		Organisation: "jstrachan",
    37  		Name:         "foo",
    38  	}
    39  	markdown, err := gits.GenerateMarkdown(releaseSpec, gitInfo)
    40  	assert.Nil(t, err)
    41  	//t.Log("Generated => " + markdown)
    42  
    43  	expectedMarkdown := `## Changes
    44  
    45  * some commit 1 ([jstrachan](https://github.com/jstrachan))
    46  * some commit 2 ([rawlingsj](https://github.com/rawlingsj))
    47  `
    48  	assert.Equal(t, expectedMarkdown, markdown)
    49  }
    50  
    51  func TestChangelogMarkdownWithConventionalCommits(t *testing.T) {
    52  	releaseSpec := &v1.ReleaseSpec{
    53  		Commits: []v1.CommitSummary{
    54  			{
    55  				Message: "fix: some commit 1\nfixes #123",
    56  				SHA:     "123",
    57  				Author: &v1.UserDetails{
    58  					Name:  "James Strachan",
    59  					Login: "jstrachan",
    60  				},
    61  			},
    62  			{
    63  				Message: "feat: some commit 2\nfixes #345",
    64  				SHA:     "456",
    65  				Author: &v1.UserDetails{
    66  					Name:  "James Rawlings",
    67  					Login: "rawlingsj",
    68  				},
    69  			},
    70  			{
    71  				Message: "feat(has actual feature name): some commit 3\nfixes #456",
    72  				SHA:     "567",
    73  				Author: &v1.UserDetails{
    74  					Name:  "James Rawlings",
    75  					Login: "rawlingsj",
    76  				},
    77  			},
    78  			{
    79  				Message: "bad comment 4",
    80  				SHA:     "678",
    81  				Author: &v1.UserDetails{
    82  					Name:  "James Rawlings",
    83  					Login: "rawlingsj",
    84  				},
    85  			},
    86  		},
    87  	}
    88  	gitInfo := &gits.GitRepository{
    89  		Host:         "github.com",
    90  		Organisation: "jstrachan",
    91  		Name:         "foo",
    92  	}
    93  	markdown, err := gits.GenerateMarkdown(releaseSpec, gitInfo)
    94  	assert.Nil(t, err)
    95  	//t.Log("Generated => " + markdown)
    96  
    97  	expectedMarkdown := `## Changes
    98  
    99  ### New Features
   100  
   101  * some commit 2 ([rawlingsj](https://github.com/rawlingsj))
   102  * has actual feature name: some commit 3 ([rawlingsj](https://github.com/rawlingsj))
   103  
   104  ### Bug Fixes
   105  
   106  * some commit 1 ([jstrachan](https://github.com/jstrachan))
   107  
   108  ### Other Changes
   109  
   110  These commits did not use [Conventional Commits](https://conventionalcommits.org/) formatted messages:
   111  
   112  * bad comment 4 ([rawlingsj](https://github.com/rawlingsj))
   113  `
   114  	assert.Equal(t, expectedMarkdown, markdown)
   115  }