Add custom prop functionality

Signed-off-by: Efren Aguilar <efrenaguilar95@hotmail.com>
This commit is contained in:
Efren Aguilar
2024-08-29 15:13:43 -07:00
parent 8f85ab3b04
commit 8eb75423a5
6 changed files with 133 additions and 0 deletions
@@ -287,6 +287,36 @@ describe('publish:github', () => {
has_projects: false,
has_issues: false,
});
await action.handler({
...mockContext,
input: {
...mockContext.input,
customProperties: {
foo: 'bar',
foo2: 'bar2',
},
},
});
expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({
description: 'description',
name: 'repo',
org: 'owner',
private: true,
delete_branch_on_merge: false,
allow_squash_merge: true,
squash_merge_commit_title: 'COMMIT_OR_PR_TITLE',
squash_merge_commit_message: 'COMMIT_MESSAGES',
allow_merge_commit: true,
allow_rebase_merge: true,
allow_auto_merge: false,
visibility: 'private',
custom_properties: {
foo: 'bar',
foo2: 'bar2',
},
});
});
it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => {
@@ -412,6 +442,33 @@ describe('publish:github', () => {
has_projects: false,
has_issues: false,
});
// Custom properties on user repos should be ignored
await action.handler({
...mockContext,
input: {
...mockContext.input,
customProperties: {
foo: 'bar',
foo2: 'bar2',
},
},
});
expect(
mockOctokit.rest.repos.createForAuthenticatedUser,
).toHaveBeenCalledWith({
description: 'description',
name: 'repo',
private: true,
delete_branch_on_merge: false,
allow_squash_merge: true,
squash_merge_commit_title: 'COMMIT_OR_PR_TITLE',
squash_merge_commit_message: 'COMMIT_MESSAGES',
allow_merge_commit: true,
allow_rebase_merge: true,
allow_auto_merge: false,
});
});
it('should call initRepoAndPush with the correct values', async () => {
@@ -115,6 +115,7 @@ export function createPublishGithubAction(options: {
includeClaimKeys?: string[];
};
requiredCommitSigning?: boolean;
customProperties?: { [key: string]: string };
}>({
id: 'publish:github',
description:
@@ -164,6 +165,7 @@ export function createPublishGithubAction(options: {
secrets: inputProps.secrets,
oidcCustomization: inputProps.oidcCustomization,
requiredCommitSigning: inputProps.requiredCommitSigning,
customProperties: inputProps.customProperties,
},
},
output: {
@@ -213,6 +215,7 @@ export function createPublishGithubAction(options: {
secrets,
oidcCustomization,
token: providedToken,
customProperties,
requiredCommitSigning = false,
} = ctx.input;
@@ -253,6 +256,7 @@ export function createPublishGithubAction(options: {
repoVariables,
secrets,
oidcCustomization,
customProperties,
ctx.logger,
);
@@ -235,6 +235,36 @@ describe('github:repo:create', () => {
has_projects: false,
has_issues: false,
});
await action.handler({
...mockContext,
input: {
...mockContext.input,
customProperties: {
foo: 'bar',
foo2: 'bar2',
},
},
});
expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({
description: 'description',
name: 'repo',
org: 'owner',
private: true,
delete_branch_on_merge: false,
allow_squash_merge: true,
squash_merge_commit_title: 'COMMIT_OR_PR_TITLE',
squash_merge_commit_message: 'COMMIT_MESSAGES',
allow_merge_commit: true,
allow_rebase_merge: true,
allow_auto_merge: false,
visibility: 'private',
custom_properties: {
foo: 'bar',
foo2: 'bar2',
},
});
});
it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => {
@@ -360,6 +390,33 @@ describe('github:repo:create', () => {
has_projects: false,
has_issues: false,
});
// Custom properties on user repos should be ignored
await action.handler({
...mockContext,
input: {
...mockContext.input,
customProperties: {
foo: 'bar',
foo2: 'bar2',
},
},
});
expect(
mockOctokit.rest.repos.createForAuthenticatedUser,
).toHaveBeenCalledWith({
description: 'description',
name: 'repo',
private: true,
delete_branch_on_merge: false,
allow_squash_merge: true,
squash_merge_commit_title: 'COMMIT_OR_PR_TITLE',
squash_merge_commit_message: 'COMMIT_MESSAGES',
allow_merge_commit: true,
allow_rebase_merge: true,
allow_auto_merge: false,
});
});
it('should add access for the team when it starts with the owner', async () => {
@@ -100,6 +100,7 @@ export function createGithubRepoCreateAction(options: {
includeClaimKeys?: string[];
};
requireCommitSigning?: boolean;
customProperties?: { [key: string]: string };
}>({
id: 'github:repo:create',
description: 'Creates a GitHub repository.',
@@ -139,6 +140,7 @@ export function createGithubRepoCreateAction(options: {
secrets: inputProps.secrets,
oidcCustomization: inputProps.oidcCustomization,
requiredCommitSigning: inputProps.requiredCommitSigning,
customProperties: inputProps.customProperties,
},
},
output: {
@@ -171,6 +173,7 @@ export function createGithubRepoCreateAction(options: {
repoVariables,
secrets,
oidcCustomization,
customProperties,
token: providedToken,
} = ctx.input;
@@ -211,6 +214,7 @@ export function createGithubRepoCreateAction(options: {
repoVariables,
secrets,
oidcCustomization,
customProperties,
ctx.logger,
);
@@ -148,6 +148,7 @@ export async function createGithubRepoWithCollaboratorsAndTopics(
includeClaimKeys?: string[];
}
| undefined,
customProperties: { [key: string]: string } | undefined,
logger: LoggerService,
) {
// eslint-disable-next-line testing-library/no-await-sync-queries
@@ -179,6 +180,8 @@ export async function createGithubRepoWithCollaboratorsAndTopics(
has_projects: hasProjects,
has_wiki: hasWiki,
has_issues: hasIssues,
// Custom properties only available on org repos
custom_properties: customProperties,
})
: client.rest.repos.createForAuthenticatedUser({
name: repo,
@@ -304,6 +304,13 @@ const oidcCustomization = {
},
};
const customProperties = {
title: 'Custom Repository Properties',
description:
'Custom properties to be added to the repository (note, this only works for organization repositories)',
type: 'object',
};
export { access };
export { allowMergeCommit };
export { allowRebaseMerge };
@@ -342,3 +349,4 @@ export { requiredCommitSigning };
export { repoVariables };
export { secrets };
export { oidcCustomization };
export { customProperties };