Skip to content

Commit 4cac5a4

Browse files
authored
Use base URL of GitLab for the /uploads URLs (#1482)
* Use base URL of GitLab for the `/uploads` URLs * Update gitlab.js * Fix non-native uploads * fixup! Fix non-native uploads * fixup! Fix non-native uploads * Update gitlab.yml * Update gitlab.yml
1 parent 95e931d commit 4cac5a4

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

bin/cml/asset/publish.e2e.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('CML e2e', () => {
125125
'assets/test.svg'
126126
);
127127

128-
expect(output.startsWith('https://')).toBe(true);
128+
expect(output.startsWith('/uploads/')).toBe(true);
129129
});
130130

131131
test('cml publish /nonexistent produces file error', async () => {

src/cml.e2e.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ describe('Gitlab tests', () => {
144144
native: true
145145
});
146146

147-
expect(output.startsWith('https://')).toBe(true);
148-
expect(output.includes('cml=png')).toBe(true);
147+
expect(output.startsWith('/uploads/')).toBe(true);
148+
expect(output.includes('cml=png')).toBe(false);
149149
});
150150

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

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

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

178-
expect(output.startsWith(`[${title}](https://`)).toBe(true);
178+
expect(output.startsWith(`[${title}](/uploads/`)).toBe(true);
179179
expect(output.endsWith(')')).toBe(true);
180-
expect(output.includes('cml=pdf')).toBe(true);
180+
expect(output.includes('cml=pdf')).toBe(false);
181181
});
182182

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

194-
expect(output.startsWith(`[${title}](https://`)).toBe(true);
194+
expect(output.startsWith(`[${title}](/uploads/`)).toBe(true);
195195
expect(output.endsWith(')')).toBe(true);
196-
expect(output.includes('cml=pdf')).toBe(true);
196+
expect(output.includes('cml=pdf')).toBe(false);
197197
});
198198

199199
test('Publish should fail with an invalid driver', async () => {

src/cml.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,14 @@ class CML {
346346
({ mime, uri } = await upload(opts));
347347
}
348348

349-
if (!rmWatermark) {
349+
if (!rmWatermark && !native) {
350350
const [, type] = mime.split('/');
351351
uri = watermarkUri({ uri, type });
352352
}
353353

354-
uri = preventcacheUri({ uri });
354+
if (!native) {
355+
uri = preventcacheUri({ uri });
356+
}
355357

356358
if (md && mime.match('(image|video)/.*'))
357359
return `![](${uri}${title ? ` "${title}"` : ''})`;

src/drivers/gitlab.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ class Gitlab {
131131
}
132132

133133
async upload(opts = {}) {
134-
const { repo } = this;
135-
136134
const projectPath = await this.projectPath();
137135
const endpoint = `/projects/${projectPath}/uploads`;
138136
const { size, mime, data } = await fetchUploadData(opts);
@@ -141,7 +139,7 @@ class Gitlab {
141139

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

144-
return { uri: `${repo}${url}`, mime, size };
142+
return { uri: url, mime, size };
145143
}
146144

147145
async runnerToken(body) {

0 commit comments

Comments
 (0)