Add topics input to publish:github action

This change adds an array input of topics to attach on a repository upon
creation.

Signed-off-by: Crevil <bjoern.soerensen@gmail.com>
This commit is contained in:
Crevil
2021-06-16 13:31:00 +02:00
parent dd99f8e380
commit 878c1851d4
4 changed files with 61 additions and 0 deletions
@@ -19,6 +19,7 @@ export const mockGithubClient = {
createInOrg: jest.fn(),
createForAuthenticatedUser: jest.fn(),
addCollaborator: jest.fn(),
replaceAllTopics: jest.fn(),
},
users: {
getByUsername: jest.fn(),
@@ -341,6 +341,39 @@ describe('publish:github', () => {
]);
});
it('should add topics when provided', async () => {
mockGithubClient.users.getByUsername.mockResolvedValue({
data: { type: 'User' },
});
mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({
data: {
clone_url: 'https://github.com/clone/url.git',
html_url: 'https://github.com/html/url',
},
});
mockGithubClient.repos.replaceAllTopics.mockResolvedValue({
data: {
names: ['node.js'],
},
});
await action.handler({
...mockContext,
input: {
...mockContext.input,
topics: ['node.js'],
},
});
expect(mockGithubClient.repos.replaceAllTopics).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repo',
names: ['node.js'],
});
});
it('should call output with the remoteUrl and the repoContentsUrl', async () => {
mockGithubClient.users.getByUsername.mockResolvedValue({
data: { type: 'User' },
@@ -48,6 +48,7 @@ export function createPublishGithubAction(options: {
sourcePath?: string;
repoVisibility: 'private' | 'internal' | 'public';
collaborators: Collaborator[];
topics?: string[];
}>({
id: 'publish:github',
description:
@@ -99,6 +100,14 @@ export function createPublishGithubAction(options: {
},
},
},
topics: {
title: 'Topics',
description: 'Uppercase letters no allowed',
type: 'array',
items: {
type: 'string',
},
},
},
},
output: {
@@ -122,6 +131,7 @@ export function createPublishGithubAction(options: {
access,
repoVisibility = 'private',
collaborators,
topics,
} = ctx.input;
const { owner, repo, host } = parseRepoUrl(repoUrl);
@@ -215,6 +225,18 @@ export function createPublishGithubAction(options: {
}
}
if (topics) {
try {
await client.repos.replaceAllTopics({
owner,
repo,
names: topics,
});
} catch (e) {
ctx.logger.warn(`Skipping topics ${topics.join(' ')}, ${e.message}`);
}
}
const remoteUrl = newRepo.clone_url;
const repoContentsUrl = `${newRepo.html_url}/blob/master`;