1- const parseGithubUrl = require ( 'parse-github-url' ) ;
21const urlJoin = require ( 'url-join' ) ;
32const got = require ( 'got' ) ;
4- const debug = require ( 'debug' ) ( 'semantic-release:github ' ) ;
3+ const debug = require ( 'debug' ) ( 'semantic-release:gitlab ' ) ;
54const resolveConfig = require ( './resolve-config' ) ;
5+ const getRepoId = require ( './get-repo-id' ) ;
66
77module . exports = async ( pluginConfig , { repositoryUrl} , { gitHead, gitTag, notes} , logger ) => {
88 const { gitlabToken, gitlabUrl, gitlabApiPathPrefix} = resolveConfig ( pluginConfig ) ;
9- const { name : repo , owner } = parseGithubUrl ( repositoryUrl ) ;
9+ const repoId = encodeURIComponent ( getRepoId ( gitlabUrl , repositoryUrl ) ) ;
1010
11+ debug ( 'repoId: %o' , repoId ) ;
1112 debug ( 'release name: %o' , gitTag ) ;
1213 debug ( 'release ref: %o' , gitHead ) ;
1314
1415 try {
1516 // Test if the tag already exists
16- await got . get ( urlJoin ( gitlabUrl , gitlabApiPathPrefix , `/projects/${ owner } %2F ${ repo } /repository/tags/${ gitTag } ` ) , {
17+ await got . get ( urlJoin ( gitlabUrl , gitlabApiPathPrefix , `/projects/${ repoId } /repository/tags/${ gitTag } ` ) , {
1718 json : true ,
1819 headers : { 'Private-Token' : gitlabToken } ,
1920 } ) ;
2021 debug ( 'The git tag %o already exists, update the release description' , gitTag ) ;
2122 // Update the release notes
2223 await got . post (
23- urlJoin ( gitlabUrl , gitlabApiPathPrefix , `/projects/${ owner } %2F ${ repo } /repository/tags/${ gitTag } /release` ) ,
24+ urlJoin ( gitlabUrl , gitlabApiPathPrefix , `/projects/${ repoId } /repository/tags/${ gitTag } /release` ) ,
2425 { json : true , headers : { 'Private-Token' : gitlabToken } , body : { tag_name : gitTag , description : notes } } // eslint-disable-line camelcase
2526 ) ;
2627 } catch ( err ) {
@@ -29,14 +30,11 @@ module.exports = async (pluginConfig, {repositoryUrl}, {gitHead, gitTag, notes},
2930 throw err ;
3031 }
3132 debug ( 'Create git tag %o with commit %o and release description' , gitTag , gitHead ) ;
32- await got . post (
33- urlJoin ( gitlabUrl , gitlabApiPathPrefix , `/projects/${ owner } %2F${ repo } /repository/tags/${ gitTag } /release` ) ,
34- {
35- json : true ,
36- headers : { 'PRIVATE-TOKEN' : gitlabToken } ,
37- body : { tag_name : gitTag , ref : gitHead , release_description : notes } , // eslint-disable-line camelcase
38- }
39- ) ;
33+ await got . post ( urlJoin ( gitlabUrl , gitlabApiPathPrefix , `/projects/${ repoId } /repository/tags/${ gitTag } /release` ) , {
34+ json : true ,
35+ headers : { 'PRIVATE-TOKEN' : gitlabToken } ,
36+ body : { tag_name : gitTag , ref : gitHead , release_description : notes } , // eslint-disable-line camelcase
37+ } ) ;
4038 }
4139
4240 logger . log ( 'Published GitLab release: %s' , gitTag ) ;
0 commit comments