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

Use base URL of GitLab for the /uploads URLs #1482

Merged
merged 9 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cml/asset/publish.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('CML e2e', () => {
'assets/test.svg'
);

expect(output.startsWith('https://')).toBe(true);
expect(output.startsWith('/uploads/')).toBe(true);
});

test('cml publish /nonexistent produces file error', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/cml.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith('https://')).toBe(true);
expect(output.includes('cml=png')).toBe(true);
expect(output.startsWith('/uploads/')).toBe(true);
expect(output.includes('cml=png')).toBe(false);
});

test('Publish image using gl with markdown', async () => {
Expand All @@ -159,9 +159,9 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith('![](https://')).toBe(true);
expect(output.startsWith('![](/uploads/')).toBe(true);
expect(output.endsWith(` "${title}")`)).toBe(true);
expect(output.includes('cml=png')).toBe(true);
expect(output.includes('cml=png')).toBe(false);
});

test('Publish a non image file using gl in markdown', async () => {
Expand All @@ -175,9 +175,9 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith(`[${title}](https://`)).toBe(true);
expect(output.startsWith(`[${title}](/uploads/`)).toBe(true);
expect(output.endsWith(')')).toBe(true);
expect(output.includes('cml=pdf')).toBe(true);
expect(output.includes('cml=pdf')).toBe(false);
});

test('Publish a non image file using native', async () => {
Expand All @@ -191,9 +191,9 @@ describe('Gitlab tests', () => {
native: true
});

expect(output.startsWith(`[${title}](https://`)).toBe(true);
expect(output.startsWith(`[${title}](/uploads/`)).toBe(true);
expect(output.endsWith(')')).toBe(true);
expect(output.includes('cml=pdf')).toBe(true);
expect(output.includes('cml=pdf')).toBe(false);
});

test('Publish should fail with an invalid driver', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@ class CML {
({ mime, uri } = await upload(opts));
}

if (!rmWatermark) {
if (!rmWatermark && !native) {
const [, type] = mime.split('/');
uri = watermarkUri({ uri, type });
}

uri = preventcacheUri({ uri });
if (!native) {
uri = preventcacheUri({ uri });
}

if (md && mime.match('(image|video)/.*'))
return `![](${uri}${title ? ` "${title}"` : ''})`;
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ class Gitlab {
}

async upload(opts = {}) {
const { repo } = this;

const projectPath = await this.projectPath();
const endpoint = `/projects/${projectPath}/uploads`;
const { size, mime, data } = await fetchUploadData(opts);
Expand All @@ -141,7 +139,7 @@ class Gitlab {

const { url } = await this.request({ endpoint, method: 'POST', body });

return { uri: `${repo}${url}`, mime, size };
return { uri: url, mime, size };
}

async runnerToken(body) {
Expand Down
Loading