ICRAR / EAGLE

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

EAGLE-1266: Add developer setting to load repo containing the graph from the URL #771

Open james-strauss-uwa opened 2 days ago

james-strauss-uwa commented 2 days ago

If the new setting is enabled, then when EAGLE "autoloads" a graph from the URL, it will also fetch the contents of the repository the graph is from.

If the repository is not already in EAGLE's list of repositories, then nothing extra will happen.

I also improved the GitLab and GitHub repository list-building functions to use async/await, so that "fetching the contents" of the repo can be done AFTER the repository list has been fully build. Previously, if the repository list took longer than usual to read from localStorage, or fetch from the EAGLE server, then EAGLE would attempt to load the repo contents before the repo was in EAGLE's list of repositories, which would fail.

I also snuck in a new setting to enable/disable printing the JSON sent to the translator to the javascript console. This just cleans up the console a little during normal operation.

Summary by Sourcery

Add a developer setting to load repositories from URLs and improve repository list handling with async/await.

New Features:

Enhancements:

sourcery-ai[bot] commented 2 days ago

Reviewer's Guide by Sourcery

This PR implements a new developer setting that allows EAGLE to automatically fetch repository contents when loading a graph from a URL. The implementation includes a significant refactoring of the GitHub and GitLab repository loading logic to use async/await, improving the reliability of repository loading. Additionally, a new developer setting was added to control the visibility of translator JSON in the console.

Sequence diagram for repository loading process

sequenceDiagram
    actor User
    participant EAGLE
    participant GitHub
    participant GitLab
    participant Repositories
    participant localStorage

    User->>EAGLE: Load graph from URL
    EAGLE->>GitHub: loadRepoList()
    GitHub->>Repositories: Fetch repositories
    GitHub->>localStorage: Fetch custom repositories
    localStorage-->>GitHub: Return custom repositories
    GitHub-->>Repositories: Return repositories
    EAGLE->>GitLab: loadRepoList()
    GitLab->>Repositories: Fetch repositories
    GitLab->>localStorage: Fetch custom repositories
    localStorage-->>GitLab: Return custom repositories
    GitLab-->>Repositories: Return repositories
    Repositories->>EAGLE: Update repository list
    EAGLE->>User: Graph loaded with repository contents

Updated class diagram for repository management

classDiagram
    class GitHub {
        +async refresh()
        +async loadRepoList() Promise<Repository[]>
    }
    class GitLab {
        +async refresh()
        +async loadRepoList() Promise<Repository[]>
    }
    class Repositories {
        +static listCustomRepositories(service: Repository.Service) Repository[]
        +addCustomRepository()
    }
    class Setting {
        +static FETCH_REPOSITORY_FOR_URLS
        +static PRINT_TRANSLATOR_JSON_TO_JS_CONSOLE
    }
    GitHub --> Repositories
    GitLab --> Repositories
    Repositories --> Setting
    Repositories --> GitHub
    Repositories --> GitLab
    Setting <.. Repositories: uses
    Setting <.. GitHub: uses
    Setting <.. GitLab: uses
    note for GitHub "Refactored to use async/await"
    note for GitLab "Refactored to use async/await"
    note for Repositories "New method for listing custom repositories"

File-Level Changes

Change Details Files
Refactored repository loading logic to use async/await pattern
  • Converted loadRepoList functions to return Promises
  • Created new refresh methods to handle repository list updates
  • Extracted common repository loading logic into a shared method
  • Improved error handling in repository loading functions
src/GitHub.ts
src/GitLab.ts
Added new developer settings for repository loading and console output
  • Added FETCH_REPOSITORY_FOR_URLS setting to control automatic repository loading
  • Added PRINT_TRANSLATOR_JSON_TO_JS_CONSOLE setting to control console output
  • Updated settings group with new options
src/Setting.ts
Modified repository and graph loading sequence
  • Created new loadRepos async function to handle repository initialization
  • Updated autoLoad function to support fetching repository contents
  • Modified main initialization sequence to properly handle async loading
src/main.ts
Improved translator console output handling
  • Made translator JSON console output conditional based on new setting
  • Cleaned up and organized console output formatting
src/Translator.ts

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
james-strauss-uwa commented 2 days ago

Yes, I think we could also open the folder hierarchy down to the graph's location. I'll add that.

I guess we could also add the repo if it doesn't exist. I'll probably add it permanently, rather than temporarily.

james-strauss-uwa commented 12 hours ago

OK, I've added:

Note: the existing error messages are shown when: