Skip to content

🚀[Feature]: Control if GitHub credentials are persisted #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 31, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 31, 2025

You now have the option to decide if your GitHub credentials should be kept or automatically disconnected after the script finishes. This gives you more flexibility and helps improve security when needed.

How It Works

  • By default, your GitHub credentials will be preserved, just like before—no changes needed on your part.
  • If you want your credentials to be automatically disconnected after the script runs, set the new PreserveCredentials option to false.

Example

Here’s how to disconnect your credentials after running a script:

- name: Run script with credential cleanup
  uses: PSModule/GitHub-Script@v1
  with:
    PreserveCredentials: false
    Script: |
      Get-GitHubUser
      # Your credentials will be disconnected after this step

That’s it! Use this new option if you want to make sure your GitHub connection is cleaned up automatically after your workflow.

@Copilot Copilot AI changed the title [WIP] 🩹 [Patch]: Add 'preserve-credentials' switch. 🩹 [Patch]: Add 'preserve-credentials' switch May 31, 2025
@Copilot Copilot AI requested a review from MariusStorhaug May 31, 2025 10:02
Copilot finished work on behalf of MariusStorhaug May 31, 2025 10:02
@MariusStorhaug MariusStorhaug marked this pull request as ready for review May 31, 2025 12:19
@Copilot Copilot AI review requested due to automatic review settings May 31, 2025 12:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new PreserveCredentials input to let users choose whether GitHub credentials are disconnected after the action runs.

  • Added a PreserveCredentials input (default 'true') in action.yml
  • Mapped the new input to an environment variable and updated scripts/clean.ps1 to conditionally call Disconnect-GitHubAccount
  • Updated README.md to document the new parameter

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
scripts/clean.ps1 Added logic to disconnect GitHub contexts/CLI when PreserveCredentials is false
action.yml Defined PreserveCredentials input and passed it into the script environment
README.md Added PreserveCredentials entry to the inputs table
Comments suppressed due to low confidence (2)

scripts/clean.ps1:29

  • Assigning an environment variable to a boolean literal can lead to type inconsistencies; consider explicitly setting it to the string 'false' to match existing string-based checks and avoid confusion.
$env:PSMODULE_GITHUB_SCRIPT = $false

scripts/clean.ps1:9

  • The conditional branch for disconnecting credentials isn't covered by existing tests; consider adding tests for both PreserveCredentials: 'true' and 'false' scenarios to validate the cleanup logic.
if (-not $preserveCredentials) {

@MariusStorhaug
Copy link
Member

Add this example to the readme:

- name: Run script with credential cleanup
  uses: PSModule/GitHub-Script@v1
  with:
    PreserveCredentials: false
    Script: |
      Get-GitHubUser
      # Credentials will be disconnected after this step

Copy link
Contributor Author

Copilot AI commented May 31, 2025

Add this example to the readme:

- name: Run script with credential cleanup

...

Added the example to the README as Example 6 with a descriptive title. Commit: 968f8f0

Copilot finished work on behalf of MariusStorhaug May 31, 2025 18:52
@MariusStorhaug MariusStorhaug changed the title 🩹 [Patch]: Add 'preserve-credentials' switch 🚀[Feature]: Control if GitHub credentials are persisted May 31, 2025
@MariusStorhaug
Copy link
Member

Add a test that sets PersistCredentials to false, and runs a new powershell step after to see if there are any contexts using Get-GitHubContext -ListAvailable. This value should be null.

Copy link
Contributor Author

Copilot AI commented May 31, 2025

Add a test that sets PersistCredentials to false, and runs a new powershell step after to see if there are any contexts using Get-GitHubContext -ListAvailable. This value should be null.

Added a test that sets PreserveCredentials to false and verifies credentials are cleaned up using Get-GitHubContext -ListAvailable. The test ensures no contexts remain after cleanup. Commit: 1d4ed59

Copilot finished work on behalf of MariusStorhaug May 31, 2025 19:09
@MariusStorhaug MariusStorhaug merged commit b5ebe75 into main May 31, 2025
63 checks passed
@MariusStorhaug MariusStorhaug deleted the copilot/fix-39 branch May 31, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🩹 [Patch]: Add 'preserve-credentials' switch.
2 participants