Skip to content

Commit

Permalink
fix: handle undefined API prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 17, 2018
1 parent c4d18d6 commit 8d87b4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ const getRepoId = require('./get-repo-id');
module.exports = async (pluginConfig, {repositoryUrl}, {gitHead, gitTag, notes}, logger) => {
const {gitlabToken, gitlabUrl, gitlabApiPathPrefix} = resolveConfig(pluginConfig);
const repoId = encodeURIComponent(getRepoId(gitlabUrl, repositoryUrl));
const apiUrl = urlJoin(gitlabUrl, gitlabApiPathPrefix);

debug('repoId: %o', repoId);
debug('release name: %o', gitTag);
debug('release ref: %o', gitHead);

try {
// Test if the tag already exists
await got.get(urlJoin(gitlabUrl, gitlabApiPathPrefix, `/projects/${repoId}/repository/tags/${gitTag}`), {
await got.get(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}`), {
json: true,
headers: {'Private-Token': gitlabToken},
});
debug('The git tag %o already exists, update the release description', gitTag);
// Update the release notes
await got.post(
urlJoin(gitlabUrl, gitlabApiPathPrefix, `/projects/${repoId}/repository/tags/${gitTag}/release`),
urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`),
{json: true, headers: {'Private-Token': gitlabToken}, body: {tag_name: gitTag, description: notes}} // eslint-disable-line camelcase
);
} catch (err) {
Expand All @@ -30,7 +31,7 @@ module.exports = async (pluginConfig, {repositoryUrl}, {gitHead, gitTag, notes},
throw err;
}
debug('Create git tag %o with commit %o and release description', gitTag, gitHead);
await got.post(urlJoin(gitlabUrl, gitlabApiPathPrefix, `/projects/${repoId}/repository/tags/${gitTag}/release`), {
await got.post(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`), {
json: true,
headers: {'PRIVATE-TOKEN': gitlabToken},
body: {tag_name: gitTag, ref: gitHead, release_description: notes}, // eslint-disable-line camelcase
Expand Down
6 changes: 4 additions & 2 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ module.exports = async (pluginConfig, {repositoryUrl}, logger) => {
);
}

logger.log('Verify GitLab authentication (%s)', urlJoin(gitlabUrl, gitlabApiPathPrefix));
const apiUrl = urlJoin(gitlabUrl, gitlabApiPathPrefix);

logger.log('Verify GitLab authentication (%s)', apiUrl);

let projectAccess;
let groupAccess;

try {
({body: {permissions: {project_access: projectAccess, group_access: groupAccess}}} = await got.get(
urlJoin(gitlabUrl, gitlabApiPathPrefix, `/projects/${encodeURIComponent(repoId)}`),
urlJoin(apiUrl, `/projects/${encodeURIComponent(repoId)}`),
{json: true, headers: {'Private-Token': gitlabToken}}
));
} catch (err) {
Expand Down

0 comments on commit 8d87b4b

Please sign in to comment.