Skip to content
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

fix(assets): changed generation of gitlab release asset url #754

Closed
wants to merge 0 commits into from

Conversation

aldenbe
Copy link
Contributor

@aldenbe aldenbe commented Jul 23, 2024

fix(assets): changed generation of gitlab release asset url when providing file assets with target project_upload to point to url for the uploaded file

#753

Copy link
Contributor

@JonasSchubert JonasSchubert left a comment

Choose a reason for hiding this comment

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

Let's also discuss a bit in the issue ;)

lib/publish.js Outdated
@@ -149,7 +149,8 @@ export default async (pluginConfig, context) => {
throw error;
}

const { url, alt } = response;
const { alt } = response;
const url = urlJoin(gitlabUrl, response["full_path"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks the unit tests. Can you locally run npm run test.

Suggested change
const url = urlJoin(gitlabUrl, response["full_path"]);
const url = urlJoin(gitlabUrl, response.full_path);

In ln. 177 we are already building the url for the assets using urlJoin(gitlabUrl, repoId, url).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aldenbe aldenbe force-pushed the master branch 3 times, most recently from 3bd8cce to 1d4d173 Compare July 27, 2024 04:34
@@ -56,7 +56,7 @@ test.serial("Publish a release with templated path", async (t) => {
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const generic = { path: "${env.FIXTURE}.txt", filepath: "/upload.txt" };
const assets = [generic];
const uploaded = { url: "/uploads/upload.txt", alt: "upload.txt" };
const uploaded = getUploadResponse(generic.filepath, encodedRepoId);
Copy link
Contributor

@fgreinacher fgreinacher Jul 29, 2024

Choose a reason for hiding this comment

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

I would prefer to keep the test cases self-contained and hardcode the upload responses like we do for most other test data.

That would also keep amount of changes minimal.

Copy link
Contributor Author

@aldenbe aldenbe Jul 30, 2024

Choose a reason for hiding this comment

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

It is my opinion that using a helper function to mimic the gitlab api endpoint responses offers the following benefits over hardcoded values.

  1. Increased readability. It is more clear what determines the url values passed to the simulated release endpoint which are programatically generated by gitlab and not semantic-release it also removes the implication of some variables being treated as a gitlab response which are not actually contained in response data from the gitlab markdown upload endpoint. see parameters expected in release request taken from variable uploaded not supplied by gitlab markdown upload endpoint and uploaded implied to be a response from the gitlab markdown upload endpoint
  2. Increased maintainability. Should gitlab change their endpoint (again) updates need only to be made to the mocked gitlab upload endpoint instead of each test case being updated individually.
  3. Increased reliability. Although no test case currently exists, breakages potentially caused by the gitlab upload behavior of only using the file name and ignoring the file path would be more easily detected by mimicking the gitlab endpoint response than relying on hardcoded values and expecting developers to properly account for this, especially given that as far as I can tell this behavior is not actually documented anywhere (including in gitlab's documentation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gitlab response handling in publish.js would also contain the unexpected variables in point 1, which makes that point both a readability and reliability concern.

Copy link
Contributor

@fgreinacher fgreinacher Jul 30, 2024

Choose a reason for hiding this comment

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

Thanks for providing your reasoning @aldenbe, it's very clear!

I do agree with you in general, but seeing that we have many other similar places where we "hardcode" responses, e.g.

gitlab/test/publish.test.js

Lines 181 to 182 in 4554f49

const uploaded = { file: { url: "http://aws.example.com/bucket/gitlab/file.css" } };
const generic = { path: "file.css", label: "Style package", target: "generic_package", status: "hidden" };
I would prefer to keep that style in this PR.

I would however be very open to accept a PR that refactors all the responses towards the style you suggest here. Would you be willing to give that a try? Also fine if you start with what you already have and we finish it for the other responses.

@JonasSchubert WDYT?

Copy link
Contributor Author

@aldenbe aldenbe Jul 30, 2024

Choose a reason for hiding this comment

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

Simplified PR explicitly addressing this issue created #755

Unfortunately I have spent too much time on this already. Feel free to take anything desired from https://github.com/aldenbe/semantic-release-gitlab/tree/gitlab-mock-upload-endpoint and use it as you please.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks again @aldenbe for your work and fix.
I agree with @fgreinacher to keep the context of PRs to one topic to avoid too many changes in one. This usually helps to review a PR. I would be happy to see you create a second PR with your changes for the tests, @aldenbe. This can indeed improve readability. I understand if you have no time for this now, but if you would like to tackle that in the future it would be appreciated.

Copy link
Contributor

@fgreinacher fgreinacher left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @aldenbe, greatly appreciated!

The fix itself looks perfect, but I'd prefer to keep the existing test structure.

Also we have some lint issues, see https://github.com/semantic-release/gitlab/actions/runs/10120894480/job/28034084391?pr=754. You should be able to fix them via npm run lint:fix.

@aldenbe
Copy link
Contributor Author

aldenbe commented Jul 30, 2024

Thanks for your contribution @aldenbe, greatly appreciated!

The fix itself looks perfect, but I'd prefer to keep the existing test structure.

Also we have some lint issues, see https://github.com/semantic-release/gitlab/actions/runs/10120894480/job/28034084391?pr=754. You should be able to fix them via npm run lint:fix.

https://github.com/semantic-release/gitlab/compare/1d4d17336b77aaa8ecdc58174cfcacda12e673be..35c76790fbe11d88f8c968c180a062964e562e21

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.

3 participants