diff --git a/.kubecoder/config.yaml b/.kubecoder/config.yaml index eb57d864..689d69de 100644 --- a/.kubecoder/config.yaml +++ b/.kubecoder/config.yaml @@ -14,8 +14,9 @@ tools: memory: 4Gi secrets: - # Permanent token for https://issues.webathome.org. Only for checking the - # YouTrack plugin's REST calls with curl; nothing in the repo reads it. + # Permanent token for https://issues.webathome.org, for checking the YouTrack + # plugin's REST calls with curl and for the live fixture `kc project test` + # runs (read-only). YOUTRACK_API_KEY_SECRET: youtrack-api-key preamble: diff --git a/.kubecoder/project.yaml b/.kubecoder/project.yaml index 1c501ee4..980701ce 100644 --- a/.kubecoder/project.yaml +++ b/.kubecoder/project.yaml @@ -1,9 +1,10 @@ # Curated entry points for TQL. Schema: https://kubecoder.home/help/reference/project-yaml/ # -# Every project in Tql.sln targets net8.0-windows (WPF + WinForms). It compiles on Linux -# through EnableWindowsTargeting (Directory.Build.props) with Microsoft's SDK, but nothing -# WPF runs here: not the app, and not the test projects, whose test host needs the -# Microsoft.WindowsDesktop.App runtime that only exists on Windows. +# Every project in Tql.sln but one targets net8.0-windows (WPF + WinForms). They compile +# on Linux through EnableWindowsTargeting (Directory.Build.props) with Microsoft's SDK, but +# nothing WPF runs here: not the app, and not their test projects, whose test host needs +# the Microsoft.WindowsDesktop.App runtime that only exists on Windows. The exception is +# tests/Tql.Plugins.YouTrack.Test, plain net8.0, which the test verb runs. projects: root: @@ -22,9 +23,16 @@ projects: # win-x64 section to each tracked packages.lock.json; NuGetLockFilePath keeps those # lock files in obj/ instead. - cexec dotnet dotnet publish src/Tql.DebugApp -c Debug -r win-x64 --self-contained -o build/DebugApp -p:NuGetLockFilePath=obj/packages.win-x64.lock.json - # test: deliberately unset. No test project can run on Linux (see the header), and CI - # runs none either. A WPF-free test project (plain net8.0) is the plan for the YouTrack - # plugin; see docs/Designs/YouTrack-plugin.md. + # The one test project that runs on Linux: the YouTrack plugin's WPF-free core, compiled + # into plain net8.0 (docs/Designs/YouTrack-plugin.md). The other test projects need + # Windows (see the header), and CI runs none. cexec passes the environment on to the + # dotnet container, so the live fixture runs too: read-only, against + # issues.webathome.org, with the environment's token. + test: + - >- + YOUTRACK_TEST_URL=https://issues.webathome.org + YOUTRACK_TEST_TOKEN="$YOUTRACK_API_KEY_SECRET" + cexec dotnet dotnet test tests/Tql.Plugins.YouTrack.Test lint: - cexec dotnet dotnet csharpier --check . diff --git a/README.md b/README.md index 6d45ac1a..e71b30e3 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ towards the first release. ## Features -- Support for Azure, Azure DevOps, JIRA, Confluence, GitHub, Outlook and - Microsoft Teams. +- Support for Azure, Azure DevOps, JIRA, YouTrack, Confluence, GitHub, Outlook + and Microsoft Teams. - Built in plugin system to be able to add your own plugins. - Quick start tutorial to get you up and running quickly. - Advanced search capabilities. You'll forget how to use the web apps once you @@ -83,6 +83,8 @@ available! - The theme came from https://github.com/AngryCarrot789/WPFDarkTheme. - Some icons came from https://github.com/microsoft/fluentui-system-icons (search engine is at https://fluenticons.co/). +- The YouTrack plugin's category icons came from + https://github.com/JetBrains/icons (Apache License 2.0). - The original grab cursor came from https://www.svgrepo.com/svg/372329/cursor-hand-grab. The one I'm using is modified to better support high DPI. diff --git a/Tql.sln b/Tql.sln index 5395e9f0..5b31fd9f 100644 --- a/Tql.sln +++ b/Tql.sln @@ -45,6 +45,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tql.Benchmarks", "src\Tql.B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tql.Localization", "src\Tql.Localization\Tql.Localization.csproj", "{3BCD5CFB-31AD-42E5-BC08-40C38F63523E}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tql.Plugins.YouTrack.Test", "tests\Tql.Plugins.YouTrack.Test\Tql.Plugins.YouTrack.Test.csproj", "{581A2C7D-0C4D-4B2D-8621-4834EC4378F6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tql.Plugins.YouTrack", "src\Tql.Plugins.YouTrack\Tql.Plugins.YouTrack.csproj", "{1EC1CE1A-E99C-41AF-8EB6-05FEC29C9CA7}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C6ED2573-EB45-49CB-BFD3-9D09A60BA23F}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props @@ -137,6 +141,14 @@ Global {3BCD5CFB-31AD-42E5-BC08-40C38F63523E}.Debug|Any CPU.Build.0 = Debug|Any CPU {3BCD5CFB-31AD-42E5-BC08-40C38F63523E}.Release|Any CPU.ActiveCfg = Release|Any CPU {3BCD5CFB-31AD-42E5-BC08-40C38F63523E}.Release|Any CPU.Build.0 = Release|Any CPU + {581A2C7D-0C4D-4B2D-8621-4834EC4378F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {581A2C7D-0C4D-4B2D-8621-4834EC4378F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {581A2C7D-0C4D-4B2D-8621-4834EC4378F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {581A2C7D-0C4D-4B2D-8621-4834EC4378F6}.Release|Any CPU.Build.0 = Release|Any CPU + {1EC1CE1A-E99C-41AF-8EB6-05FEC29C9CA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EC1CE1A-E99C-41AF-8EB6-05FEC29C9CA7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EC1CE1A-E99C-41AF-8EB6-05FEC29C9CA7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EC1CE1A-E99C-41AF-8EB6-05FEC29C9CA7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -161,6 +173,8 @@ Global {493C14D2-0DAF-4167-BC04-2023DF55AB45} = {E67CF545-0D68-469F-BD58-DAC8EDCE4562} {E5226BB4-2336-40E5-8A8F-9B3F241AA459} = {094A034F-EBB5-42F1-A87B-633A3117042F} {3BCD5CFB-31AD-42E5-BC08-40C38F63523E} = {094A034F-EBB5-42F1-A87B-633A3117042F} + {581A2C7D-0C4D-4B2D-8621-4834EC4378F6} = {E67CF545-0D68-469F-BD58-DAC8EDCE4562} + {1EC1CE1A-E99C-41AF-8EB6-05FEC29C9CA7} = {E67CF545-0D68-469F-BD58-DAC8EDCE4562} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {473D3E4B-C738-47D6-8D01-1D80FA3D6F49} diff --git a/docs/Designs/YouTrack-plugin.md b/docs/Designs/YouTrack-plugin.md index 01115ae8..0537610f 100644 --- a/docs/Designs/YouTrack-plugin.md +++ b/docs/Designs/YouTrack-plugin.md @@ -1,6 +1,7 @@ # YouTrack plugin: design -Status: proposed, 2026-11-21. Nothing is built yet. +Status: built, 2026-11-21. The Windows test run (`specs/Plugins - YouTrack/`) is +still to do. ## Decisions @@ -102,8 +103,9 @@ once there is more than one. ## Features -Paged lists use `$skip` and `$top`; every call passes `$top`, because YouTrack -returns 42 items when it is left out. +Paged lists use `$skip` and `$top`; every call passes `$top`, because the +default page size is not documented (measured: `/api/issues` returned 500 items +without it). - **YouTrack Issues**: searched live with `GET /api/issues?query=&$top=100`. The text goes to YouTrack as a query, @@ -126,7 +128,9 @@ returns 42 items when it is left out. Measured on issues.webathome.org: YouTrack matches word prefixes without a wildcard (`kubecod` finds "KubeCoder"), so the plugin never appends `*`. Doing so could also break a query the user typed. `GET /api/issues/` answers 404 -for an issue that doesn't exist, and the search then runs as usual. +for an issue that doesn't exist, and the search then runs as usual. A half-typed +query such as `#Unres` or `state: Op` answers 400 with `invalid_query`; the +plugin shows no results for it rather than an error. The people directory searches `GET /api/users?query=&$top=100`. It leaves out users without an email address, banned users and guests, and hands the rest @@ -150,9 +154,10 @@ The project follows `Tql.Plugins.Jira` file by file: JIRA plugin does), `IconCacheManager` and `YouTrackPeopleDirectory`. - `ConfigurationUI/`: the connections list and the connection dialog. - `Labels.resx`, `Labels.nl.resx` and `Labels.Designer.cs`. -- `Resources/`: Fluent UI System Icons (MIT, already credited in the README), - recoloured to `#B6C2CF` like the JIRA category icons, and the YouTrack product - icon from JetBrains' brand resources. +- `Resources/`: the glyphs YouTrack's own web app shows for each category + (JetBrains icons, Apache 2.0; the search glyph stands in for saved searches), + in the `#8496AD` YouTrack shows them in, and the YouTrack product icon from + JetBrains' brand resources. These four files have no WPF or TQL dependencies, and the test project includes them as linked `Compile` items: diff --git a/specs/Plugins - YouTrack/001-Installation.md b/specs/Plugins - YouTrack/001-Installation.md new file mode 100644 index 00000000..2fff2fdf --- /dev/null +++ b/specs/Plugins - YouTrack/001-Installation.md @@ -0,0 +1,45 @@ +--- +testspace: +title: Plugins - YouTrack / 001 - Installation +description: Install the YouTrack plugin. +--- + +{% if page %}{% assign spec = page %}{% endif %} + +# {{ spec.title }} + +{{ spec.description }} + +{% include Setup/Clean-Setup.md %} + +## Installation + +{% include Setup/Local-package-source.md %} + +Until the plugin is published, run it from the KubeCoder dev build instead. The +plugin is already loaded in that build, so skip the installation table below and +continue with **Verify installation**, which then only checks that the plugin is +present: + +- Run `\\tqlapp-tql-49385e.home\work\TQL\scripts\Run-KubeCoder-Build.bat`. It + copies the build to `%TEMP%\TQL-DebugApp` and starts + `Tql.DebugApp.exe --env Debug` there. + +For the published plugin: + +| Action | Expected result | +| ------------------------------------------- | --------------- | +| Open the **Configuration** window. | | +| Navigate to **Application > Plugins**. | | +| Select the **TQL YouTrack Plugin** plugin. | | +| **Install** the plugin. | | +| **Restart** the application when requested. | | + +## Verify installation + +| Action | Expected result | +| ------------------------------------------------ | ------------------------------------------------------ | +| Open the **Configuration** window. | | +| Navigate to **Application > Plugins**. | | +| Switch to the **Installed** tab. | The **TQL YouTrack Plugin** plugin shows as installed. | +| Navigate to the **YouTrack** configuration page. | The configuration page opens. | diff --git a/specs/Plugins - YouTrack/002-Configuration.md b/specs/Plugins - YouTrack/002-Configuration.md new file mode 100644 index 00000000..41ae567a --- /dev/null +++ b/specs/Plugins - YouTrack/002-Configuration.md @@ -0,0 +1,96 @@ +--- +testspace: +title: Plugins - YouTrack / 002 - Configuration +description: Configure the YouTrack plugin. +--- + +{% if page %}{% assign spec = page %}{% endif %} +{% include Configuration/Plugins/YouTrack.md %} + +# {{ spec.title }} + +{{ spec.description }} + +{% include Setup/Run-App.md %} + +A token is created in YouTrack under Profile, Account Security, New token, with +the YouTrack scope. + +## Validate dialog + +| Action | Expected result | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | The **YouTrack > General** page is highlighted. | +| **Add** a new connection. | The dialog has the fields **Name**, **URL** and **Token**. | +| Look at the help text of **URL**. | It reads "The address you open YouTrack on, e.g. https://youtrack.example.com or https://example.youtrack.cloud." | +| Look at the help text of **Token**. | It says where a token is made: Profile, Account Security, New token, with the YouTrack scope. The token is shown as a password box. | +| **Cancel** the dialog. | No connection is added. | + +## URL copied from the address bar + +| Action | Expected result | +| ------------------------------------------------- | ---------------------------------------------------------------------------------------- | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | | +| **Add** a new connection with the settings below. | | +| Click **Save**. | The dialog asks "Did you mean {{ youtrack_url }}/?". No exception shows. | +| Decline the suggestion. | The connection is not saved with the wrong URL; the dialog stays open or closes cleanly. | +| Click **Save** again and accept the suggestion. | The URL changes to `{{ youtrack_url }}/` and the connection is accepted. | +| **Cancel** the dialog. | | + +- Connection settings: + - Name: `{{ youtrack_name }}` + - URL: `{{ youtrack_bad_url }}` + - Token: `{{ youtrack_token }}` + +## Wrong token + +| Action | Expected result | +| ------------------------------------------------- | --------------------------------------------------------------------------- | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | | +| **Add** a new connection with the settings below. | | +| Click **Save**. | A plain message says the token is wrong. No exception or stack trace shows. | +| **Cancel** the dialog. | No connection is added. | + +- Connection settings: + - Name: `{{ youtrack_name }}` + - URL: `{{ youtrack_url }}` + - Token: `wrong-token` + +## Configuration + +| Action | Expected result | +| ------------------------------------------------- | ------------------------------------------------ | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | The **YouTrack > General** page is highlighted. | +| **Add** a new connection with the settings below. | | +| Click **Save**. | The connection is accepted without any question. | +| Click **Save**. | | + +- Connection settings: + - Name: `{{ youtrack_name }}` + - URL: `{{ youtrack_url }}` + - Token: `{{ youtrack_token }}` + +## Validate configuration + +| Action | Expected result | +| -------------------------------------------- | --------------------------------------------------------------------------------- | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | The **YouTrack > General** page is highlighted. | +| Highlight the connection and click **Edit**. | The settings conform to the settings below. The token is not shown in clear text. | + +- Connection settings: + - Name: `{{ youtrack_name }}` + - URL: `{{ youtrack_url }}/` + - Token: `{{ youtrack_token }}` + +## Validate authentication + +| Action | Expected result | +| --------------------------------------------- | ----------------------------- | +| Open the app. | | +| Type in `youtrack`. | The YouTrack categories show. | +| **Enter** the **YouTrack Projects** category. | A list of projects shows. | diff --git a/specs/Plugins - YouTrack/003-Search.md b/specs/Plugins - YouTrack/003-Search.md new file mode 100644 index 00000000..bd30ce02 --- /dev/null +++ b/specs/Plugins - YouTrack/003-Search.md @@ -0,0 +1,109 @@ +--- +testspace: +title: Plugins - YouTrack / 003 - Search +description: Verify search features. +--- + +{% if page %}{% assign spec = page %}{% endif %} + +# {{ spec.title }} + +{{ spec.description }} + +{% include Setup/Run-App.md %} + +## Find issue + +| Action | Expected result | +| ------------------------------------------- | ----------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Issues** category. | No issues show. | +| **Type** a search term. | All issues matching the search term show. | +| **Type** a partial word, like `kubecod`. | Issues with words starting with it show. | +| **Activate** an issue. | The issue opens. | + +## Find issue by ID + +| Action | Expected result | +| ----------------------------------------------------------- | ---------------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Issues** category. | | +| **Type** an existing issue ID in upper case, like `KC-230`. | The issue shows first. | +| **Type** the same issue ID in lower case, like `kc-230`. | The issue shows first. | +| **Activate** the issue. | The issue opens directly. | +| **Type** an issue ID that does not exist, like `KC-999999`. | No error shows; the list is searched as usual. | + +## Find issue with a YouTrack query + +| Action | Expected result | +| ------------------------------------------- | -------------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Issues** category. | | +| **Type** in `#Unresolved for: me`. | Only unresolved issues assigned to you show. | +| **Activate** an issue. | The issue opens. | + +## Find project + +| Action | Expected result | +| --------------------------------------------- | -------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Projects** category. | A list of projects shows. | +| Verify the list. | No archived projects show. | +| **Activate** a project. | The project page opens. | + +## Find issues in project + +| Action | Expected result | +| --------------------------------------------- | --------------------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Projects** category. | A list of projects shows. | +| **Enter** a project. | All issues of the project show, last updated first. | +| **Type** a search term. | Only issues of the project matching the term show. | +| **Activate** an issue. | The issue opens. | + +## Find agile board + +| Action | Expected result | +| ------------------------------------------------- | ------------------------------------------ | +| Open the app. | | +| **Enter** the **YouTrack Agile Boards** category. | A list of boards shows. | +| **Type** a search term. | The list of boards is filtered by name. | +| **Activate** a board. | The board opens, also if it has no sprint. | +| Select a board. | It cannot be entered to search in it. | + +## Find saved search + +| Action | Expected result | +| --------------------------------------------------- | ------------------------------------------------ | +| Open the app. | | +| **Enter** the **YouTrack Saved Searches** category. | A list of saved searches shows. | +| **Activate** a saved search. | The issues of the saved search show in YouTrack. | + +## Find issue in saved search + +| Action | Expected result | +| --------------------------------------------------- | -------------------------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Saved Searches** category. | | +| **Enter** a saved search. | All issues matching the saved search show. | +| **Type** a search term. | Only issues matching the saved search and the term show. | +| **Activate** an issue. | The issue opens. | + +## Find dashboard + +| Action | Expected result | +| ----------------------------------------------- | ------------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Dashboards** category. | A list of dashboards shows. | +| **Type** a search term. | The list of dashboards is filtered by name. | +| **Activate** a dashboard. | The dashboard opens. | +| Select a dashboard. | It cannot be entered to search in it. | + +## Create issue + +| Action | Expected result | +| ---------------------------------------------- | -------------------------------------------------------- | +| Open the app. | | +| **Enter** the **New YouTrack Issue** category. | One item per project shows. | +| **Type** in the name of a project. | The item of that project shows. | +| **Activate** the item. | The new issue page opens with that project pre-selected. | diff --git a/specs/Plugins - YouTrack/004-Second-connection.md b/specs/Plugins - YouTrack/004-Second-connection.md new file mode 100644 index 00000000..81ad3dd8 --- /dev/null +++ b/specs/Plugins - YouTrack/004-Second-connection.md @@ -0,0 +1,41 @@ +--- +testspace: +title: Plugins - YouTrack / 004 - Second connection +description: Configure a second connection. +--- + +{% if page %}{% assign spec = page %}{% endif %} +{% include Configuration/Plugins/YouTrack.md %} + +# {{ spec.title }} + +{{ spec.description }} + +{% include Setup/Run-App.md %} + +## Create connection + +| Action | Expected result | +| ------------------------------------------------- | ----------------------------------------------- | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | The **YouTrack > General** page is highlighted. | +| **Add** a new connection with the settings below. | | +| Click **Save**. | | +| Click **Save**. | | + +- Connection settings: + - Name: `{{ youtrack_alt_name }}` + - URL: `{{ youtrack_url }}` + - Token: `{{ youtrack_token }}` + +## Verify multiple connections + +| Action | Expected result | +| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| Open the app. | | +| Type in `youtrack projects`. | One **YouTrack Projects ({{ youtrack_name }})** item and one **YouTrack Projects ({{ youtrack_alt_name }})** item show. | +| Type in `youtrack issues`. | Both an **YouTrack Issues ({{ youtrack_name }})** and an **YouTrack Issues ({{ youtrack_alt_name }})** item show. | +| Type in `youtrack agile`. | The agile boards categories carry the connection names too. | +| Type in `youtrack saved`. | The saved searches categories carry the connection names too. | +| Type in `youtrack dash`. | The dashboards categories carry the connection names too. | +| Type in `new youtrack`. | The **New YouTrack Issue** categories carry the connection names too. | diff --git a/specs/Plugins - YouTrack/005-Search-second-connection.md b/specs/Plugins - YouTrack/005-Search-second-connection.md new file mode 100644 index 00000000..c25cccc1 --- /dev/null +++ b/specs/Plugins - YouTrack/005-Search-second-connection.md @@ -0,0 +1,47 @@ +--- +testspace: +title: Plugins - YouTrack / 005 - Search second connection +description: Verify functionality with a second connection. +--- + +{% if page %}{% assign spec = page %}{% endif %} +{% include Configuration/Plugins/YouTrack.md %} + +# {{ spec.title }} + +{{ spec.description }} + +{% include Setup/Run-App.md %} + +## Verify history of the connections + +| Action | Expected result | +| ----------------------------------------------------------------------- | ----------------------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Projects ({{ youtrack_name }})** category. | The previously selected project shows in the history. | +| **Enter** the **YouTrack Projects ({{ youtrack_alt_name }})** category. | No history shows. | + +## Search in the second connection + +| Action | Expected result | +| --------------------------------------------------------------------- | ----------------------------------------- | +| Open the app. | | +| **Enter** the **YouTrack Issues ({{ youtrack_alt_name }})** category. | No issues show. | +| **Type** a search term. | All issues matching the search term show. | +| **Activate** an issue. | The issue opens. | + +## Delete connection + +| Action | Expected result | +| -------------------------------------------------------------------------- | ----------------------------------------------- | +| Open the **Configuration** window. | | +| Navigate to **YouTrack**. | The **YouTrack > General** page is highlighted. | +| Highlight the **{{ youtrack_alt_name }}** connection and click **Delete**. | The connection is deleted. | +| Click **Save**. | | + +## Verify single connection + +| Action | Expected result | +| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Open the app. | | +| Type in `youtrack projects`. | Only a **YouTrack Projects** item shows instead of the **YouTrack Projects ({{ youtrack_name }})** and **YouTrack Projects ({{ youtrack_alt_name }})**. | diff --git a/specs/_includes/Configuration/Plugins/YouTrack.md b/specs/_includes/Configuration/Plugins/YouTrack.md new file mode 100644 index 00000000..6506581c --- /dev/null +++ b/specs/_includes/Configuration/Plugins/YouTrack.md @@ -0,0 +1,5 @@ +{% assign youtrack_name = "webathome" -%} +{% assign youtrack_alt_name = "test" -%} +{% assign youtrack_url = "https://issues.webathome.org" -%} +{% assign youtrack_bad_url = "https://issues.webathome.org/issues" -%} +{% assign youtrack_token = "(omitted)" -%} diff --git a/src/Tql.DebugApp/Program.cs b/src/Tql.DebugApp/Program.cs index e11f2406..9fb89acf 100644 --- a/src/Tql.DebugApp/Program.cs +++ b/src/Tql.DebugApp/Program.cs @@ -8,6 +8,7 @@ using Tql.Plugins.Jira; using Tql.Plugins.MicrosoftTeams; using Tql.Plugins.Outlook; +using Tql.Plugins.YouTrack; namespace Tql.DebugApp; @@ -24,6 +25,7 @@ public static int Main() typeof(ConfluencePlugin).Assembly, typeof(MicrosoftTeamsPlugin).Assembly, typeof(OutlookPlugin).Assembly, + typeof(YouTrackPlugin).Assembly, typeof(DemoPlugin).Assembly ); diff --git a/src/Tql.DebugApp/Tql.DebugApp.csproj b/src/Tql.DebugApp/Tql.DebugApp.csproj index 280f464f..c1bf09b2 100644 --- a/src/Tql.DebugApp/Tql.DebugApp.csproj +++ b/src/Tql.DebugApp/Tql.DebugApp.csproj @@ -29,6 +29,7 @@ + diff --git a/src/Tql.DebugApp/packages.lock.json b/src/Tql.DebugApp/packages.lock.json index c22392d0..88c627f1 100644 --- a/src/Tql.DebugApp/packages.lock.json +++ b/src/Tql.DebugApp/packages.lock.json @@ -2030,6 +2030,12 @@ "TQLApp.Utilities": "[0.0.0, )" } }, + "TQLApp.Plugins.YouTrack": { + "type": "Project", + "dependencies": { + "TQLApp.Utilities": "[0.0.0, )" + } + }, "TQLApp.Utilities": { "type": "Project", "dependencies": { diff --git a/src/Tql.Plugins.YouTrack/Categories/BoardMatch.cs b/src/Tql.Plugins.YouTrack/Categories/BoardMatch.cs new file mode 100644 index 00000000..1d86ec55 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/BoardMatch.cs @@ -0,0 +1,37 @@ +using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Support; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class BoardMatch(BoardMatchDto dto) : IRunnableMatch, ISerializableMatch, ICopyableMatch +{ + public string Text => string.Format(Labels.BoardMatch_Label, dto.Name); + public ImageSource Icon => Images.Boards; + public MatchTypeId TypeId => TypeIds.Board; + + public Task Run(IServiceProvider serviceProvider, IWin32Window owner) + { + serviceProvider.GetRequiredService().OpenUrl(dto.GetUrl()); + + return Task.CompletedTask; + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } + + public Task Copy(IServiceProvider serviceProvider) + { + serviceProvider.GetRequiredService().CopyUri(Text, dto.GetUrl()); + + return Task.CompletedTask; + } +} + +internal record BoardMatchDto(string Url, string Id, string Name) +{ + public string GetUrl() => YouTrackUrls.GetAgileBoardUrl(Url, Id); +}; diff --git a/src/Tql.Plugins.YouTrack/Categories/BoardType.cs b/src/Tql.Plugins.YouTrack/Categories/BoardType.cs new file mode 100644 index 00000000..462b6ebd --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/BoardType.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class BoardType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Board.Id; + + protected override bool IsValid(BoardMatchDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/BoardsMatch.cs b/src/Tql.Plugins.YouTrack/Categories/BoardsMatch.cs new file mode 100644 index 00000000..763efdc7 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/BoardsMatch.cs @@ -0,0 +1,37 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class BoardsMatch( + RootItemDto dto, + ICache cache, + ConfigurationManager configurationManager, + IMatchFactory factory +) : CachedMatch(cache), ISerializableMatch +{ + public override string Text => + MatchUtils.GetMatchLabel( + Labels.BoardsMatch_Label, + configurationManager.Configuration, + dto.Url + ); + + public override ImageSource Icon => Images.Boards; + public override MatchTypeId TypeId => TypeIds.Boards; + public override string SearchHint => Labels.BoardsMatch_SearchHint; + + protected override IEnumerable Create(YouTrackData data) + { + return from board in data.GetConnection(dto.Url).AgileBoards + select factory.Create(new BoardMatchDto(dto.Url, board.Id, board.Name)); + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/BoardsType.cs b/src/Tql.Plugins.YouTrack/Categories/BoardsType.cs new file mode 100644 index 00000000..b9c2a74b --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/BoardsType.cs @@ -0,0 +1,19 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +[RootMatchType(YouTrackEndpoint.AgileBoards)] +internal class BoardsType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Boards.Id; + + protected override bool IsValid(RootItemDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/DashboardMatch.cs b/src/Tql.Plugins.YouTrack/Categories/DashboardMatch.cs new file mode 100644 index 00000000..d28e2c54 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/DashboardMatch.cs @@ -0,0 +1,40 @@ +using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Support; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class DashboardMatch(DashboardMatchDto dto) + : IRunnableMatch, + ISerializableMatch, + ICopyableMatch +{ + public string Text => string.Format(Labels.DashboardMatch_Label, dto.Name); + public ImageSource Icon => Images.Dashboards; + public MatchTypeId TypeId => TypeIds.Dashboard; + + public Task Run(IServiceProvider serviceProvider, IWin32Window owner) + { + serviceProvider.GetRequiredService().OpenUrl(dto.GetUrl()); + + return Task.CompletedTask; + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } + + public Task Copy(IServiceProvider serviceProvider) + { + serviceProvider.GetRequiredService().CopyUri(Text, dto.GetUrl()); + + return Task.CompletedTask; + } +} + +internal record DashboardMatchDto(string Url, string Id, string Name) +{ + public string GetUrl() => YouTrackUrls.GetDashboardUrl(Url, Id); +}; diff --git a/src/Tql.Plugins.YouTrack/Categories/DashboardType.cs b/src/Tql.Plugins.YouTrack/Categories/DashboardType.cs new file mode 100644 index 00000000..2d980cc1 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/DashboardType.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class DashboardType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Dashboard.Id; + + protected override bool IsValid(DashboardMatchDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/DashboardsMatch.cs b/src/Tql.Plugins.YouTrack/Categories/DashboardsMatch.cs new file mode 100644 index 00000000..2cbf9c7e --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/DashboardsMatch.cs @@ -0,0 +1,37 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class DashboardsMatch( + RootItemDto dto, + ICache cache, + ConfigurationManager configurationManager, + IMatchFactory factory +) : CachedMatch(cache), ISerializableMatch +{ + public override string Text => + MatchUtils.GetMatchLabel( + Labels.DashboardsMatch_Label, + configurationManager.Configuration, + dto.Url + ); + + public override ImageSource Icon => Images.Dashboards; + public override MatchTypeId TypeId => TypeIds.Dashboards; + public override string SearchHint => Labels.DashboardsMatch_SearchHint; + + protected override IEnumerable Create(YouTrackData data) + { + return from dashboard in data.GetConnection(dto.Url).Dashboards + select factory.Create(new DashboardMatchDto(dto.Url, dashboard.Id, dashboard.Name)); + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/DashboardsType.cs b/src/Tql.Plugins.YouTrack/Categories/DashboardsType.cs new file mode 100644 index 00000000..2e5dc2b3 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/DashboardsType.cs @@ -0,0 +1,19 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +[RootMatchType(YouTrackEndpoint.Dashboards)] +internal class DashboardsType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Dashboards.Id; + + protected override bool IsValid(RootItemDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/IssueMatch.cs b/src/Tql.Plugins.YouTrack/Categories/IssueMatch.cs new file mode 100644 index 00000000..cdf6791d --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/IssueMatch.cs @@ -0,0 +1,37 @@ +using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Support; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class IssueMatch(IssueMatchDto dto) : IRunnableMatch, ISerializableMatch, ICopyableMatch +{ + public string Text => $"{dto.IdReadable} {dto.Summary}"; + public ImageSource Icon => Images.Issues; + public MatchTypeId TypeId => TypeIds.Issue; + + public Task Run(IServiceProvider serviceProvider, IWin32Window owner) + { + serviceProvider.GetRequiredService().OpenUrl(dto.GetUrl()); + + return Task.CompletedTask; + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } + + public Task Copy(IServiceProvider serviceProvider) + { + serviceProvider.GetRequiredService().CopyUri(Text, dto.GetUrl()); + + return Task.CompletedTask; + } +} + +internal record IssueMatchDto(string Url, string IdReadable, string Summary) +{ + public string GetUrl() => YouTrackUrls.GetIssueUrl(Url, IdReadable); +}; diff --git a/src/Tql.Plugins.YouTrack/Categories/IssueType.cs b/src/Tql.Plugins.YouTrack/Categories/IssueType.cs new file mode 100644 index 00000000..64f37283 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/IssueType.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class IssueType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Issue.Id; + + protected override bool IsValid(IssueMatchDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/IssueUtils.cs b/src/Tql.Plugins.YouTrack/Categories/IssueUtils.cs new file mode 100644 index 00000000..73e5951f --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/IssueUtils.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; + +namespace Tql.Plugins.YouTrack.Categories; + +internal static class IssueUtils +{ + public static IEnumerable CreateMatches( + string url, + IEnumerable issues, + IMatchFactory factory + ) + { + return issues.Select(p => factory.Create(new IssueMatchDto(url, p.IdReadable, p.Summary))); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/IssuesMatch.cs b/src/Tql.Plugins.YouTrack/Categories/IssuesMatch.cs new file mode 100644 index 00000000..31c3c8ab --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/IssuesMatch.cs @@ -0,0 +1,79 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class IssuesMatch( + RootItemDto dto, + ConfigurationManager configurationManager, + IMatchFactory factory +) : ISearchableMatch, ISerializableMatch +{ + public string Text => + MatchUtils.GetMatchLabel( + Labels.IssuesMatch_Label, + configurationManager.Configuration, + dto.Url + ); + + public ImageSource Icon => Images.Issues; + public MatchTypeId TypeId => TypeIds.Issues; + public string SearchHint => Labels.IssuesMatch_SearchHint; + + public async Task> Search( + ISearchContext context, + string text, + CancellationToken cancellationToken + ) + { + if (text.IsWhiteSpace()) + return Array.Empty(); + + var maybeId = YouTrackQueries.IsIssueId(text); + if (maybeId) + context.SuppressPreliminaryResults(); + + await context.DebounceDelay(cancellationToken); + + var client = configurationManager.GetClient(dto.Url); + + if (maybeId) + { + try + { + var issue = await client.GetIssue(text, cancellationToken); + if (issue != null) + return IssueUtils.CreateMatches(dto.Url, new[] { issue }, factory); + } + catch (YouTrackException) + { + // Ignore. Fall back to a normal search. + } + } + + // The text goes to YouTrack as a query, so "#Unresolved for: me" + // works. A query that's still being typed, such as "#Unres", doesn't + // parse; that's no results rather than an error. + try + { + var issues = await client.SearchIssues( + text.Trim(), + YouTrackClient.DefaultSearchTop, + cancellationToken + ); + + return IssueUtils.CreateMatches(dto.Url, issues, factory); + } + catch (YouTrackInvalidQueryException) + { + return Array.Empty(); + } + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/IssuesType.cs b/src/Tql.Plugins.YouTrack/Categories/IssuesType.cs new file mode 100644 index 00000000..5aacd7a0 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/IssuesType.cs @@ -0,0 +1,18 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +[RootMatchType] +internal class IssuesType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Issues.Id; + + protected override bool IsValid(RootItemDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/NewMatch.cs b/src/Tql.Plugins.YouTrack/Categories/NewMatch.cs new file mode 100644 index 00000000..4aa841bc --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/NewMatch.cs @@ -0,0 +1,49 @@ +using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class NewMatch(NewMatchDto dto, IconCacheManager iconCacheManager) + : IRunnableMatch, + ISerializableMatch, + ICopyableMatch +{ + public string Text => MatchText.Path(dto.ProjectName, Labels.NewMatch_NewIssue); + public ImageSource Icon { get; } = + (dto.IconUrl != null ? iconCacheManager.GetIcon(new IconKey(dto.Url, dto.IconUrl)) : null) + ?? Images.Issues; + public MatchTypeId TypeId => TypeIds.New; + + public Task Run(IServiceProvider serviceProvider, IWin32Window owner) + { + serviceProvider.GetRequiredService().OpenUrl(dto.GetUrl()); + + return Task.CompletedTask; + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } + + public Task Copy(IServiceProvider serviceProvider) + { + serviceProvider.GetRequiredService().CopyUri(Text, dto.GetUrl()); + + return Task.CompletedTask; + } +} + +internal record NewMatchDto( + string Url, + string ProjectShortName, + string ProjectName, + string? IconUrl +) +{ + public string GetUrl() => YouTrackUrls.GetNewIssueUrl(Url, ProjectShortName); +}; diff --git a/src/Tql.Plugins.YouTrack/Categories/NewType.cs b/src/Tql.Plugins.YouTrack/Categories/NewType.cs new file mode 100644 index 00000000..f5073d49 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/NewType.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class NewType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.New.Id; + + protected override bool IsValid(NewMatchDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/NewsMatch.cs b/src/Tql.Plugins.YouTrack/Categories/NewsMatch.cs new file mode 100644 index 00000000..5cf12e73 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/NewsMatch.cs @@ -0,0 +1,39 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class NewsMatch( + RootItemDto dto, + ICache cache, + ConfigurationManager configurationManager, + IMatchFactory factory +) : CachedMatch(cache), ISerializableMatch +{ + public override string Text => + MatchUtils.GetMatchLabel( + Labels.NewsMatch_Label, + configurationManager.Configuration, + dto.Url + ); + + public override ImageSource Icon => Images.Issues; + public override MatchTypeId TypeId => TypeIds.News; + public override string SearchHint => Labels.NewsMatch_SearchHint; + + protected override IEnumerable Create(YouTrackData data) + { + return from project in data.GetConnection(dto.Url).Projects + select factory.Create( + new NewMatchDto(dto.Url, project.ShortName, project.Name, project.IconUrl) + ); + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/NewsType.cs b/src/Tql.Plugins.YouTrack/Categories/NewsType.cs new file mode 100644 index 00000000..f68a41a6 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/NewsType.cs @@ -0,0 +1,19 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +[RootMatchType(YouTrackEndpoint.Projects)] +internal class NewsType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.News.Id; + + protected override bool IsValid(RootItemDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/ProjectMatch.cs b/src/Tql.Plugins.YouTrack/Categories/ProjectMatch.cs new file mode 100644 index 00000000..080356f1 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/ProjectMatch.cs @@ -0,0 +1,74 @@ +using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class ProjectMatch( + ProjectMatchDto dto, + IconCacheManager iconCacheManager, + ConfigurationManager configurationManager, + IMatchFactory factory +) : IRunnableMatch, ISerializableMatch, ICopyableMatch, ISearchableMatch +{ + public string Text => string.Format(Labels.ProjectMatch_Label, dto.Name); + public ImageSource Icon { get; } = + (dto.IconUrl != null ? iconCacheManager.GetIcon(new IconKey(dto.Url, dto.IconUrl)) : null) + ?? Images.Projects; + public MatchTypeId TypeId => TypeIds.Project; + public string SearchHint => Labels.ProjectMatch_SearchHint; + + public Task Run(IServiceProvider serviceProvider, IWin32Window owner) + { + serviceProvider.GetRequiredService().OpenUrl(dto.GetUrl()); + + return Task.CompletedTask; + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } + + public Task Copy(IServiceProvider serviceProvider) + { + serviceProvider.GetRequiredService().CopyUri(Text, dto.GetUrl()); + + return Task.CompletedTask; + } + + public async Task> Search( + ISearchContext context, + string text, + CancellationToken cancellationToken + ) + { + await context.DebounceDelay(cancellationToken); + + var client = configurationManager.GetClient(dto.Url); + + // "project: KC ", or the most recently updated issues without + // text. A query that's still being typed is no results. + try + { + var issues = await client.SearchIssues( + YouTrackQueries.Project(dto.ShortName, text), + YouTrackClient.DefaultSearchTop, + cancellationToken + ); + + return IssueUtils.CreateMatches(dto.Url, issues, factory); + } + catch (YouTrackInvalidQueryException) + { + return Array.Empty(); + } + } +} + +internal record ProjectMatchDto(string Url, string ShortName, string Name, string? IconUrl) +{ + public string GetUrl() => YouTrackUrls.GetProjectUrl(Url, ShortName); +}; diff --git a/src/Tql.Plugins.YouTrack/Categories/ProjectType.cs b/src/Tql.Plugins.YouTrack/Categories/ProjectType.cs new file mode 100644 index 00000000..485e37d3 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/ProjectType.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class ProjectType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Project.Id; + + protected override bool IsValid(ProjectMatchDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/ProjectsMatch.cs b/src/Tql.Plugins.YouTrack/Categories/ProjectsMatch.cs new file mode 100644 index 00000000..c1360843 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/ProjectsMatch.cs @@ -0,0 +1,39 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class ProjectsMatch( + RootItemDto dto, + ICache cache, + ConfigurationManager configurationManager, + IMatchFactory factory +) : CachedMatch(cache), ISerializableMatch +{ + public override string Text => + MatchUtils.GetMatchLabel( + Labels.ProjectsMatch_Label, + configurationManager.Configuration, + dto.Url + ); + + public override ImageSource Icon => Images.Projects; + public override MatchTypeId TypeId => TypeIds.Projects; + public override string SearchHint => Labels.ProjectsMatch_SearchHint; + + protected override IEnumerable Create(YouTrackData data) + { + return from project in data.GetConnection(dto.Url).Projects + select factory.Create( + new ProjectMatchDto(dto.Url, project.ShortName, project.Name, project.IconUrl) + ); + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/ProjectsType.cs b/src/Tql.Plugins.YouTrack/Categories/ProjectsType.cs new file mode 100644 index 00000000..61944eaa --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/ProjectsType.cs @@ -0,0 +1,19 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +[RootMatchType(YouTrackEndpoint.Projects)] +internal class ProjectsType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.Projects.Id; + + protected override bool IsValid(RootItemDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/RootItemDto.cs b/src/Tql.Plugins.YouTrack/Categories/RootItemDto.cs new file mode 100644 index 00000000..13408376 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/RootItemDto.cs @@ -0,0 +1,3 @@ +namespace Tql.Plugins.YouTrack.Categories; + +internal record RootItemDto(string Url); diff --git a/src/Tql.Plugins.YouTrack/Categories/SavedSearchMatch.cs b/src/Tql.Plugins.YouTrack/Categories/SavedSearchMatch.cs new file mode 100644 index 00000000..842a68a9 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/SavedSearchMatch.cs @@ -0,0 +1,71 @@ +using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class SavedSearchMatch( + SavedSearchMatchDto dto, + ConfigurationManager configurationManager, + IMatchFactory factory +) : IRunnableMatch, ISerializableMatch, ICopyableMatch, ISearchableMatch +{ + public string Text => dto.Name; + public ImageSource Icon => Images.SavedSearches; + public MatchTypeId TypeId => TypeIds.SavedSearch; + public string SearchHint => Labels.SavedSearchMatch_SearchHint; + + public Task Run(IServiceProvider serviceProvider, IWin32Window owner) + { + serviceProvider.GetRequiredService().OpenUrl(dto.GetUrl()); + + return Task.CompletedTask; + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } + + public Task Copy(IServiceProvider serviceProvider) + { + serviceProvider.GetRequiredService().CopyUri(Text, dto.GetUrl()); + + return Task.CompletedTask; + } + + public async Task> Search( + ISearchContext context, + string text, + CancellationToken cancellationToken + ) + { + await context.DebounceDelay(cancellationToken); + + var client = configurationManager.GetClient(dto.Url); + + // The saved search narrowed with the text: "() and + // ()". A query that's still being typed is no results. + try + { + var issues = await client.SearchIssues( + YouTrackQueries.SavedSearch(dto.Query, text), + YouTrackClient.DefaultSearchTop, + cancellationToken + ); + + return IssueUtils.CreateMatches(dto.Url, issues, factory); + } + catch (YouTrackInvalidQueryException) + { + return Array.Empty(); + } + } +} + +internal record SavedSearchMatchDto(string Url, string Id, string Name, string Query) +{ + public string GetUrl() => YouTrackUrls.GetSavedSearchUrl(Url, Query); +}; diff --git a/src/Tql.Plugins.YouTrack/Categories/SavedSearchType.cs b/src/Tql.Plugins.YouTrack/Categories/SavedSearchType.cs new file mode 100644 index 00000000..063f3a5e --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/SavedSearchType.cs @@ -0,0 +1,16 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Services; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class SavedSearchType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.SavedSearch.Id; + + protected override bool IsValid(SavedSearchMatchDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/SavedSearchesMatch.cs b/src/Tql.Plugins.YouTrack/Categories/SavedSearchesMatch.cs new file mode 100644 index 00000000..0a5bc21d --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/SavedSearchesMatch.cs @@ -0,0 +1,44 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +internal class SavedSearchesMatch( + RootItemDto dto, + ICache cache, + ConfigurationManager configurationManager, + IMatchFactory factory +) : CachedMatch(cache), ISerializableMatch +{ + public override string Text => + MatchUtils.GetMatchLabel( + Labels.SavedSearchesMatch_Label, + configurationManager.Configuration, + dto.Url + ); + + public override ImageSource Icon => Images.SavedSearches; + public override MatchTypeId TypeId => TypeIds.SavedSearches; + public override string SearchHint => Labels.SavedSearchesMatch_SearchHint; + + protected override IEnumerable Create(YouTrackData data) + { + return from savedSearch in data.GetConnection(dto.Url).SavedSearches + select factory.Create( + new SavedSearchMatchDto( + dto.Url, + savedSearch.Id, + savedSearch.Name, + savedSearch.Query + ) + ); + } + + public string Serialize() + { + return JsonSerializer.Serialize(dto); + } +} diff --git a/src/Tql.Plugins.YouTrack/Categories/SavedSearchesType.cs b/src/Tql.Plugins.YouTrack/Categories/SavedSearchesType.cs new file mode 100644 index 00000000..6a280342 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/SavedSearchesType.cs @@ -0,0 +1,19 @@ +using Tql.Abstractions; +using Tql.Plugins.YouTrack.Data; +using Tql.Plugins.YouTrack.Services; +using Tql.Plugins.YouTrack.Support; +using Tql.Utilities; + +namespace Tql.Plugins.YouTrack.Categories; + +[RootMatchType(YouTrackEndpoint.SavedSearches)] +internal class SavedSearchesType( + IMatchFactory factory, + ConfigurationManager configurationManager +) : MatchType(factory) +{ + public override Guid Id => TypeIds.SavedSearches.Id; + + protected override bool IsValid(RootItemDto dto) => + configurationManager.Configuration.HasConnection(dto.Url); +} diff --git a/src/Tql.Plugins.YouTrack/Categories/TypeIds.cs b/src/Tql.Plugins.YouTrack/Categories/TypeIds.cs new file mode 100644 index 00000000..47235628 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Categories/TypeIds.cs @@ -0,0 +1,32 @@ +using Tql.Abstractions; + +namespace Tql.Plugins.YouTrack.Categories; + +internal static class TypeIds +{ + private static MatchTypeId CreateId(string id) => new(Guid.Parse(id), YouTrackPlugin.Id); + + public static readonly MatchTypeId Boards = CreateId("836195e8-2fdd-4280-9079-a9541409820a"); + public static readonly MatchTypeId Board = CreateId("05d3125b-4e61-4e65-a8b9-b79ab1f2924a"); + + public static readonly MatchTypeId Dashboards = CreateId( + "ec125bd1-8f26-4ead-90ad-285a31e94719" + ); + public static readonly MatchTypeId Dashboard = CreateId("ec8ffed0-4b1f-4da7-92c2-d26c533ae54e"); + + public static readonly MatchTypeId Issues = CreateId("f0a983c9-e93d-4995-bb36-e4857167cfc1"); + public static readonly MatchTypeId Issue = CreateId("eec71d7f-237f-4120-9dd5-122f53e551fd"); + + public static readonly MatchTypeId News = CreateId("c4780f73-fe57-4b6d-b911-7e0aa1f914a2"); + public static readonly MatchTypeId New = CreateId("4c780a20-d582-40e9-9668-616e07491495"); + + public static readonly MatchTypeId Projects = CreateId("0268f2d0-7c99-46c2-a6f4-7a1379ea7c9e"); + public static readonly MatchTypeId Project = CreateId("dafbacd3-ff99-4de2-bd7f-baa871399aa1"); + + public static readonly MatchTypeId SavedSearches = CreateId( + "c0b268e5-a45c-441a-ab89-42c5171857df" + ); + public static readonly MatchTypeId SavedSearch = CreateId( + "cc06857b-d24a-4d9c-916a-c1e95801fc2e" + ); +} diff --git a/src/Tql.Plugins.YouTrack/Configuration.cs b/src/Tql.Plugins.YouTrack/Configuration.cs new file mode 100644 index 00000000..1ea54e87 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/Configuration.cs @@ -0,0 +1,10 @@ +namespace Tql.Plugins.YouTrack; + +internal record Configuration(ImmutableArray Connections) +{ + public static readonly Configuration Empty = new(ImmutableArray.Empty); + + public bool HasConnection(string url) => Connections.Any(p => p.Url == url); +} + +internal record Connection(Guid Id, string Name, string Url, string ProtectedToken); diff --git a/src/Tql.Plugins.YouTrack/ConfigurationUI/ConfigurationControl.xaml b/src/Tql.Plugins.YouTrack/ConfigurationUI/ConfigurationControl.xaml new file mode 100644 index 00000000..12dc9465 --- /dev/null +++ b/src/Tql.Plugins.YouTrack/ConfigurationUI/ConfigurationControl.xaml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + +