Merge pull request #21389 from kmarkow/fix-creating-secrets-github-environment-create

Fix creating secrets in github:environment:create action
This commit is contained in:
Ben Lambert
2023-11-20 15:14:38 +01:00
committed by GitHub
4 changed files with 20 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fix creating env secret in github:environment:create action
@@ -25,7 +25,7 @@ import { examples } from './gitHubEnvironment.examples';
const mockOctokit = {
rest: {
actions: {
getRepoPublicKey: jest.fn(),
getEnvironmentPublicKey: jest.fn(),
createEnvironmentVariable: jest.fn(),
createOrUpdateEnvironmentSecret: jest.fn(),
},
@@ -68,7 +68,7 @@ describe('github:environment:create examples', () => {
};
beforeEach(() => {
mockOctokit.rest.actions.getRepoPublicKey.mockResolvedValue({
mockOctokit.rest.actions.getEnvironmentPublicKey.mockResolvedValue({
data: {
key: publicKey,
key_id: 'keyid',
@@ -109,7 +109,9 @@ describe('github:environment:create examples', () => {
expect(
mockOctokit.rest.actions.createEnvironmentVariable,
).not.toHaveBeenCalled();
expect(mockOctokit.rest.actions.getRepoPublicKey).not.toHaveBeenCalled();
expect(
mockOctokit.rest.actions.getEnvironmentPublicKey,
).not.toHaveBeenCalled();
expect(
mockOctokit.rest.actions.createOrUpdateEnvironmentSecret,
).not.toHaveBeenCalled();
@@ -141,7 +143,9 @@ describe('github:environment:create examples', () => {
expect(
mockOctokit.rest.actions.createEnvironmentVariable,
).not.toHaveBeenCalled();
expect(mockOctokit.rest.actions.getRepoPublicKey).not.toHaveBeenCalled();
expect(
mockOctokit.rest.actions.getEnvironmentPublicKey,
).not.toHaveBeenCalled();
expect(
mockOctokit.rest.actions.createOrUpdateEnvironmentSecret,
).not.toHaveBeenCalled();
@@ -24,7 +24,7 @@ import { ScmIntegrations } from '@backstage/integration';
const mockOctokit = {
rest: {
actions: {
getRepoPublicKey: jest.fn(),
getEnvironmentPublicKey: jest.fn(),
createEnvironmentVariable: jest.fn(),
createOrUpdateEnvironmentSecret: jest.fn(),
},
@@ -71,7 +71,7 @@ describe('github:environment:create', () => {
};
beforeEach(() => {
mockOctokit.rest.actions.getRepoPublicKey.mockResolvedValue({
mockOctokit.rest.actions.getEnvironmentPublicKey.mockResolvedValue({
data: {
key: publicKey,
key_id: 'keyid',
@@ -167,10 +167,11 @@ export function createGithubEnvironmentAction(options: {
}
if (secrets) {
const publicKeyResponse = await client.rest.actions.getRepoPublicKey({
owner: owner,
repo: repo,
});
const publicKeyResponse =
await client.rest.actions.getEnvironmentPublicKey({
repository_id: repository.data.id,
environment_name: name,
});
await Sodium.ready;
const binaryKey = Sodium.from_base64(