Skip to content

fix: added support for generic package name #879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Rechem
Copy link

@Rechem Rechem commented Jul 29, 2025

The current version of this project doesn't support custom generic packages names, instead publishes them under the release package.

When publishing generic packages to the package repository on Gitlab, you are able to specify the name of your package in the URL : /projects/:id/packages/generic/:package_name/:package_version/:file_name

I added the ability to provide a custom package name through the optional packageName property.

Usage example:

{
  "branches": ["main"],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/gitlab",
      {
        "gitlabUrl": "https://custom.gitlab.com",
        "assets": [
          { "path": "dist/asset.min.js", "label": "JS distribution", "target": "generic_package", "packageName": "styles" },
        ]
      }
    ]
  ]
}

This will create a new styles package in the Gitlab package repository with the specified files.

@fgreinacher fgreinacher requested a review from Copilot August 1, 2025 18:43
Copilot

This comment was marked as outdated.

@Rechem Rechem requested a review from Copilot August 7, 2025 08:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for custom package names when publishing to GitLab's generic package registry, allowing users to specify a packageName property instead of defaulting to "release".

  • Introduces packageName property for generic package assets with "release" as the default value
  • Updates URL construction to use the custom package name in API endpoints
  • Adds comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/publish.js Implements packageName support with template processing and URL encoding
test/publish.test.js Adds test case for custom packageName functionality
README.md Documents the new packageName property in the assets table
test/helpers/mock-gitlab.js Code style formatting changes (single to double quotes)
test/fixtures/files/file.css Formatting change for CSS test fixture
lib/definitions/errors.js Code style formatting changes (single to double quotes)
lib/definitions/constants.js Code style formatting changes (single to double quotes)

Comment on lines +198 to +200
const encodedLabel = encodeURIComponent(generic.label);
const encodedPackageName = encodeURIComponent(generic.packageName);
const expectedUrl = `https://gitlab.com/api/v4/projects/${encodedProjectPath}/packages/generic/${encodedPackageName}/${encodedVersion}/${encodedLabel}`;
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expectedUrl construction is inconsistent with the actual upload endpoint. The test uses encodedLabel in the URL construction but the upload endpoint uses the filename from the file path. This could cause the test to pass incorrectly if the label and filename differ.

Suggested change
const encodedLabel = encodeURIComponent(generic.label);
const encodedPackageName = encodeURIComponent(generic.packageName);
const expectedUrl = `https://gitlab.com/api/v4/projects/${encodedProjectPath}/packages/generic/${encodedPackageName}/${encodedVersion}/${encodedLabel}`;
const encodedFilename = encodeURIComponent(require("path").basename(generic.path));
const encodedPackageName = encodeURIComponent(generic.packageName);
const expectedUrl = `https://gitlab.com/api/v4/projects/${encodedProjectPath}/packages/generic/${encodedPackageName}/${encodedVersion}/${encodedFilename}`;

Copilot uses AI. Check for mistakes.

.reply(200);
const gitlabUpload = authenticate(env)
.put(
`/projects/${encodedProjectPath}/packages/generic/${encodedPackageName}/${encodedVersion}/${encodedLabel}?status=${generic.status}&select=package_file`,
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upload endpoint uses encodedLabel as the filename parameter, but according to GitLab's generic package API, this should be the actual filename from the file path, not the label. The label is metadata while the filename should match the actual file being uploaded.

Suggested change
`/projects/${encodedProjectPath}/packages/generic/${encodedPackageName}/${encodedVersion}/${encodedLabel}?status=${generic.status}&select=package_file`,
`/projects/${encodedProjectPath}/packages/generic/${encodedPackageName}/${encodedVersion}/${encodedFilename}?status=${generic.status}&select=package_file`,

Copilot uses AI. Check for mistakes.

@fgreinacher
Copy link
Contributor

@Rechem Thanks for the PR. This looks very similar to #607 or do I miss something here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants