Skip to content

Commit

Permalink
fix: Update creation of tag link in default success template (#90)
Browse files Browse the repository at this point in the history
fixes: #82
  • Loading branch information
fmigot committed Jan 28, 2022
1 parent e85e59c commit 9f4c735
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.idea/
3 changes: 2 additions & 1 deletion lib/getRepoInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = repositoryUrl => {
.substring(1) // remove leading "/"
.replace('.git', '') // remove .git
.replace(':', '') // remove any colons from path (present in github for example)
const hostname = parsedUrl.hostname
const URL = `https://${parsedUrl.host}/${path}`
return { path, URL }
return { path, URL, hostname }
}
10 changes: 7 additions & 3 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ module.exports = async (pluginConfig, context) => {

if (repo.path) {
const gitTag = nextRelease.gitTag
const gitTagPrefix = repo.hostname.startsWith('gitlab')
? '/-/releases/'
: '/releases/tag/'
const gitTagUrl = repo.URL + gitTagPrefix + gitTag

slackMessage.attachments = [
{
Expand All @@ -104,9 +108,9 @@ module.exports = async (pluginConfig, context) => {
elements: [
{
type: 'mrkdwn',
text: `:package: *<${repo.URL}|${repo.path}>:* <${
repo.URL
}/releases/tag/${gitTag}|${gitTag}>`
text: `:package: *<${repo.URL}|${
repo.path
}>:* <${gitTagUrl}|${gitTag}>`
}
]
}
Expand Down
21 changes: 14 additions & 7 deletions test/getRepoInfo.test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
const assert = require('assert')
const getRepoInfo = require('../lib/getRepoInfo')

const runAssert = (repoUrl, path, url) => {
const runAssert = (repoUrl, path, url, hostname) => {
const actual = getRepoInfo(repoUrl)

assert.equal(path, actual.path)
assert.equal(url, actual.URL)
assert.equal(hostname, actual.hostname)
}

describe('test getRepoInfo', () => {
it('should work for github', () => {
const repositoryUrl = 'ssh://git@github.com:hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://github.com/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
const expectedHostname = 'github.com'
runAssert(repositoryUrl, expectedPath, expectedUrl, expectedHostname)
})

it('should work for bitbucket', () => {
const repositoryUrl = 'ssh://hg@bitbucket.org/hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://bitbucket.org/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
const expectedHostname = 'bitbucket.org'
runAssert(repositoryUrl, expectedPath, expectedUrl, expectedHostname)
})

it('should work for gitlab', () => {
const repositoryUrl = 'ssh://git@gitlab.com:hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://gitlab.com/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
const expectedHostname = 'gitlab.com'
runAssert(repositoryUrl, expectedPath, expectedUrl, expectedHostname)
})

it('should work for repo url with https', () => {
const repositoryUrl = 'https://github.com/hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://github.com/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
const expectedHostname = 'github.com'
runAssert(repositoryUrl, expectedPath, expectedUrl, expectedHostname)
})

it('should work for repo url with git@', () => {
const repositoryUrl = 'git@github.com:hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://github.com/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
const expectedHostname = 'github.com'
runAssert(repositoryUrl, expectedPath, expectedUrl, expectedHostname)
})

it('should work for repo url with other TLD', () => {
const repositoryUrl = 'git@github.pl:hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://github.pl/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
const expectedHostname = 'github.pl'
runAssert(repositoryUrl, expectedPath, expectedUrl, expectedHostname)
})
})

0 comments on commit 9f4c735

Please sign in to comment.