dockerhub: api client to get repo details and update description

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-04 03:06:23 +01:00
parent 556fff451f
commit 96ad2a52f8
4 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
/**
* Copyright 2023 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, expect, jest, it, beforeEach} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import {DockerHub} from '../src/dockerhub';
import {RepositoryResponse} from '../src/types/dockerhub';
beforeEach(() => {
jest.clearAllMocks();
});
import repoInfoFixture from './fixtures/dockerhub-repoinfo.json';
describe('getRepository', () => {
it('returns repo info', async () => {
jest.spyOn(DockerHub.prototype, 'getRepository').mockImplementation((): Promise<RepositoryResponse> => {
return <Promise<RepositoryResponse>>(repoInfoFixture as unknown);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(DockerHub as any, 'login').mockReturnValue('jwt_token');
const dockerhub = await DockerHub.build({
credentials: {
username: 'foo',
password: '0123456-7890-0000-1111-222222222'
}
});
const repoinfo = await dockerhub.getRepository({
namespace: 'foo',
name: 'bar'
});
expect(repoinfo.namespace).toEqual('foo');
expect(repoinfo.name).toEqual('bar');
expect(repoinfo.repository_type).toEqual('image');
});
});
describe('updateRepoDescription', () => {
it.skip('set repo description', async () => {
const dockerhub = await DockerHub.build({
credentials: {
username: 'foo',
password: 'bar'
}
});
const resp = await dockerhub.updateRepoDescription({
namespace: 'crazymax',
name: 'test-toolkit',
description: 'Hello-World',
full_description: fs.readFileSync(path.join(__dirname, '..', 'README.md'), 'utf-8')
});
expect(resp.namespace).toEqual('foo');
expect(resp.name).toEqual('bar');
expect(resp.description).toEqual('Hello-World');
});
});

View File

@@ -0,0 +1,34 @@
{
"user": "foo",
"name": "bar",
"namespace": "foo",
"repository_type": "image",
"status": 1,
"status_description": "active",
"description": "Bar",
"is_private": false,
"is_automated": false,
"can_edit": true,
"star_count": 68,
"pull_count": 178255909,
"last_updated": "2023-02-02T14:22:31.184404Z",
"date_registered": "2019-06-04T20:08:57.306333Z",
"collaborator_count": 0,
"affiliation": "owner",
"hub_user": "foo",
"has_starred": false,
"full_description": "This is the full description of the repo.",
"permissions": {
"read": true,
"write": true,
"admin": true
},
"media_types": [
"application/vnd.docker.container.image.v1+json",
"application/vnd.docker.distribution.manifest.list.v2+json",
"application/vnd.oci.image.index.v1+json"
],
"content_types": [
"image"
]
}