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

Configure compare URL and commit URL with Angular preset #695

Closed
GiamBoscaro opened this issue Aug 7, 2024 · 4 comments
Closed

Configure compare URL and commit URL with Angular preset #695

GiamBoscaro opened this issue Aug 7, 2024 · 4 comments

Comments

@GiamBoscaro
Copy link

GiamBoscaro commented Aug 7, 2024

I am generating the CHANGELOG for some repositories hosted in an on premise Bitbucket. The compare and commit link are generated wrong.
The repositoryUrl parameter is configured as this: https://<host>/git/scm/<project>/<repo>.git.
The commit url should be this: https://<host>/git/projects/<project>/repos/<repo>/commits/<commit-sha>
The compare url should be this: https://<host>/git/projects/<project>/repos/<repo>/compare/diff?sourceBranch=refs%2Ftags%2F<current-tag>&targetBranch=refs%2Ftags%2F<previous-tag>

As you can see the links are different from each other and completely different from the ones generated by the preset. One of the reasons (but not the only one) is that the preset is using repositoryUrl to generate the links to the commit url and compare url, but the repositoryUrl used to git pull and git push is completely different from the one that should be for the links.

I have seen that for other presets you could use presetConfig to configure these links. An example:

"presetConfig": { 
       "commitUrlFormat": "{{host}}/git/projects/{{owner}}/repos/{{repository}}/commits/{{hash}}",
       "compareUrlFormat": "{{host}}/git/projects/{{owner}}/repos/{{repository}}/diff?sourceBranch=refs%2Ftags%2F/{{currentTag}}&targetBranch=refs%2Ftags%2F{{previousTag}}"
}

but these do not seem to work with the angular preset. So is there any way to customize these links?

@SaschaJohn
Copy link

@GiamBoscaro I ran into the same issue.
It looks like the conventional-changelog-conventionalcommits is the only preset that allows customization of templates.

All others only provide static "github-style" link generation.

E.g see angular-preset for :
https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/src/templates/header.hbs
vs https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-conventionalcommits/src/templates/header.hbs

From my analysis conventionalcommits is a superset of angular. So changing to
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"commitUrlFormat": "{{host}}/{{owner}}/{{repository}}/commits/{{hash}}",
"compareUrlFormat": "http://www.abc.de/{{owner}}/{{repository}}/compare/{{currentTag}}%0D{{previousTag}}#diff",
"issueUrlFormat ": "{{host}}/{{owner}}/{{repository}}/issue/{{id}}"
}
}
]

should be a valid mitigation of the issue. To test create a local commit and run npx semantic-release --dry-run --debug to see the output.

@GiamBoscaro
Copy link
Author

GiamBoscaro commented Jan 20, 2025

@GiamBoscaro I ran into the same issue. It looks like the conventional-changelog-conventionalcommits is the only preset that allows customization of templates.

All others only provide static "github-style" link generation.

E.g see angular-preset for : https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/src/templates/header.hbs vs https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-conventionalcommits/src/templates/header.hbs

From my analysis conventionalcommits is a superset of angular. So changing to "@semantic-release/release-notes-generator", { "preset": "conventionalcommits", "presetConfig": { "commitUrlFormat": "{{host}}/{{owner}}/{{repository}}/commits/{{hash}}", "compareUrlFormat": "http://www.abc.de/{{owner}}/{{repository}}/compare/{{currentTag}}%0D{{previousTag}}#diff", "issueUrlFormat ": "{{host}}/{{owner}}/{{repository}}/issue/{{id}}" } } ]

should be a valid mitigation of the issue. To test create a local commit and run npx semantic-release --dry-run --debug to see the output.

Hello, thank you for your reply. I am actually trying to test this but it does not work for me. The commits are still generated with the usual wrong urls.

My config:

module.exports = {
  branches: [
    { name: 'main' },
    { name: 'stage', prerelease: true },
    { name: 'dev', prerelease: true },
  ],
  repositoryUrl: '',
  plugins: [
    '@semantic-release/commit-analyzer',
    ['@semantic-release/release-notes-generator', {
      preset: 'conventionalcommits',
      presetConfig: {
        commitUrlFormat: '{{host}}/git/projects/{{owner}}/repos/{{repository}}/commits/{{hash}}',
        compareUrlFormat: '{{host}}/git/projects/{{owner}}/repos/{{repository}}/diff?sourceBranch=refs%2Ftags%2F/{{currentTag}}&targetBranch=refs%2Ftags%2F{{previousTag}}',
        issueUrlFormat: '{{host}}/{{owner}}/{{repository}}/issue/{{id}}',
      },
    }],
    ['@semantic-release/changelog', {
      changelogFile: 'docs/CHANGELOG.md',
    }],
    '@semantic-release/npm',
    ['@semantic-release/git', {
      assets: ['docs/CHANGELOG.md', 'package-lock.json', 'package.json'],
      message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
    }],
  ],
};

Am I doing something different than you?

I have also tried this config here:

module.exports = {
  branches: [
    { name: 'main' },
    { name: 'stage', prerelease: true },
    { name: 'dev', prerelease: true },
  ],
  preset: "conventionalcommits",
  repositoryUrl: '',
  plugins: [
    ["@semantic-release/commit-analyzer", {
      preset: "conventionalcommits"
    }],
    ['@semantic-release/release-notes-generator', {
      preset: 'conventionalcommits',
      presetConfig: {
        commitUrlFormat: '{{host}}/git/projects/{{owner}}/repos/{{repository}}/commits/{{hash}}',
        compareUrlFormat: '{{host}}/git/projects/{{owner}}/repos/{{repository}}/diff?sourceBranch=refs%2Ftags%2F/{{currentTag}}&targetBranch=refs%2Ftags%2F{{previousTag}}',
        issueUrlFormat: '{{host}}/{{owner}}/{{repository}}/issue/{{id}}',
      },
    }],
    ['@semantic-release/changelog', {
      changelogFile: 'docs/CHANGELOG.md',
    }],
    '@semantic-release/npm',
    ['@semantic-release/git', {
      assets: ['package-lock.json', 'package.json'],
      message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
    }],
  ],
};

and here I the semantic-release just exits without any error while analyzing the commints. Last log is this:

[1:03:47 PM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"

@SaschaJohn
Copy link

@GiamBoscaro interesting, it's not working for you.
Maybe because urlFormats need to be in double quotes?

I work with a .releaserc file:

{ "plugins": [ "@semantic-release/commit-analyzer", [ "@semantic-release/release-notes-generator", { "preset": "conventionalcommits", "presetConfig": { "compareUrlFormat": "{{host}}/{{owner}}/{{repository}}/branchCompare?baseVersion=GT{{previousTag}}&targetVersion=GT{{currentTag}}&_a=files", "issueUrlFormat": "{{host}}/{{owner}}/_workitems?id={{id}}" } } ], [ "@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" } ], ["@semantic-release/git", { "assets": ["CHANGELOG.md"], "message": "chore(release): ${nextRelease.version} [skip ci] \n\n${nextRelease.notes}" } ] ], "tagFormat": "v${version}", "branches": [ "develop" ] }

try to do a local commit git commit and provide a commit comment in proper format:

 feat(test): fix releaserc

 - updated releaserc

 Related work items: #62971

afterwards run npx semantic-release --dry-run -D that should render you the output as expected:

Image

@GiamBoscaro
Copy link
Author

@GiamBoscaro interesting, it's not working for you. Maybe because urlFormats need to be in double quotes?

I work with a .releaserc file:

{ "plugins": [ "@semantic-release/commit-analyzer", [ "@semantic-release/release-notes-generator", { "preset": "conventionalcommits", "presetConfig": { "compareUrlFormat": "{{host}}/{{owner}}/{{repository}}/branchCompare?baseVersion=GT{{previousTag}}&targetVersion=GT{{currentTag}}&_a=files", "issueUrlFormat": "{{host}}/{{owner}}/_workitems?id={{id}}" } } ], [ "@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" } ], ["@semantic-release/git", { "assets": ["CHANGELOG.md"], "message": "chore(release): ${nextRelease.version} [skip ci] \n\n${nextRelease.notes}" } ] ], "tagFormat": "v${version}", "branches": [ "develop" ] }

try to do a local commit git commit and provide a commit comment in proper format:

 feat(test): fix releaserc

 - updated releaserc

 Related work items: #62971

afterwards run npx semantic-release --dry-run -D that should render you the output as expected:

Image

It is actually working now, I have retried a few times. Don't know exactly what has changed. The substitutions work, but unfortunately the {{owner}} and {{repository}} variables are filled wrong, or at least they're not the value that I actually need. So I will need to hardcode the URL to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants