-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding support for Package Registry API
- Loading branch information
1 parent
f07403a
commit 0255a0e
Showing
9 changed files
with
158 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { BaseService } from '@gitbeaker/requester-utils'; | ||
import { RequestHelper, Sudo } from '../infrastructure'; | ||
|
||
export class PackageRegistry<C extends boolean = false> extends BaseService<C> { | ||
publish( | ||
projectId: string | number, | ||
packageName: string, | ||
packageVersion: string, | ||
filename: string, | ||
content: string, | ||
options?: { status?: 'default' | 'hidden' }, | ||
) { | ||
const pId = encodeURIComponent(projectId); | ||
|
||
return RequestHelper.put<{ message: string }>()( | ||
this, | ||
`projects/${pId}/packages/generic/${packageName}/${packageVersion}/${filename}`, | ||
{ | ||
isForm: true, | ||
file: [content, { filename }], | ||
...options, | ||
}, | ||
); | ||
} | ||
|
||
download( | ||
projectId: string | number, | ||
packageName: string, | ||
packageVersion: string, | ||
filename: string, | ||
options?: Sudo, | ||
) { | ||
const pId = encodeURIComponent(projectId); | ||
|
||
return RequestHelper.get<{ message: string }>()( | ||
this, | ||
`projects/${pId}/packages/generic/${packageName}/${packageVersion}/${filename}`, | ||
options, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { RequestHelper } from '../../../src/infrastructure'; | ||
import { PackageRegistry } from '../../../src'; | ||
|
||
jest.mock( | ||
'../../../src/infrastructure/RequestHelper', | ||
() => require('../../__mocks__/RequestHelper').default, | ||
); | ||
|
||
let service: PackageRegistry; | ||
|
||
beforeEach(() => { | ||
service = new PackageRegistry({ | ||
requesterFn: jest.fn(), | ||
token: 'abcdefg', | ||
requestTimeout: 3000, | ||
}); | ||
}); | ||
|
||
describe('Instantiating PackageRegistry service', () => { | ||
it('should create a valid service object', () => { | ||
expect(service).toBeInstanceOf(PackageRegistry); | ||
expect(service.url).toBeDefined(); | ||
expect(service.rejectUnauthorized).toBeTruthy(); | ||
expect(service.headers).toMatchObject({ 'private-token': 'abcdefg' }); | ||
expect(service.requestTimeout).toBe(3000); | ||
}); | ||
}); | ||
|
||
describe('PackageRegistry.publish', () => { | ||
it('should request PUT projects/:projectId/packages/generic/:packageName/:packageVersion/:filename', async () => { | ||
await service.publish(1, 'name', 'v1.0', 'filename.txt', 'content'); | ||
|
||
expect(RequestHelper.put()).toHaveBeenCalledWith( | ||
service, | ||
`projects/1/packages/generic/name/v1.0/filename.txt`, | ||
{ | ||
isForm: true, | ||
file: ['content', { filename: 'filename.txt' }], | ||
}, | ||
); | ||
}); | ||
}); | ||
|
||
describe('PackageRegistry.download', () => { | ||
it('should request GET projects/:projectId/packages/generic/:packageName/:packageVersion/:filename', async () => { | ||
await service.download(1, 'name', 'v1.0', 'filename.txt'); | ||
|
||
expect(RequestHelper.get()).toHaveBeenCalledWith( | ||
service, | ||
`projects/1/packages/generic/name/v1.0/filename.txt`, | ||
undefined, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters