diff --git a/lib/plugin.ts b/lib/plugin.ts index 7ccbade..c51d742 100644 --- a/lib/plugin.ts +++ b/lib/plugin.ts @@ -10,6 +10,7 @@ export interface UserConfig { projectId: string | undefined; assets: Assets[] | undefined; commitTitle: string | undefined; + branchName: string | undefined; } export interface Assets { @@ -22,6 +23,7 @@ export interface PluginConfig { gitlabToken: string; assets: Assets[]; commitTitle: string; + branchName: string; } export function resolvePluginConfig(userConfig: UserConfig, context: VerifyConditionsContext): PluginConfig { @@ -37,6 +39,7 @@ export function resolvePluginConfig(userConfig: UserConfig, context: VerifyCondi } const assets = userConfig.assets || []; const commitTitle = userConfig.commitTitle || 'chore(release): ${nextRelease.name} [skip ci]'; + const branchName = userConfig.branchName || 'assets/${commit.short}'; const pluginConfig: PluginConfig = { gitlabBaseUrl: urlJoin(gitlabUrl, 'api/v4', 'projects', projectId), @@ -44,6 +47,7 @@ export function resolvePluginConfig(userConfig: UserConfig, context: VerifyCondi gitlabToken: gitlabToken, assets: assets, commitTitle: commitTitle, + branchName: branchName, } return assertPluginConfig(pluginConfig); } diff --git a/lib/publish.ts b/lib/publish.ts index c6094ae..7b49a5f 100644 --- a/lib/publish.ts +++ b/lib/publish.ts @@ -80,15 +80,21 @@ function isAffordableError(error: AxiosError, context: PublishContext): boolean async function makeCommitRequestBody(config: PluginConfig, context: PublishContext) { const publishConfig = resolvePublishConfig(); - const commitMessage = template(config.commitTitle)({ - branch: context.branch, + const templateVariables = { + branch: context.branch.name, lastRelease: context.lastRelease, - nextRelease: context.nextRelease - }); + nextRelease: context.nextRelease, + commit: { + short: publishConfig.commitSha.substring(0, 8), + full: publishConfig.commitSha, + } + }; + const commitMessage = template(config.commitTitle)(templateVariables); + const branchName = template(config.branchName)(templateVariables); // https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions const body = { - branch: `assets/${publishConfig.commitSha.substring(0, 8)}`, + branch: branchName, start_branch: context.branch.name, commit_message: commitMessage, actions: [],