ICRAR / EAGLE

Editor for the Astronomical Graph Language Environment
GNU Lesser General Public License v3.0
0 stars 1 forks source link

EAGLE-1268: Delete files from git repositories within EAGLE #742

Closed james-strauss-uwa closed 1 month ago

james-strauss-uwa commented 1 month ago

Adds a "trash can" icon next to each file in the repository tab. Clicking the icon deletes the file from the repository.

There is a user confirmation step before the deletion. The confirmation step can be skipped using a new setting CONFIRM_DELETE_FILES.

Both GitLab and GitHub repositories are supported.

Once the file is deleted, we could trigger a refresh of the repository listing to visualise the change, but that is slow. So instead we just remove the file from the client-side repository file hierarchy, assuming this will exactly mirror the state of the remote repository.

Considered adding a "delete directory" button, but git directories only exist when a file exists within them. So removing all files from a directory will delete the directory from git.

Every delete results in one commit to the repository.

Summary by Sourcery

Add functionality to delete files from GitHub and GitLab repositories within EAGLE, including a user confirmation step and client-side updates to the file hierarchy.

New Features:

Enhancements:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request implements a new feature to delete files from Git repositories (both GitHub and GitLab) within the EAGLE application. The changes include adding a "trash can" icon next to each file in the repository tab, implementing the deletion functionality on both client and server sides, and adding a user confirmation step that can be skipped using a new setting.

Sequence Diagram

sequenceDiagram
    participant User
    participant UI
    participant Eagle
    participant GitHub/GitLab
    participant Server
    User->>UI: Click delete icon
    UI->>Eagle: deleteRemoteFile()
    Eagle->>User: Confirm deletion
    User->>Eagle: Confirm
    Eagle->>GitHub/GitLab: deleteRemoteFile()
    GitHub/GitLab->>Server: HTTP POST /deleteRemoteGithubFile or /deleteRemoteGitlabFile
    Server->>GitHub/GitLab API: Delete file
    GitHub/GitLab API-->>Server: Response
    Server-->>GitHub/GitLab: Response
    GitHub/GitLab-->>Eagle: Callback
    Eagle->>UI: Update repository view

File-Level Changes

Change Details Files
Implement file deletion functionality for GitHub repositories
  • Add a new Flask route '/deleteRemoteGithubFile' to handle file deletion requests
  • Implement the deletion logic using the GitHub API
  • Handle potential errors and return appropriate responses
eagleServer/eagleServer.py
Implement file deletion functionality for GitLab repositories
  • Add a new Flask route '/deleteRemoteGitlabFile' to handle file deletion requests
  • Implement the deletion logic using the GitLab API
  • Handle potential errors and return appropriate responses
eagleServer/eagleServer.py
Add client-side file deletion functionality in the Eagle class
  • Implement deleteRemoteFile method to handle user confirmation and trigger deletion
  • Add _deleteRemoteFile private method to perform the actual deletion based on repository service
  • Update the repository file hierarchy after successful deletion
src/Eagle.ts
Extend Repository class to support file deletion
  • Add deleteFile method to remove files from the repository structure
  • Implement logic to remove empty folders after file deletion
src/Repository.ts
Add file deletion support for GitHub and GitLab services
  • Implement deleteRemoteFile static method in GitHub class
  • Implement deleteRemoteFile static method in GitLab class
  • Handle access token validation and API requests for both services
src/GitHub.ts
src/GitLab.ts
Add new setting for file deletion confirmation
  • Create new CONFIRM_DELETE_FILES setting
  • Update settings initialization to include the new setting
  • Add the new setting to the reset action confirmations method
src/Setting.ts
Update UI to include delete icon for repository files
  • Add a new column with a trash can icon to the repository file component
  • Bind the deleteRemoteFile action to the new icon
static/components/repository-file.html

Tips and commands - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.