From 9503d5cee0de1aadbb65d1cfbaebc11edfc49502 Mon Sep 17 00:00:00 2001
From: Party Wumpus <48649272+PartyWumpus@users.noreply.github.com>
Date: Thu, 15 Feb 2024 02:32:58 +0000
Subject: Testing PRs from within decky (#496)

* git no work so manually uploading files :(

* argh i wish git was working

* ok next time i'll make git work

* Update updater.py

* git please work next time this took ages without you

* fix me locales

* Update updater.py

* Update en-US.json

* Update updater.py

* Update updater.py

* i wish my python LSP stuff was working

* fix it

* Update updater.py

* Update updater.py

* Only show testing branch as an option if it is already selected

* Initial implementation for fetching the open PRs. Still need testing and a token to complete this.

* Wrong filter capitalization

* Fix a couple of typos in the python backend updater.

* Fix typos pt 3

* This should be the last one

* Prepend the PR version number with PR- to make it clearer that's the PR number.

* Update prettier to the latest version otherwise it will never be happy with the formatting.

* fix merge mistake

* fix pyright errors & type hint most new code

* fix strict pyright errors...

* not sure why my local linter didn't catch this

* Reimplement the logic between PR and artifact build to limit API calls

* Fix pyright errors

* use nightly.link for downloads

* remove accidental dollar sign

* fix various logical errors. the code actually works now.

* set branch to testing when user downloads a testing version

---------

Co-authored-by: Marco Rodolfi <marco.rodolfi@tuta.io>
---
 .../components/settings/pages/testing/index.tsx    | 87 ++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 frontend/src/components/settings/pages/testing/index.tsx

(limited to 'frontend/src/components/settings/pages/testing/index.tsx')

diff --git a/frontend/src/components/settings/pages/testing/index.tsx b/frontend/src/components/settings/pages/testing/index.tsx
new file mode 100644
index 00000000..a32ce80e
--- /dev/null
+++ b/frontend/src/components/settings/pages/testing/index.tsx
@@ -0,0 +1,87 @@
+import { DialogBody, DialogButton, DialogControlsSection, Focusable, Navigation } from 'decky-frontend-lib';
+import { useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { FaDownload, FaInfo } from 'react-icons/fa';
+
+import { callUpdaterMethod } from '../../../../updater';
+import { setSetting } from '../../../../utils/settings';
+import { UpdateBranch } from '../general/BranchSelect';
+
+interface TestingVersion {
+  id: number;
+  name: string;
+  link: string;
+  head_sha: string;
+}
+
+export default function TestingVersionList() {
+  const { t } = useTranslation();
+  const [testingVersions, setTestingVersions] = useState<TestingVersion[]>([]);
+
+  useEffect(() => {
+    (async () => {
+      setTestingVersions((await callUpdaterMethod('get_testing_versions')).result);
+    })();
+  }, []);
+
+  if (testingVersions.length === 0) {
+    return (
+      <div>
+        <p>No open PRs found</p>
+      </div>
+    );
+  }
+
+  return (
+    <DialogBody>
+      <DialogControlsSection>
+        <ul style={{ listStyleType: 'none', padding: '0' }}>
+          {testingVersions.map((version) => {
+            return (
+              <li style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', paddingBottom: '10px' }}>
+                <span>
+                  {version.name} <span style={{ opacity: '50%' }}>{'#' + version.id}</span>
+                </span>
+                <Focusable style={{ height: '40px', marginLeft: 'auto', display: 'flex' }}>
+                  <DialogButton
+                    style={{ height: '40px', minWidth: '60px', marginRight: '10px' }}
+                    onClick={() => {
+                      callUpdaterMethod('download_testing_version', { pr_id: version.id, sha_id: version.head_sha });
+                      setSetting('branch', UpdateBranch.Testing);
+                    }}
+                  >
+                    <div
+                      style={{
+                        display: 'flex',
+                        minWidth: '150px',
+                        justifyContent: 'space-between',
+                        alignItems: 'center',
+                      }}
+                    >
+                      {t('Testing.download')}
+                      <FaDownload style={{ paddingLeft: '1rem' }} />
+                    </div>
+                  </DialogButton>
+                  <DialogButton
+                    style={{
+                      height: '40px',
+                      width: '40px',
+                      padding: '10px 12px',
+                      minWidth: '40px',
+                      display: 'flex',
+                      flexDirection: 'column',
+                      justifyContent: 'center',
+                    }}
+                    onClick={() => Navigation.NavigateToExternalWeb(version.link)}
+                  >
+                    <FaInfo />
+                  </DialogButton>
+                </Focusable>
+              </li>
+            );
+          })}
+        </ul>
+      </DialogControlsSection>
+    </DialogBody>
+  );
+}
-- 
cgit v1.2.3

