Skip to content

Commit

Permalink
fix: add branch name template
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Jun 12, 2024
1 parent bd785bd commit cdffb62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface UserConfig {
projectId: string | undefined;
assets: Assets[] | undefined;
commitTitle: string | undefined;
branchName: string | undefined;
}

export interface Assets {
Expand All @@ -22,6 +23,7 @@ export interface PluginConfig {
gitlabToken: string;
assets: Assets[];
commitTitle: string;
branchName: string;
}

export function resolvePluginConfig(userConfig: UserConfig, context: VerifyConditionsContext): PluginConfig {
Expand All @@ -37,13 +39,15 @@ 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),
gitlabProjectId: projectId,
gitlabToken: gitlabToken,
assets: assets,
commitTitle: commitTitle,
branchName: branchName,
}
return assertPluginConfig(pluginConfig);
}
Expand Down
16 changes: 11 additions & 5 deletions lib/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down

0 comments on commit cdffb62

Please sign in to comment.