Skip to content

Commit 7eecd65

Browse files
authored
Re-enabling attempt to delete environment (#89)
* Re-enabling attempt to delete environment, and log a message with explanations if cannot be done
1 parent 27cbbc5 commit 7eecd65

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ inputs:
1919
description: "Label to use for triggering preview deployments"
2020
default: "pullpreview"
2121
github_token:
22-
description: "The personal access token used to update the status of your commit"
22+
description: "The GitHub access token used to perform GitHub API operations. A custom token is only required for auto-cleanup of GitHub environment objects."
2323
default: "${{ github.token }}"
2424
admins:
2525
description: "Logins of GitHub users that will have their SSH key installed on the instance, comma-separated"

lib/pull_preview/github_sync.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ def self.destroy_environment(repo, environment)
109109
deploys.each do |deployment|
110110
PullPreview.octokit.delete(deployment.url)
111111
end
112-
# This requires repository permission, which the GitHub Action token cannot get, so cannot delete the environment unfortunately
113-
# PullPreview.octokit.delete_environment(repo, environment)
112+
# This requires repository permission, which the default GitHub Action token cannot get, so this will fail if the github_token input is not used.
113+
# Logging a warning message to let the user know that he will have to clean the environment manually.
114+
begin
115+
PullPreview.octokit.delete_environment(repo, environment)
116+
rescue Octokit::Error => e
117+
PullPreview.logger.warn "Unable to destroy the environment #{environment.inspect}: #{e.message}. To destroy the environment object on GitHub, you will have to manually delete it from the GitHub UI, or pass a GitHub token with repository permissions to the action. This does not affect the cleaning of instances, only the GitHub environment object."
118+
end
114119
rescue => e
115-
PullPreview.logger.warn "Unable to destroy environment #{environment.inspect}: #{e.message}"
120+
PullPreview.logger.error "Unable to destroy environment #{environment.inspect}: #{e.message}"
116121
end
117122

118123
def initialize(github_context, app_path, opts = {})

0 commit comments

Comments
 (0)