Skip to content

Commit

Permalink
feat(delete-deployment): also delete environment (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored May 18, 2022
1 parent 7564d1c commit 076860d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Each of the following helpers are defined in a file of the same name in `src/hel
* Comments on a pull request or other issue

### [delete-deployment](.github/workflows/deployments.yml#L53)
* Deletes a Github [deployment](https://docs.github.com/en/rest/reference/repos#deployments)
* Deletes a Github [deployment](https://docs.github.com/en/rest/reference/repos#deployments) and [environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#about-environments)

### [filter-paths](.github/workflows/filter-paths.yml)
* Returns `true` if specified file paths have changed for a PR, and `false` otherwise
Expand Down
5 changes: 4 additions & 1 deletion dist/12.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/12.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions src/helpers/delete-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ export const deleteDeployment = async ({ sha, environment }: DeleteDeployment) =
...context.repo,
...GITHUB_OPTIONS
});
return octokit.repos.deleteDeployment({
deployment_id,
...context.repo,
...GITHUB_OPTIONS
});
return Promise.all([
octokit.repos.deleteDeployment({
deployment_id,
...context.repo,
...GITHUB_OPTIONS
}),
octokit.repos.deleteAnEnvironment({
environment_name: environment,
...context.repo,
...GITHUB_OPTIONS
})
]);
}
};
13 changes: 13 additions & 0 deletions test/helpers/delete-deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jest.mock('@actions/github', () => ({
repos: {
createDeploymentStatus: jest.fn(),
deleteDeployment: jest.fn(),
deleteAnEnvironment: jest.fn(),
listDeployments: jest.fn()
}
}
Expand Down Expand Up @@ -79,6 +80,14 @@ describe('deleteDeployment', () => {
...GITHUB_OPTIONS
});
});

it('should call deleteAnEnvironment with correct params', () => {
expect(octokit.repos.deleteAnEnvironment).toHaveBeenCalledWith({
environment_name: environment,
...context.repo,
...GITHUB_OPTIONS
});
});
});

describe('deployment does not exist', () => {
Expand Down Expand Up @@ -108,5 +117,9 @@ describe('deleteDeployment', () => {
it('should not call deleteDeployment', () => {
expect(octokit.repos.deleteDeployment).not.toHaveBeenCalled();
});

it('should not call deleteAnEnvironment', () => {
expect(octokit.repos.deleteAnEnvironment).not.toHaveBeenCalled();
});
});
});

0 comments on commit 076860d

Please sign in to comment.